Skip to content

Commit b5a86bc

Browse files
committed
polish spectra library
1 parent 694ec4d commit b5a86bc

File tree

4 files changed

+83
-57
lines changed

4 files changed

+83
-57
lines changed

content/dia_library.py

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ def terminate_subprocess():
105105
if not selected_mzML_files:
106106
st.warning("Please select at least one experiment (mzML/raw file) for generating the library.")
107107
else:
108+
if uploaded_file is not None:
109+
uploaded_stem = Path(uploaded_file.name).stem
110+
111+
if user_library_name == uploaded_stem:
112+
st.error(
113+
"The library output file name tag cannot be the same as the uploaded library file name. "
114+
"Please choose a different library output file name tag."
115+
)
116+
st.stop()
117+
108118
# Extract base names (without extension) for matching
109119
mzml_basenames = {os.path.splitext(os.path.basename(f))[0] for f in selected_mzML_files}
110120

@@ -234,49 +244,50 @@ def log(msg: str):
234244

235245
#--------------- File Info---------------------
236246
log("====> mzML file Info with FileInfo OpenMS <====\n")
237-
238-
FileInfo_exec = os.path.join(os.getcwd(), 'FileInfo')
239-
#st.write(selected_mzML_files)
240-
for mzml_file in selected_mzML_files:
241-
# Input file: from result-files folder
242-
mzml_path_in = Path(st.session_state.workspace, "mzML-files", mzml_file)
243-
244-
# Append current file being processed
245-
log(f"---> Processing mzml file FileInfo: {mzml_file}\n")
246-
247-
if os.name == 'nt':
248-
args_FileInfo = [
249-
FileInfo_exec,
250-
"-in", str(mzml_path_in)
251-
]
252-
else:
253-
args_FileInfo = [
254-
"FileInfo",
255-
"-in", str(mzml_path_in)
256-
]
257-
258-
#st.info(f"Running: {' '.join(args_FileInfo)}")
259-
260-
result_FileInfo = subprocess.run(
261-
args_FileInfo,
262-
stdout=subprocess.PIPE,
263-
stderr=subprocess.PIPE,
264-
text=True
265-
)
266-
267-
if result_FileInfo.returncode != 0:
268-
console_output.text("FileInfo failed")
269-
st.text(result.stderr)
270-
st.error("FileInfo failed")
271-
st.stop()
272-
else:
273-
log(f"{result_FileInfo.stdout}\n")
274-
275-
#-------------------check FileInfo output-----------------
276-
if "ion mobility: <none> .. <none>" in result_FileInfo.stdout:
277-
log("\n====> WARNING: No ion mobility information found in mzML files. Please ensure your data contains ion mobility for library generation. <====\n")
278-
st.error("No ion mobility information found in mzML files. Please ensure your data contains ion mobility for library generation.")
279-
st.stop()
247+
fileinfo=False
248+
if fileinfo:
249+
FileInfo_exec = os.path.join(os.getcwd(), 'FileInfo')
250+
#st.write(selected_mzML_files)
251+
for mzml_file in selected_mzML_files:
252+
# Input file: from result-files folder
253+
mzml_path_in = Path(st.session_state.workspace, "mzML-files", mzml_file)
254+
255+
# Append current file being processed
256+
log(f"---> Processing mzml file FileInfo: {mzml_file}\n")
257+
258+
if os.name == 'nt':
259+
args_FileInfo = [
260+
FileInfo_exec,
261+
"-in", str(mzml_path_in)
262+
]
263+
else:
264+
args_FileInfo = [
265+
"FileInfo",
266+
"-in", str(mzml_path_in)
267+
]
268+
269+
#st.info(f"Running: {' '.join(args_FileInfo)}")
270+
271+
result_FileInfo = subprocess.run(
272+
args_FileInfo,
273+
stdout=subprocess.PIPE,
274+
stderr=subprocess.PIPE,
275+
text=True
276+
)
277+
278+
if result_FileInfo.returncode != 0:
279+
console_output.text("FileInfo failed")
280+
st.text(result.stderr)
281+
st.error("FileInfo failed")
282+
st.stop()
283+
else:
284+
log(f"{result_FileInfo.stdout}\n")
285+
286+
#-------------------check FileInfo output-----------------
287+
if "ion mobility: <none> .. <none>" in result_FileInfo.stdout:
288+
log("\n====> WARNING: No ion mobility information found in mzML files. Please ensure your data contains ion mobility for library generation. <====\n")
289+
st.error("No ion mobility information found in mzML files. Please ensure your data contains ion mobility for library generation.")
290+
st.stop()
280291

