diff --git a/proteobench/io/params/maxquant.py b/proteobench/io/params/maxquant.py index 979e9f40..f74bd306 100644 --- a/proteobench/io/params/maxquant.py +++ b/proteobench/io/params/maxquant.py @@ -2,7 +2,6 @@ from __future__ import annotations import collections -import json import logging import xml.etree.ElementTree as ET from pathlib import Path @@ -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 [ @@ -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) diff --git a/test/params/mqpar1.5.3.30_MBR_sel.json b/test/params/mqpar1.5.3.30_MBR_sel.json new file mode 100644 index 00000000..1f2a86db --- /dev/null +++ b/test/params/mqpar1.5.3.30_MBR_sel.json @@ -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" +} \ No newline at end of file diff --git a/test/params/mqpar_MQ1.6.3.3_MBR_sel.json b/test/params/mqpar_MQ1.6.3.3_MBR_sel.json new file mode 100644 index 00000000..7926d42f --- /dev/null +++ b/test/params/mqpar_MQ1.6.3.3_MBR_sel.json @@ -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" +} \ No newline at end of file diff --git a/test/params/mqpar_MQ2.1.3.0_noMBR_sel.json b/test/params/mqpar_MQ2.1.3.0_noMBR_sel.json new file mode 100644 index 00000000..0258c2d4 --- /dev/null +++ b/test/params/mqpar_MQ2.1.3.0_noMBR_sel.json @@ -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" +} \ No newline at end of file diff --git a/test/test_parse_params_maxquant.py b/test/test_parse_params_maxquant.py index df3c2714..7c7320c3 100644 --- a/test/test_parse_params_maxquant.py +++ b/test/test_parse_params_maxquant.py @@ -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 = [ @@ -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) @@ -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) @@ -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