Skip to content

Commit

Permalink
Merge pull request #35 from ArthurDeclercq/feature/Peaks_id_file_parser
Browse files Browse the repository at this point in the history
Feature/peaks id file parser
  • Loading branch information
RalfG authored Dec 14, 2021
2 parents 8ef9ccd + c39ef8a commit 1a95e0c
Show file tree
Hide file tree
Showing 14 changed files with 468 additions and 136 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ MS²Rescore uses identifications from a
or from the output of one of these search engines:

- [MaxQuant](https://www.maxquant.org/): Start from `msms.txt` identification
file and directory with `.mgf` files. (Be sure to export without FDR
filtering!)
file and directory with `.mgf` files.
- [MSGFPlus](https://omics.pnl.gov/software/ms-gf): Start with an `.mzid`
identification file and corresponding `.mgf`.
- [X!Tandem](https://www.thegpm.org/tandem/): Start with an X!Tandem `.xml`
identification file and corresponding `.mgf`.
- [PEAKS](https://www.bioinfor.com/peaksdb/): Start with an `.mzid` identification
file and directory with `.mgf` files.
- [PeptideShaker](http://compomics.github.io/projects/peptide-shaker): Start with a
PeptideShaker Extended PSM Report and corresponding `.mgf` file.

Expand Down Expand Up @@ -187,6 +188,17 @@ one of the modifications listed in the MS²PIP configuration (see
- `fixed_modifications`: Must list all modifications set as fixed during the
MaxQuant search (as this is not denoted in the msms.txt file). Keys refer to the
amino acid, values to the modification name used in the MS²PIP configuration.
- The maxquant specific configuration could for example be:
```json
"maxquant_to_rescore": {
"modification_mapping":{
"ox":"Oxidation",
"cm":"Carbamidomethyl"
},
"fixed_modifications":{
"C":"Carbamidomethyl"
}
```

As a general rule, MS²Rescore always needs access to all target and decoy PSMs, not
only the FDR-filtered targets.
Expand Down
1 change: 0 additions & 1 deletion configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
- **Items**: Refer to *#/definitions/modifications*.
- **`percolator`** *(object)*: Command line options directly passed to Percolator (see the Percolator wiki).
- **`maxquant_to_rescore`** *(object)*: Settings specific to the MaxQuant pipeline. Cannot contain additional properties.
- **`mgf_dir`** *(string)*: Path to directory with MGF files.
- **`modification_mapping`** *(object)*: Mapping of MaxQuant modification labels to modifications names for MS²PIP. Default: `{}`.
- **`fixed_modifications`** *(object)*: Mapping of amino acids with fixed modifications to the modification name. Default: `{}`.
## Definitions
Expand Down
69 changes: 41 additions & 28 deletions ms2rescore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from multiprocessing import cpu_count
from typing import Dict, Optional, Union

from pandas.errors import EmptyDataError

from ms2pip.ms2pipC import MS2PIP

from ms2rescore import id_file_parser, plotting, rescore_core, setup_logging
Expand Down Expand Up @@ -44,6 +46,7 @@ def __init__(
self.config = parse_config(
parse_cli_args=parse_cli_args, config_class=configuration
)

if set_logger:
setup_logging.setup_logging(self.config["general"]["log_level"])

Expand Down Expand Up @@ -119,6 +122,8 @@ def _select_pipeline(self):
pipeline = id_file_parser.TandemPipeline
elif self.config["general"]["pipeline"] == "peptideshaker":
pipeline = id_file_parser.PeptideShakerPipeline
elif self.config["general"]["pipeline"] == "peaks":
pipeline = id_file_parser.PeaksPipeline
else:
raise NotImplementedError(self.config["general"]["pipeline"])
return pipeline
Expand Down Expand Up @@ -216,6 +221,7 @@ def _run_percolator(self):
def run(self):
"""Run MS²ReScore."""
peprec = self.pipeline.get_peprec()
peprec.validate_decoy_presence()
peprec_filename = self.tmpfile_basepath + ".peprec"
peprec.to_csv(peprec_filename)

Expand Down Expand Up @@ -254,35 +260,42 @@ def run(self):
if self.config["general"]["run_percolator"]:
self._run_percolator()

logger.info("Generating Rescore plots")
if self.config["general"]["plotting"]:

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

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"
)
plotting.POUT(
pout_file,
pout_decoy_file,
self.config["general"]["output_filename"],
" ".join(fset)
)
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],
)
if not self.config["general"]["run_percolator"] and self.config["general"]["plotting"]:
logger.warn("To plot rescore results run_percolator should be enabled")
logger.info("MS²ReScore finished!")
38 changes: 38 additions & 0 deletions ms2rescore/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,42 @@ def _parse_arguments() -> argparse.Namespace:
default="info",
help="logging level (default: `info`)",
)
parser.add_argument(
"-n",
metavar="VALUE",
action="store",
type=int,
dest="num_cpu",
default=None,
help="number of cpus available to MS²Rescore",
)
parser.add_argument(
"--pipeline",
metavar="PIPELINE",
action="store",
type=str,
dest="pipeline",
default=None,
help="determines which pipeline to use (default: 'infer')",
)
parser.add_argument(
"--percolator",
metavar="BOOL",
action="store",
type=bool,
dest="run_percolator",
default=None,
help="run percolator (default: 'True')",
)
parser.add_argument(
"--plotting",
metavar="BOOL",
action="store",
type=bool,
dest="plotting",
default=None,
help="write PDF with result plots",
)
return parser.parse_args()


Expand Down Expand Up @@ -156,4 +192,6 @@ def parse_config(parse_cli_args: bool = True, config_class: Optional[Dict] = Non
config = _validate_filenames(config)
config = _validate_num_cpu(config)

config["general"]["pipeline"] = config["general"]["pipeline"].lower()

return config
Loading

0 comments on commit 1a95e0c

Please sign in to comment.