Skip to content
Draft
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.gitignore
/venv
/.pytest_cache
/.pytest_cache
__pycache__/
Binary file added __pycache__/data_loading.cpython-312.pyc
Binary file not shown.
Binary file added __pycache__/processing.cpython-312.pyc
Binary file not shown.
17 changes: 9 additions & 8 deletions processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
# Pattern 4: full numeric
_NUMERIC_PATTERN = re.compile(r'^\d+$')

# Default spectrum dictionary for missing matches (ensures consistent schema with None values)
_DEFAULT_SPEC = {'title': None, 'mz_array': None, 'intensity_array': None, 'pepmass': None}


def extract_index_from_spectra_ref(s: Optional[str]) -> Optional[str]:
"""
Expand Down Expand Up @@ -98,16 +101,14 @@ 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: Use .tolist() for faster iteration and explicit columns to skip schema inference.
# Also use _DEFAULT_SPEC to ensure missing rows have None instead of NaN for correct logic in app.py.

# 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
# Convert matched Series to list, replacing NaNs with default dict for DataFrame construction
specs_list = [x if isinstance(x, dict) else _DEFAULT_SPEC for x in 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_df = pd.DataFrame(specs_list, columns=['title', 'mz_array', 'intensity_array', 'pepmass'])
specs_df.index = psm_df.index # Align index with original DataFrame

mappings = pd.DataFrame({
'psm_index': psm_df.index,
Expand Down
Binary file added tests/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.