Skip to content

Commit

Permalink
Merge pull request #130 from Proteobench/add_tests_parsing
Browse files Browse the repository at this point in the history
✅Test MQ parameter extraction, document output
  • Loading branch information
wolski authored Nov 23, 2023
2 parents 690ce5d + acbb136 commit e509ecf
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 5 deletions.
7 changes: 6 additions & 1 deletion proteobench/io/params/maxquant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from __future__ import annotations

import collections
import json
import logging
import xml.etree.ElementTree as ET
from pathlib import Path
Expand Down Expand Up @@ -207,6 +206,7 @@ def extract_params(fname, ms2frac="FTMS") -> ProteoBenchParameters:

# create a first version of json files to match
if __name__ == "__main__":
import json
from pprint import pprint

for test_file in [
Expand All @@ -231,3 +231,8 @@ def extract_params(fname, ms2frac="FTMS") -> ProteoBenchParameters:
record.to_csv(Path(test_file).with_suffix(".csv"))
params = extract_params(test_file, ms2frac="FTMS")
pprint(params.__dict__)
test_file = Path(test_file)
fname = test_file.with_suffix(".json").with_stem(test_file.stem + "_sel")

with open(fname, "w") as f:
json.dump(params.__dict__, f, indent=4)
21 changes: 21 additions & 0 deletions test/params/mqpar1.5.3.30_MBR_sel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"software_name": null,
"software_version": "1.5.3.30",
"search_engine": "Andromeda",
"search_engine_version": null,
"ident_fdr_psm": null,
"ident_fdr_peptide": "0.01",
"ident_fdr_protein": "0.01",
"enable_match_between_runs": "true",
"precursor_mass_tolerance": "4.5 ppm",
"fragment_mass_tolerance": "20 ppm",
"enzyme": "Trypsin/P",
"allowed_miscleavages": "2",
"min_peptide_length": "7",
"max_peptide_length": null,
"fixed_mods": "Carbamidomethyl (C)",
"variable_mods": "Oxidation (M),Acetyl (Protein N-term)",
"max_mods": "5",
"min_precursor_charge": null,
"max_precursor_charge": "7"
}
21 changes: 21 additions & 0 deletions test/params/mqpar_MQ1.6.3.3_MBR_sel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"software_name": null,
"software_version": "1.6.3.3",
"search_engine": "Andromeda",
"search_engine_version": null,
"ident_fdr_psm": null,
"ident_fdr_peptide": "0.01",
"ident_fdr_protein": "0.01",
"enable_match_between_runs": "True",
"precursor_mass_tolerance": "4.5 ppm",
"fragment_mass_tolerance": "20 ppm",
"enzyme": "Trypsin/P",
"allowed_miscleavages": "2",
"min_peptide_length": "7",
"max_peptide_length": null,
"fixed_mods": "Carbamidomethyl (C)",
"variable_mods": "Oxidation (M),Acetyl (Protein N-term)",
"max_mods": "5",
"min_precursor_charge": null,
"max_precursor_charge": "7"
}
21 changes: 21 additions & 0 deletions test/params/mqpar_MQ2.1.3.0_noMBR_sel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"software_name": null,
"software_version": "2.1.3.0",
"search_engine": "Andromeda",
"search_engine_version": null,
"ident_fdr_psm": null,
"ident_fdr_peptide": "0.01",
"ident_fdr_protein": "0.01",
"enable_match_between_runs": "False",
"precursor_mass_tolerance": "4.5 ppm",
"fragment_mass_tolerance": "20 ppm",
"enzyme": "Trypsin/P",
"allowed_miscleavages": "2",
"min_peptide_length": "7",
"max_peptide_length": null,
"fixed_mods": "Carbamidomethyl (C)",
"variable_mods": "Oxidation (M),Acetyl (Protein N-term)",
"max_mods": "5",
"min_precursor_charge": null,
"max_precursor_charge": "7"
}
22 changes: 18 additions & 4 deletions test/test_parse_params_maxquant.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

TESTDATA_DIR = Path(__file__).parent / "params"

mq_paras = [
mqpar_fnames = [
"mqpar_MQ1.6.3.3_MBR.xml",
"mqpar_MQ2.1.3.0_noMBR.xml",
"mqpar1.5.3.30_MBR.xml",
]

mq_paras = [TESTDATA_DIR / mq_para for mq_para in mq_paras]
mqpar_fnames = [TESTDATA_DIR / mq_para for mq_para in mqpar_fnames]


parameters = [
Expand All @@ -38,7 +38,7 @@ def test_list_of_tuple_expansion():
assert actual == expected


parameters = [(fname, Path(fname).with_suffix(".json")) for fname in mq_paras]
parameters = [(fname, fname.with_suffix(".json")) for fname in mqpar_fnames]


@pytest.mark.parametrize("file,json_expected", parameters)
Expand Down Expand Up @@ -96,7 +96,7 @@ def test_flatten_of_dicts(dict_in, list_expected):
assert actual == list_expected


parameters = [(fname, Path(fname).with_suffix(".csv")) for fname in mq_paras]
parameters = [(fname, fname.with_suffix(".csv")) for fname in mqpar_fnames]


@pytest.mark.parametrize("file,csv_expected", parameters)
Expand All @@ -107,3 +107,17 @@ def test_file_parsing_to_csv(file, csv_expected):
actual = actual.to_frame("run_identifier")
actual = pd.read_csv(io.StringIO(actual.to_csv()), index_col=[0, 1, 2, 3])
assert actual.equals(expected)


parameters = [
(fname, (fname.parent / (fname.stem + "_sel.json"))) for fname in mqpar_fnames
]


@pytest.mark.parametrize("file,json_expected", parameters)
def test_extract_params(file, json_expected):
with open(json_expected) as f:
expected = json.load(f)
actual = mq_params.extract_params(file)
actual = actual.__dict__
assert actual == expected

0 comments on commit e509ecf

Please sign in to comment.