Skip to content

Commit

Permalink
validate_peptides.py -> spectrumai.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ypriverol committed Apr 24, 2024
1 parent 96341a4 commit f2d58c8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
25 changes: 12 additions & 13 deletions pypgatk/commands/validate_peptides.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
import click

from pypgatk.toolbox.general import read_yaml_from_file
from pypgatk.proteogenomics.validate_peptides import ValidatePeptidesService
from pypgatk.proteogenomics.spectrumai import SpectrumAIService
from pypgatk.commands.utils import print_help

log = logging.getLogger(__name__)


@click.command('validate_peptides',
@click.command('spectrumai',
short_help='Command to inspect MS2 spectra of single-subsititution peptide identifications')
@click.option('-c', '--config_file', help='Configuration file for the validate peptides pipeline')
@click.option('-p', '--mzml_path', help='The mzml file path.You only need to use either mzml_path or mzml_files')
@click.option('-f', '--mzml_files',
help='The mzml files.Different files are separated by ",".You only need to use either mzml_path or mzml_files')
@click.option('-f', '--mzml_files', help='The mzml files. Different files are separated by ","')
@click.option('-i', '--infile_name', help='Variant peptide PSMs table')
@click.option('-o', '--outfile_name', help='Output file for the results')
@click.option('-ion', '--ions_tolerance', help='MS2 fragment ions mass accuracy')
Expand All @@ -25,8 +24,8 @@
help='If the tsv was obtained from mzTab, please enable this option. Default to tsv obtained from parquet',
is_flag=True)
@click.pass_context
def validate_peptides(ctx, config_file, mzml_path, mzml_files, infile_name, outfile_name, ions_tolerance,
number_of_processes, relative, mztab):
def spectrumai(ctx, config_file, mzml_path, mzml_files, infile_name, outfile_name, ions_tolerance,
number_of_processes, relative, mztab):
config_data = None
if config_file is not None:
config_data = read_yaml_from_file(config_file)
Expand All @@ -38,18 +37,18 @@ def validate_peptides(ctx, config_file, mzml_path, mzml_files, infile_name, outf
pipeline_arguments = {}

if mzml_path is not None:
pipeline_arguments[ValidatePeptidesService.CONFIG_MZML_PATH] = mzml_path
pipeline_arguments[SpectrumAIService.CONFIG_MZML_PATH] = mzml_path
if mzml_files is not None:
pipeline_arguments[ValidatePeptidesService.CONFIG_MZML_FILES] = mzml_files
pipeline_arguments[SpectrumAIService.CONFIG_MZML_FILES] = mzml_files
if ions_tolerance is not None:
pipeline_arguments[ValidatePeptidesService.CONFIG_IONS_TOLERANCE] = ions_tolerance
pipeline_arguments[SpectrumAIService.CONFIG_IONS_TOLERANCE] = ions_tolerance
if number_of_processes is not None:
pipeline_arguments[ValidatePeptidesService.CONFIG_NUMBER_OF_PROCESSES] = number_of_processes
pipeline_arguments[SpectrumAIService.CONFIG_NUMBER_OF_PROCESSES] = number_of_processes
if relative is not None:
pipeline_arguments[ValidatePeptidesService.CONFIG_RELATIVE] = relative
pipeline_arguments[SpectrumAIService.CONFIG_RELATIVE] = relative
if mztab is not None:
pipeline_arguments[ValidatePeptidesService.CONFIG_MZTAB] = mztab
pipeline_arguments[SpectrumAIService.CONFIG_MZTAB] = mztab

validate_peptides_service = ValidatePeptidesService(config_data, pipeline_arguments)
validate_peptides_service = SpectrumAIService(config_data, pipeline_arguments)
if validate_flag:
validate_peptides_service.validate(infile_name, outfile_name)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pypgatk.toolbox.general import ParameterConfiguration


class ValidatePeptidesService(ParameterConfiguration):
class SpectrumAIService(ParameterConfiguration):
CONFIG_KEY_VALIDATE_PEPTIDES = 'validate_peptides'
CONFIG_MZML_PATH = 'mzml_path'
CONFIG_MZML_FILES = 'mzml_files'
Expand All @@ -28,8 +28,8 @@ def __init__(self, config_data, pipeline_arguments):
:param pipeline_arguments pipelines arguments
"""

super(ValidatePeptidesService, self).__init__(self.CONFIG_KEY_VALIDATE_PEPTIDES, config_data,
pipeline_arguments)
super(SpectrumAIService, self).__init__(self.CONFIG_KEY_VALIDATE_PEPTIDES, config_data,
pipeline_arguments)

self._mzml_path = self.get_validate_parameters(variable=self.CONFIG_MZML_PATH, default_value=False)
self._mzml_files = self.get_validate_parameters(variable=self.CONFIG_MZML_FILES, default_value=False)
Expand All @@ -51,6 +51,7 @@ def get_validate_parameters(self, variable: str, default_value):
return value_return

def _predict_MS2_spectrum(self, peptide, size, product_ion_charge=1):

tsg = TheoreticalSpectrumGenerator()
spec = MSSpectrum()
peptide = AASequence.fromString(peptide)
Expand Down Expand Up @@ -314,7 +315,6 @@ def validate(self, infile_name, outfile_name: str):

df_output = pd.concat(self.df_list, axis=0, ignore_index=True)


if outfile_name.endswith(".csv.gz"):
df_output.to_csv(outfile_name, header=True, sep=",", index=None, compression="gzip")
elif outfile_name.endswith(".csv"):
Expand Down
2 changes: 1 addition & 1 deletion pypgatk/pypgatk_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def cli():
cli.add_command(proteindb_decoy_cmd.generate_database)
cli.add_command(proteindb_decoy_cmd.generate_database)
cli.add_command(peptide_class_fdr_cmd.peptide_class_fdr)
cli.add_command(validate_peptides_cmd.validate_peptides)
cli.add_command(validate_peptides_cmd.spectrumai)
cli.add_command(mztab_class_fdr_cmd.mztab_class_fdr)
cli.add_command(blast_get_position_cmd.blast_get_position)

Expand Down

0 comments on commit f2d58c8

Please sign in to comment.