Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.gitignore
/venv
/.pytest_cache
/.pytest_cache
__pycache__/
*.pyc
26 changes: 18 additions & 8 deletions processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,26 @@ def map_psms_to_spectra(spectra: List[Dict], psm_df: pd.DataFrame) -> pd.DataFra

# ⚡ OPTIMIZATION: Convert list of dicts to DataFrame directly instead of repeated apply calls
# Original: Multiple apply calls (4x iteration over full dataset)
# Improvement: Iterate over list of lists (faster than dicts) and explicitly pass columns.
# This also ensures 'None' is used for missing values instead of 'NaN'.

# Convert matched Series to list, replacing NaNs with empty dicts for DataFrame construction
specs_list = [x if isinstance(x, dict) else {} for x in matched_spec_series]
specs_df = pd.DataFrame(specs_list)
specs_df.index = psm_df.index # Align index with original DataFrame
# Pre-define columns to ensure order and existence
cols = ['title', 'mz_array', 'intensity_array', 'pepmass']

# Convert Series to list to avoid Pandas iteration overhead (~2x speedup)
matched_list = matched_spec_series.tolist()

# Ensure required columns exist (if no spectra matched or mock data missing keys)
for col in ['title', 'mz_array', 'intensity_array', 'pepmass']:
if col not in specs_df.columns:
specs_df[col] = None
specs_data = []
for x in matched_list:
if isinstance(x, dict):
# Direct access for speed (keys guaranteed by load_mgf)
specs_data.append([x['title'], x['mz_array'], x['intensity_array'], x['pepmass']])
else:
# Explicitly use None for missing matches
specs_data.append([None, None, None, None])

specs_df = pd.DataFrame(specs_data, columns=cols)
specs_df.index = psm_df.index # Align index with original DataFrame

mappings = pd.DataFrame({
'psm_index': psm_df.index,
Expand Down