Beispiel #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
Beispiel #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"])
Beispiel #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)
Beispiel #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")
Beispiel #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)
Beispiel #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
Beispiel #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)

Beispiel #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:
Beispiel #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"])
Beispiel #10
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:
Beispiel #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")
Beispiel #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)