Beispiel #1
0
            "mode of operation", ["explore", "targeted extraction"],
            default=1,
            help="for explore mode no parameter table is needed")
        path_para = gui.FileOpenItem("parameter table", ("csv"))
        path_data = gui.FileOpenItem("data file to process",
                                     ("mzXML", "mzML", "mzData"))

    frontend = SRMExplorer()
    exit_code = frontend.show()

    if exit_code == 1:  # means: ok button pressed

        print "LOAD DATA"
        peakmap = ms.loadPeakMap(frontend.path_data)

        if frontend.mode == 1:
            transitions = ms.loadCSV(frontend.path_para)
            # Edit parameter table
            required_columns = [
                "name", "fragment", "precursor", "rtmin", "rtmax"
            ]
            assert transitions.hasColumns(*required_columns),\
                    "Please check column names in parameter table !!"
            transitions.title = "SRM parameter table"
        else:
            transitions = None

        print "PROCESS DATA"
        result = process_srm_data(peakmap, transitions, frontend.delta_mz)
        ms.inspect(result)
Beispiel #2
0
import sys
sys.path.insert(0, "..")
import ms

t = ms.loadTable("integrated_features.table")

t2 = t.copy()

tj = t.join(t2, t.id == t2.id)

tj.rtmin__0 -= 20
tj.rtmax__0 -= 20

pm = tj.peakmap__0.values[0]
for s in pm.spectra:
    s.rt -= 20

ms.inspect(tj)
Beispiel #3
0
    # here we build the result:
    for i in range(1, len(table)):
        result = result.leftJoin(table[i])
    return result


def add_postfix_to_column_names(table, postfix):
    mapping = dict((name, name + postfix) for name in table.colNames)
    table.renameColumns(mapping)


if __name__ == "__main__":

    import libms.gui.DialogBuilder as gui

    class SRMExplorer(gui.WorkflowFrontend):
        n_digits = gui.IntItem("no of significant digits\nof precursor m/z",
                                default=2)
        path = gui.FileOpenItem("data file to process",
                                ("mzXML", "mzML", "mzData"))


    frontend = SRMExplorer()
    exit_code = frontend.show()
    if exit_code:
        print "LOAD DATA"
        peakmap = ms.loadPeakMap(frontend.path)
        print "PROCESS DATA"
        result = process_srm_data(peakmap, frontend.n_digits)
        ms.inspect(result)
Beispiel #4
0
def show():
    ms.inspect(table)
Beispiel #5
0
def show():
    ms.inspect(table)
Beispiel #6
0
#encoding: utf-8
import sys
sys.path.insert(0, "..")

import ms

table = ms.loadTable("features.table")

print table.rows[0]
ms.inspect([table])

Beispiel #7
0
#encoding: utf-8
import sys
sys.path.insert(0, "..")

import ms

table = ms.loadTable("features.table")
table2 = ms.loadTable("integrated_features.table")

ms.inspect([table, table2])
Beispiel #8
0
def test():
    import ms
    pm = ms.loadPeakMap("emzed_files/example1.mzXML")
    t = metaboFeatureFinder(pm, epdet_width_filtering="auto")
    ms.inspect(t)
Beispiel #9
0
def test():
    import ms
    pm = ms.loadPeakMap("emzed_files/example1.mzXML")
    t = metaboFeatureFinder(pm, epdet_width_filtering="auto")
    ms.inspect(t)
Beispiel #10
0
def mzAlign(table,
            fullC13=False,
            tol=15 * MMU,
            mz_reference_table=None,
            destination=None,
            minR2=0.95,
            minPoints=5,
            interactive=False):
    """
    performs affine linear mz-correction for a feature table.

    you need a ``mz_reference_table`` with the theoretical ideal masses
    and retention times of some universal metabolites. This table needs
    columns ``m0`` for the neutral mass, ``rtmin``, ``rtmax`` for the
    retention time window for restricting the match of the table against
    the  ``mz_reference_table`` and the molecular formula ``mf``.

    If you specify ``fullC13=True`` the ``mf`` is used to correct ``m0``.

    ``destination`` is a directory which will be used for storing the
    result and intermediate data.  If you do not specify this value, a
    dialog for choosing the destination directory will be opened.

    The input table **is not mofied** in place, the function returns the
    aligned table.

    """

    import ms
    import tab
    import os
    import numpy as np
    from _mzalign_helpers import (_buildHypotheseTable, _findMzMatches,
                                  _findParametersAutomatically,
                                  _findParametersManually, _plotAndSaveMatch,
                                  _applyTransform)
    if not interactive:
        assert minR2 <= 1.0
        assert minPoints > 1

    sources = set(table.source.values)
    assert len(sources) == 1
    source = sources.pop()

    if mz_reference_table is None:
        mz_reference_table = tab.universal_metabolites
    univ = mz_reference_table
    univ.requireColumn("m0")
    univ.requireColumn("rtmin")
    univ.requireColumn("rtmax")
    univ.requireColumn("mf")
    assert univ.get(univ.colTypes, "m0") == float,\
        "col m0 is not float"
    assert univ.get(univ.colTypes, "rtmin") == float,\
        "col rtmin is not float"
    assert univ.get(univ.colTypes, "rtmax") == float,\
        "col rtmax is not float"

    polarities = set(table.polarity.values)
    assert len(polarities) == 1, "multiple polarities in table"
    polarity = polarities.pop()

    hypot = _buildHypotheseTable(polarity, univ.copy(), fullC13)

    if destination is not None:
        basename = os.path.basename(source)
        fname, _ = os.path.splitext(basename)
        hypot.store(os.path.join(destination, fname + "_hypot.table"), True)

    real, tobe, matches = _findMzMatches(hypot, table, tol)
    if len(real) <= 1:
        print "NOT ENOUGH MATCHES"
        return

    if interactive:
        ms.inspect(matches, offerAbortOption=True)

    elif len(tobe) < minPoints:
        raise Exception("could only match %d peaks" % len(tobe))

    if not interactive:
        transform, used = _findParametersAutomatically(tobe.copy(), real.copy(),\
                                                      minR2, minPoints)
    else:
        transform, used = _findParametersManually(tobe.copy(), real.copy())
        if transform is None:
            print "ABORTED"
            return

    if destination is not None:
        matches.addColumn("error", np.linalg.norm(transform(real)-tobe), float,\
                          "%.3e")
        matches.store(os.path.join(destination, fname + "_mzalign.table"),
                      True)
        matches.storeCSV(os.path.join(destination, fname + "_mzalign.csv"))

        path = os.path.join(destination, fname + "_mzalign.png")
        _plotAndSaveMatch(tobe, real, used, transform, path)

    transformedTable = _applyTransform(table, transform)
    print "DONE"
    return transformedTable
Beispiel #11
0
::

"""
run("""common = joined.filter(joined.onEarth_1==1)
common._print()""")

MMU=0.001

print """

The ``tab`` module contains some databases, eg the substances from pubchem 
categorized as *metabolomic compounds*::

"""

run("""import tab # some standard tables
pc = tab.pc_full
ms.inspect(pc)""")

print """

Before matching our data against the large pubchem table, we build an index on tthis table in order to speed up the following ``leftJoin`` call. Building an index is done by sorting the corresponding column::

"""
run("""pc.sortBy("m0")
matched=joined.leftJoin(pc, (joined.onEarth_1==1) 
                           & joined.m0.approxEqual(pc.m0, 15*MMU))""")
run("matched.meta=dict()")
run("""print matched.numRows()""")
run("""ms.inspect(matched)""")