Skip to content

Commit

Permalink
use sip int id
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-combe committed Jul 28, 2024
1 parent 8da471a commit 07d6373
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
8 changes: 4 additions & 4 deletions models/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class Match(Base):
scores: Mapped[Optional[dict[str, Any]]] = mapped_column(JSON, nullable=True)
exp_mz: Mapped[float] = mapped_column(FLOAT, nullable=True)
calc_mz: Mapped[float] = mapped_column(FLOAT, nullable=True)
sil_id: Mapped[str] = mapped_column(Text, nullable=True) # null if from csv file
sip_id: Mapped[int] = mapped_column(Integer, nullable=True) # null if from csv file
__table_args__ = (
ForeignKeyConstraint(
["sil_id", "upload_id"],
["analysiscollectionspectrumidentification.spectrum_identification_list_ref",
"analysiscollectionspectrumidentification.upload_id"],
["sip_id", "upload_id"],
["spectrumidentificationprotocol.id",
"spectrumidentificationprotocol.upload_id"],
),
ForeignKeyConstraint(
["pep1_id", "upload_id"],
Expand Down
7 changes: 5 additions & 2 deletions parser/MzIdParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def __init__(self, mzid_path, temp_dir, peak_list_dir, writer, logger):

self.peak_list_readers = {} # peak list readers indexed by spectraData_ref
self.spectra_data_id_lookup = {} # spectra_data_ref to spectra_data_id lookup
self.sip_ref_to_sip_id_lookup = {} # sip_ref to sip_id lookup
self.sil_ref_to_protocol_id_lookup = {} # sip_ref to sip_id lookup
self.temp_dir = temp_dir
if not self.temp_dir.endswith('/'):
self.temp_dir += '/'
Expand Down Expand Up @@ -385,6 +387,7 @@ def parse_analysis_protocol_collection(self):
})

sid_protocols.append(data)
self.sip_ref_to_sip_id_lookup[sid_protocol['id']] = sip_int_id
sip_int_id += 1

self.mzid_reader.reset()
Expand Down Expand Up @@ -421,7 +424,7 @@ def parse_analysis_collection(self):
'search_database_refs': search_database_refs
}
spectrum_identification.append(si_data)

self.sil_ref_to_protocol_id_lookup[si['spectrumIdentificationList_ref']] = self.sip_ref_to_sip_id_lookup[si['spectrumIdentificationProtocol_ref']]
self.mzid_reader.reset()
self.logger.info('parsing AnalysisCollection - done. Time: {} sec'.format(
round(time() - start_time, 2)))
Expand Down Expand Up @@ -743,7 +746,7 @@ def main_loop(self):
'scores': psm_level_stats,
'exp_mz': spec_id_item['experimentalMassToCharge'],
'calc_mz': calculated_mass_to_charge,
'sil_id': sil_id,
'sip_id': self.sil_ref_to_protocol_id_lookup[sil_id],
'multiple_spectra_identification_id': msi_id,
'multiple_spectra_identification_pc': msi_pc,
}
Expand Down
12 changes: 6 additions & 6 deletions tests/test_mzid_1_3_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,42 +31,42 @@ def test_psql_multi_spectra_mzid_parser(tmpdir, db_info, use_database, engine):
assert results[0].pep2_id == 'p2'
assert results[0].multiple_spectra_identification_id == 1234
assert results[0].multiple_spectra_identification_pc == 'P'
assert results[0].sil_id == 'sil_HCD'
assert results[0].sip_id == 0 # 'sil_HCD'

assert results[1].id == 'ETD_SII_0'
assert results[1].pep1_id == 'p1'
assert results[1].pep2_id == 'p2'
assert results[1].multiple_spectra_identification_id == 1234
assert results[1].multiple_spectra_identification_pc == 'P'
assert results[1].sil_id == 'sil_ETD'
assert results[1].sip_id == 1 # 'sil_ETD'

assert results[2].id == 'MS3_SII_0'
assert results[2].pep1_id == 'p1_a'
assert results[2].pep2_id is None
assert results[2].multiple_spectra_identification_id == 1234
assert results[2].multiple_spectra_identification_pc == 'C'
assert results[2].sil_id == 'sil_MS3'
assert results[2].sip_id == 2 # 'sil_MS3'

assert results[3].id == 'MS3_SII_1'
assert results[3].pep1_id == 'p2_t'
assert results[3].pep2_id is None
assert results[3].multiple_spectra_identification_id == 1234
assert results[3].multiple_spectra_identification_pc == 'C'
assert results[3].sil_id == 'sil_MS3'
assert results[3].sip_id == 2 # 'sil_MS3'

assert results[4].id == 'MS3_SII_2'
assert results[4].pep1_id == 'p1_t'
assert results[4].pep2_id is None
assert results[4].multiple_spectra_identification_id == 1234
assert results[4].multiple_spectra_identification_pc == 'C'
assert results[4].sil_id == 'sil_MS3'
assert results[4].sip_id == 2 # 'sil_MS3'

assert results[5].id == 'MS3_SII_3'
assert results[5].pep1_id == 'p2_a'
assert results[5].pep2_id is None
assert results[5].multiple_spectra_identification_id == 1234
assert results[5].multiple_spectra_identification_pc == 'C'
assert results[5].sil_id == 'sil_MS3'
assert results[5].sip_id == 2 # 'sil_MS3'

engine.dispose()

Expand Down

0 comments on commit 07d6373

Please sign in to comment.