Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEAKS support and various fixes/improvements #35

Merged
merged 28 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
44a0eb1
Added Peaks_pipeline
ArthurDeclercq Aug 20, 2021
fd7fb3e
Peaks pipeline update, plotting bug fix
ArthurDeclercq Aug 27, 2021
c3d8778
bug fix percolator modification mapping
ArthurDeclercq Sep 1, 2021
b27dad3
updating Peaks pipeline, fixes plotting module
ArthurDeclercq Sep 1, 2021
e5d288e
bux fixes percolator pipeline, peaks pipeline and plotting module
ArthurDeclercq Sep 3, 2021
bc1b0ce
bug fix parse mgf
ArthurDeclercq Sep 15, 2021
195164e
retention time calibration for each raw file
ArthurDeclercq Sep 28, 2021
bfc65ae
bug fix config parser
ArthurDeclercq Sep 28, 2021
4260ddc
removing print sstatements
ArthurDeclercq Sep 28, 2021
a6156a9
num calibration fix
ArthurDeclercq Sep 30, 2021
2ce3667
tiny fixes in plottting module and Peaks pipeline
ArthurDeclercq Oct 11, 2021
e69001d
DeepLC import fix
ArthurDeclercq Oct 11, 2021
ada66dc
Pattern change in to allow for +, - or nothing
ArthurDeclercq Oct 11, 2021
6bc2b14
requested changes
ArthurDeclercq Nov 5, 2021
8b00ebc
requested changes, added CL parameters
ArthurDeclercq Nov 10, 2021
1c7bede
removed mgf argument from maxquant_to_rescore dict in config file
ArthurDeclercq Nov 17, 2021
9e696fb
requested changes
ArthurDeclercq Nov 17, 2021
d24bfea
optimized model selection deeplc
ArthurDeclercq Nov 18, 2021
6c35e19
add plotting warning if percolator is disabled
ArthurDeclercq Nov 23, 2021
23711a0
Merge branch 'master' into feature/Peaks_id_file_parser
ArthurDeclercq Nov 23, 2021
04c1c46
MS2ReScoreError fix
ArthurDeclercq Nov 23, 2021
ba94f3e
MS2ReScoreError fix (2)
ArthurDeclercq Nov 23, 2021
eb4e15d
another MS2rescoreError fix
ArthurDeclercq Nov 23, 2021
20bd6a1
added decoy error, searchengine feature
ArthurDeclercq Dec 2, 2021
5e91a68
parse_mgf: Fix removal of lines with zero peak intensity
RalfG Dec 14, 2021
d13af34
Add example to readme for maxquant config section
RalfG Dec 14, 2021
efce2a7
Update README.md: Add PEAKS to supported input
RalfG Dec 14, 2021
c39ef8a
Remove obsolute maxquant mgf dir option
RalfG Dec 14, 2021
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
80 changes: 41 additions & 39 deletions ms2rescore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from multiprocessing import cpu_count
from typing import Dict, Optional, Union

import pandas as pd
from pandas.errors import EmptyDataError

from ms2rescore import id_file_parser, rescore_core, setup_logging
from ms2rescore._exceptions import MS2ReScoreError
Expand Down Expand Up @@ -108,21 +108,21 @@ def _infer_pipeline(identification_file: str):

def _select_pipeline(self):
"""Select specific rescoring pipeline."""
if self.config["general"]["pipeline"] == "infer":
if self.config["general"]["pipeline"].lower() == "infer":
pipeline = self._infer_pipeline(
self.config["general"]["identification_file"]
)
elif self.config["general"]["pipeline"] == "pin":
elif self.config["general"]["pipeline"].lower() == "pin":
pipeline = id_file_parser.PinPipeline
elif self.config["general"]["pipeline"] == "maxquant":
elif self.config["general"]["pipeline"].lower() == "maxquant":
pipeline = id_file_parser.MaxQuantPipeline
elif self.config["general"]["pipeline"] == "msgfplus":
elif self.config["general"]["pipeline"].lower() == "msgfplus":
pipeline = id_file_parser.MSGFPipeline
elif self.config["general"]["pipeline"] == "tandem":
elif self.config["general"]["pipeline"].lower() == "tandem":
pipeline = id_file_parser.TandemPipeline
elif self.config["general"]["pipeline"] == "peptideshaker":
elif self.config["general"]["pipeline"].lower() == "peptideshaker":
pipeline = id_file_parser.PeptideShakerPipeline
elif self.config["general"]["pipeline"] == "Peaks":
elif self.config["general"]["pipeline"].lower() == "peaks":
pipeline = id_file_parser.PeaksPipeline
else:
raise NotImplementedError(self.config["general"]["pipeline"])
Expand Down Expand Up @@ -254,39 +254,41 @@ def run(self):
if self.config["general"]["run_percolator"]:
self._run_percolator()

