Convert parameters (mqrun.mqparams)

Convert between json or yaml and MaxQuant configuration files.

Contents

xml_to_data(xml_tree[, logger]) Extract parameters and file-paths from MaxQuant configuration file
data_to_xml(user_data, file_paths, ...[, ...]) Convert parameter set to MaxQuant xml.
mqrun(binpath, params, datapaths, outdir, tmpdir) Run MaxQuant with specified parameters and paths.

Parameters files

Example data:

>>> import json
>>> from pathlib import Path
>>> from pprint import pprint

>>> # TODO how about some sensible parameters ;-)
>>> with open('paramfile.json') as f:
>>>    param_file = f.read()

>>> print(param_file)
{
    "rawFiles": [
        {
            "name": "input1",
            "params": {
                "defaults": "default",
                "variableModifications": [
                    "Oxidation (M)",
                ]
            }
        },
        {
            "name": "input2",
            "params": {
                "defaults" :"default",
            }
        }
    "fastaFiles": {
        "fileNames": ["fasta1"],
        "firstSearch": ["fasta1"],
    }
    "globalParams": {
        "defaults": "default",
        "matchBetweenRuns": True
    }
}

>>> # load json data
>>> params = json.load(param_file)

Each parameter file must contain the sections “rawFiles” and “fastaFiles”. “globalParams” and “MSMSParams” are optional.

The input files (raw and fasta) are only identified by a unique name. You must specify the paths for each of the input files in a dictionary and pass that to the relevant functions.

The “params” sections in “rawFiles” and the sections “globalParams” and “MSMSParams” have the optional argument “defaults”, that specifies default values for the other parameters in that section.

# TODO: write some of those and document how to add more

mqschema.json contains a json-schema for this file format along with descriptions for a few of the parameters.

Example

To convert above parameters to xml wee need a mapping to the file paths of the input files. Let’s say they are stored in the following locations:

>>> paths = {
>>>     "input1": Path("C://data/input1.raw")
>>>     "input2": Path("C://data/input2.raw")
>>>     "fasta1": Path("C://data/fasta1.fasta")
>>> }

Convert to xml:

>>> outdir = Path('C://output/')
>>> tmpdir = Path('C://tmp')
>>> xmltree = data_to_xml(params, paths, outdir, tmpdir)

We can now write that xml file to disk and run MaxQuantCmd on it:

>>> xmltree.write(str(outdir / "params.xml"))

To convert it back to our json format we do:

>>> params_, path_data = xml_to_data(xmltree)
>>> path_data.paths == paths
True
>>> path_data.outdir == outdir
True
>>> path_data.tmpdir == tmpdir
True

Since the xml file does not contain information about which default values have been used, it specifies all values and differs from the original. But converting it back to xml should yield the same result as before:

>>> from sort_xml_tags import equal_sorted
>>> xmltree_ = data_to_xml(params_, *path_data)
>>> equal_sorted(xmltree_, xmltree)
True