281292
#---------------upload the library file from MSFragger---------------------
282293
if uploaded_file is not None:
@@ -375,8 +386,9 @@ def log(msg: str):
375386

376387
#--------------- Save log file---------------------
377388
if success_pipline:
389+
378390
# copy library output folder to result-files for download
379-
copy_folder_library_to_results(output_folder_library)
391+
copy_folder_library_to_results(output_folder_library, filename_dont_copy=uploaded_file)
380392

381393
# Provide download link
382394
st.info(f"Preparing download link for library output files ...", icon="ℹ️")

content/file_upload.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
cols = st.columns(3)
5454
#file uploader submit button
5555
if cols[1].form_submit_button("Add mzML/raw file to workspace", type="primary"):
56-
print(files)
5756
if not files:
5857
st.warning("Upload some files first.")
5958
else:

content/rescoring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
for f in Path(st.session_state.workspace, "result-files").iterdir()
9595
if (
9696
f.name.endswith(".idXML")
97-
and not any(x in f.name for x in ["0.0100", "0.1000", "1.0000","RT_feat", "RT_Int_feat", "updated_feat", "_perc_", "_sse_perc_" ])
97+
and not any(x in f.name for x in ["0.0100", "0.1000", "1.0000","RT_feat", "RT_Int_feat", "updated_feat", "_perc", "_perc_", "_sse_perc_" ])
9898
)
9999
]
100100

src/result_files.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ def download_folder_library(folder_path: Path | str, link_name: str, zip_name: s
487487
st.markdown(href, unsafe_allow_html=True)
488488

489489

490-
def copy_folder_library_to_results(folder_path: Path | str) -> None:
490+
def copy_folder_library_to_results(folder_path: Path | str, filename_dont_copy: str) -> None:
491491
"""
492492
Create a copy of a folder into the results directory.
493493
@@ -504,20 +504,35 @@ def copy_folder_library_to_results(folder_path: Path | str) -> None:
504504
result_dir: Path = Path(st.session_state.workspace, "result-files")
505505

506506
# Copy the folder
507-
shutil.copytree(folder_path, result_dir)
508-
507+
for item in folder_path.iterdir():
508+
if item.name != filename_dont_copy.name:
509+
dest = result_dir / item.name
510+
if item.is_dir():
511+
shutil.copytree(item, dest, dirs_exist_ok=True)
512+
else:
513+
shutil.copy2(item, dest)
509514

515+
import stat
510516
def delete_folder_library(folder_path: Path | str) -> None:
511517
"""
512-
Delete a folder and its contents.
513-
514-
Parameters
515-
----------
516-
folder_path : Path or str
517-
Path to the folder to be deleted.
518+
Delete a folder and all of its contents (Linux and Windows safe).
518519
"""
519520
folder_path = Path(folder_path)
520-
if folder_path.is_dir():
521-
shutil.rmtree(folder_path)
521+
522+
if not folder_path.exists():
523+
return
524+
525+
if not folder_path.is_dir():
526+
raise ValueError(f"Provided path is not a directory: {folder_path}")
527+
528+
def _on_rm_error(func, path, exc_info):
529+
# Windows: clear read-only attribute, POSIX: no-op
530+
try:
531+
Path(path).chmod(stat.S_IWRITE)
532+
except Exception:
533+
pass
534+
func(path)
535+
536+
shutil.rmtree(folder_path, onerror=_on_rm_error)
522537

523538

0 commit comments

Comments
 (0)