logger.info("Generating Rescore plots")
if self.config["general"]["plotting"]:
# Only use plotting module when run_percolator is true
if self.config["general"]["plotting"]:
logger.info("Generating Rescore plots")

plotting.PIN(
peprec_filename, self.config["general"]["output_filename"]
)

for fset in self.config["general"]["feature_sets"]:
pout_file = (
self.config["general"]["output_filename"]
+ "_"
+ "_".join(fset)
+ "_features.pout"
plotting.PIN(
peprec_filename, self.config["general"]["output_filename"]
)
pout_decoy_file = (
self.config["general"]["output_filename"]
+ "_"
+ "_".join(fset)
+ "_features.pout_dec"
)
try:
plotting.POUT(
pout_file,
pout_decoy_file,
self.config["general"]["output_filename"],
" ".join(fset)
)
except pd.errors.EmptyDataError:
continue

plotting.RescoreRecord.save_plots_to_pdf(
self.config["general"]["output_filename"] + "_plots.pdf",
FDR_thresholds=[0.01, 0.001],
)
for fset in self.config["general"]["feature_sets"]:
pout_file = (
self.config["general"]["output_filename"]
+ "_"
+ "_".join(fset)
+ "_features.pout"
)
pout_decoy_file = (
self.config["general"]["output_filename"]
+ "_"
+ "_".join(fset)
+ "_features.pout_dec"
)
try:
plotting.POUT(
pout_file,
pout_decoy_file,
self.config["general"]["output_filename"],
" ".join(fset)
)
except EmptyDataError:
logger.warn(f"Feature set: {'_'.join(fset)} returned empty pout file")
continue

plotting.RescoreRecord.save_plots_to_pdf(
self.config["general"]["output_filename"] + "_plots.pdf",
FDR_thresholds=[0.01, 0.001],
)

logger.info("MS²ReScore finished!")
6 changes: 2 additions & 4 deletions ms2rescore/id_file_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

import numpy as np
import pandas as pd
from pyteomics import tandem
from pyteomics import mzid
from pyteomics import tandem, mzid
from tqdm import tqdm

from ms2rescore._exceptions import MS2ReScoreError
Expand Down Expand Up @@ -67,6 +66,7 @@ def __init__(self, config: Dict, output_basename: Union[str, os.PathLike]) -> No
"generic": r".+_([0-9]+)_[0-9]+_[0-9]+",
"tandem": r".+_([0-9]+)_[0-9]+_[0-9]+",
"msgfplus": r".+_SII_([0-9]+)_[0-9]+_[0-9]+_[0-9]+",
"USI": r"mzspec:PXD[0-9]{6}:[^\s\:]*:scan:([0-9]+)"
}

# Private attributes specific to pipeline, override these in each subclass
Expand Down Expand Up @@ -562,8 +562,6 @@ def read_df_from_mzid(self) -> pd.DataFrame:
retrieved_data["charge"] = flat_dict[
"SpectrumIdentificationItem_chargeState"
]
# TODO: create class for SpectrumIdentificationItem
# print(spectrum_identification_result)
retrieved_data["protein_list"] = [
d["accession"]
for d in spectrum_identification_result[
Expand Down
2 changes: 1 addition & 1 deletion ms2rescore/package_data/config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"pipeline": {
"description": "Pipeline to use, depending on input format",
"type": "string",
"enum": ["infer", "pin", "tandem", "maxquant", "msgfplus", "peptideshaker", "Peaks"],
"enum": ["infer", "pin", "tandem", "maxquant", "msgfplus", "peptideshaker", "peaks"],
"default": "infer"
},
"feature_sets": {
Expand Down
5 changes: 3 additions & 2 deletions ms2rescore/percolator.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,13 @@ def _get_sequence_column(self) -> pd.Series:

def _get_charge_column(self) -> pd.Series:
"""Get charge column from one-hot encoded `ChargeX` columns."""
charge_cols = [col for col in self.df.columns if col.startswith("charge")]
charge_cols = [col for col in self.df.columns if col.lower().startswith("charge")]
if not (self.df[charge_cols] == 1).any(axis=1).all():
raise PercolatorInError("Not all PSMs have an assigned charge state.")
return (
self.df[charge_cols]
.rename(
columns={col: int(col.replace("charge", "")) for col in charge_cols}
columns={col: int(col.lower().replace("charge", "")) for col in charge_cols}
)
.idxmax(1)
)
Expand Down Expand Up @@ -424,6 +424,7 @@ def get_feature_table(self) -> pd.DataFrame:
feature_cols = [col for col in self.df.columns if col not in non_feature_cols]
return self.df[feature_cols]

# TODO if USI is used extract_spectrum_index should be False
def to_peptide_record(
self,
extract_spectrum_index: Optional[bool] = True,
Expand Down