Ejemplo n.º 1
0
    assert tn.getColNames()[0]=="id"
    assert list(tn.id) == range(len(t))

    tn.renameColumns(int='iii')
    assert set(tn.getVisibleCols()) == { 'iii', 'long', 'id' }

    tn.addColumn('x', 'hi', str, '%s')
    assert set(tn.getVisibleCols()) == { 'iii', 'long', 'id', 'x' }
    assert tn.getColNames()[-1]=="x"

    assert list(tn.x) == ["hi"]*len(tn)

    before = set(os.listdir("temp_output"))
    tn.storeCSV(u"temp_output/x.csv")

    tnre  = ms.loadCSV("temp_output/x.csv")
    assert len(tnre) == len(tn)
    assert tnre.getColNames() == tn.getColNames()
    assert tnre.id.values == tn.id.values
    assert tnre.iii.values == tn.iii.values
    assert tnre.long.values == tn.long.values
    assert tnre.x.values == tn.x.values



    tn.storeCSV("temp_output/x.csv", onlyVisibleColumns=False)
    after = set(os.listdir("temp_output"))
    # file written twice !
    assert len(after-before) == 2
    for n in after-before:
        # maybe we have some x.csv.? from previous run of this
Ejemplo n.º 2
0
def test_handling_of_wrong_answer_from_metlin():
    t = ms.loadCSV("data/metlin_input.csv")
    assert len(t) == 2, len(t)
    tn = ms.matchMetlin(t, "mass__0", ["M"], 3)
    assert len(tn) == 12, len(tn)
    assert set(tn.formula__1.values) == set(["C7H14O6", "C13H10N2"])
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
def testCSVParsing():
    tab = ms.loadCSV("data/mass.csv", )
    fms = '"%.2fm" % (o/60.0)'
    assert tab.getFormat("RT_min") == "%.2f", tab.getFormat("RT_min")
Ejemplo n.º 5
0
import ms

universal = ms.loadCSV(r"tables\universal_metabolites.csv")
universal.renameColumns(
    RT_max="rtmax",
    RT_min="rtmin",
    M0="m0",
    link_to_pubchem="url",
    compouind_name="name",
    MF="mf",
)
universal.replaceColumn("rtmax", universal.rtmax * 60)
universal.replaceColumn("rtmin", universal.rtmin * 60)

universal.set(universal.colFormats, "rtmin", '"%.2fm" % (o/60.0)')
universal.set(universal.colFormats, "rtmax", '"%.2fm" % (o/60.0)')

universal._print()
universal.store(r"tables\universal_metabolites.table", True)
Ejemplo n.º 6
0
    assert tn.getColNames()[0] == "id"
    assert list(tn.id) == range(len(t))

    tn.renameColumns(int='iii')
    assert set(tn.getVisibleCols()) == {'iii', 'long', 'id'}

    tn.addColumn('x', 'hi', str, '%s')
    assert set(tn.getVisibleCols()) == {'iii', 'long', 'id', 'x'}
    assert tn.getColNames()[-1] == "x"

    assert list(tn.x) == ["hi"] * len(tn)

    before = set(os.listdir("temp_output"))
    tn.storeCSV(u"temp_output/x.csv")

    tnre = ms.loadCSV("temp_output/x.csv")
    assert len(tnre) == len(tn)
    assert tnre.getColNames() == tn.getColNames()
    assert tnre.id.values == tn.id.values
    assert tnre.iii.values == tn.iii.values
    assert tnre.long.values == tn.long.values
    assert tnre.x.values == tn.x.values

    tn.storeCSV("temp_output/x.csv", onlyVisibleColumns=False)
    after = set(os.listdir("temp_output"))
    # file written twice !
    assert len(after - before) == 2
    for n in after - before:
        # maybe we have some x.csv.? from previous run of this
        #function so we can not assume that we find x.csv and
        #x.csv.1
Ejemplo n.º 7
0
import ms




universal = ms.loadCSV(r"tables\universal_metabolites.csv")
universal.renameColumns(RT_max="rtmax", RT_min="rtmin", M0="m0", link_to_pubchem="url", compouind_name="name", MF="mf", )
universal.replaceColumn("rtmax", universal.rtmax * 60)
universal.replaceColumn("rtmin", universal.rtmin * 60)

universal.set(universal.colFormats, "rtmin", '"%.2fm" % (o/60.0)')
universal.set(universal.colFormats, "rtmax", '"%.2fm" % (o/60.0)')

universal._print()
universal.store(r"tables\universal_metabolites.table", True)

Ejemplo n.º 8
0
    message += "maybe this caused this exception !"
    if len(e.args) > 0:
        e0 = e.args[0] + "\n" + message
        e.args = (e0, ) + e.args[1:]
    raise e

import os, ms, glob
from libms.Chemistry.Elements import Elements

here = os.path.abspath(os.path.dirname(__file__))

for path in [here] + repositoryPathes:
    path = os.path.join(path, "tables")
    for p in glob.glob("%s/*.csv" % path):
        try:
            table = ms.loadCSV(p)
        except Exception, e:
            import traceback
            traceback.print_exc()
            print "PARSING", p, "FAILED"
            continue
        name, _ = os.path.splitext(os.path.basename(p))
        name = name.replace(" ", "_")
        table.title = name
        exec("%s=table" % name)
        print "LOADED", name, "FROM", p
    # table files overrun csv files !
    for p in glob.glob("%s/*.table" % path):
        try:
            table = ms.loadTable(p)
        except Exception, e:
Ejemplo n.º 9
0
def test_handling_of_wrong_answer_from_metlin():
    t = ms.loadCSV("data/metlin_input.csv")
    assert len(t) == 2, len(t)
    tn = ms.matchMetlin(t, "mass__0", ["M"], 3)
    assert len(tn) == 12, len(tn)
    assert set(tn.formula__1.values) == set(["C7H14O6", "C13H10N2"])
Ejemplo n.º 10
0
Archivo: tab.py Proyecto: burlab/emzed
    message += "maybe this caused this exception !"
    if len(e.args)>0:
        e0 = e.args[0] + "\n" + message
        e.args = (e0,) + e.args[1:]
    raise e

import os, ms, glob
from  libms.Chemistry.Elements import Elements

here = os.path.abspath(os.path.dirname(__file__))

for path in [here] + repositoryPathes:
    path = os.path.join(path, "tables")
    for p in glob.glob("%s/*.csv" % path):
        try:
            table = ms.loadCSV(p)
        except Exception, e:
            import traceback
            traceback.print_exc()
            print "PARSING",p,"FAILED"
            continue
        name, _ = os.path.splitext(os.path.basename(p))
        name = name.replace(" ","_")
        table.title = name
        exec("%s=table" % name)
        print "LOADED", name, "FROM", p
    # table files overrun csv files !
    for p in glob.glob("%s/*.table" % path):
        try:
            table = ms.loadTable(p)
        except Exception, e:
Ejemplo n.º 11
0
def testCSVParsing():
    tab = ms.loadCSV("data/mass.csv", )
    fms = '"%.2fm" % (o/60.0)'
    assert tab.getFormat("RT_min") == "%.2f", tab.getFormat("RT_min")
Ejemplo n.º 12
0
        mode=gui.ChoiceItem("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)