Skip to content

Commit

Permalink
Functional .msp output
Browse files Browse the repository at this point in the history
  • Loading branch information
rodvrees committed May 7, 2024
1 parent 4cf2fde commit c6073e1
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 116 deletions.
6 changes: 5 additions & 1 deletion ms2pip/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
UnresolvableModificationError,
)
from ms2pip.result import correlations_to_csv, results_to_csv
from ms2pip.spectrum_output import write_single_spectrum_csv, write_single_spectrum_png
from ms2pip.spectrum_output import write_single_spectrum_csv, write_single_spectrum_png, SpectrumOutput

console = Console()
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -125,6 +125,10 @@ def predict_library(*args, **kwargs):
logger.info(f'Writing output to {output_name_csv}')
results_to_csv(predictions, output_name_csv)
logger.info(f'Finished writing output to {output_name_csv}')
#TODO: add support for other output formats
# Initial implementation of writing to MSP format
so = SpectrumOutput(predictions, normalization="basepeak_10000")
so.write_msp()



Expand Down
2 changes: 1 addition & 1 deletion ms2pip/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def results_to_csv(results: List["ProcessingResult"], output_file: str) -> None:
writer.writerow(
{
"psm_index": result.psm_index,
"peptidoform": result.psm.peptidoform,
"peptidoform": result.psm.peptidoform, #TODO Remove this, was for checking correctness
"ion_type": ion_type,
"ion_number": i + 1,
"mz": "{:.6g}".format(result.theoretical_mz[ion_type][i]),
Expand Down
4 changes: 2 additions & 2 deletions ms2pip/search_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def into_psm_list(self, min_precursor_mz = 0, max_precursor_mz = np.Inf) -> PSML
for modifications, charge in product(self.modification_options, self.charge_options):
offset = 0
if not modifications:
psm = PSM(peptidoform=(self.sequence+'/{}'.format(charge)), spectrum_id=spectrum_id)
psm = PSM(peptidoform=(self.sequence+'/{}'.format(charge)), spectrum_id=spectrum_id, protein_list=self.proteins)
spectrum_id += 1
else:
modded_sequence = list(self.sequence)
Expand All @@ -86,7 +86,7 @@ def into_psm_list(self, min_precursor_mz = 0, max_precursor_mz = np.Inf) -> PSML
modded_sequence.append(f"-[{mod}]")

modded_sequence = "".join(modded_sequence)
psm = PSM(peptidoform=(modded_sequence+'/{}'.format(charge)), spectrum_id=spectrum_id)
psm = PSM(peptidoform=(modded_sequence+'/{}'.format(charge)), spectrum_id=spectrum_id, protein_list=self.proteins)
spectrum_id += 1
if psm.peptidoform.theoretical_mz >= min_precursor_mz and psm.peptidoform.theoretical_mz <= max_precursor_mz:
psms.append(psm)
Expand Down
Loading

0 comments on commit c6073e1

Please sign in to comment.