Exemplo n.º 1
0
def testAlignFeatureTables():
    ft = ms.loadTable("data/features.table")
    irt = ft.getIndex("rt")

    # make copy and shift
    ft2 = copy.deepcopy(ft)
    ix = ft2.getIndex("rt")
    for r in ft2.rows:
        r[ix] += 2.0
    # delete one row, so ft should become reference map !
    del ft2.rows[-1]

    ftneu, ft2neu = ms.rtAlign([ft, ft2],
                               destination="temp_output",
                               nPeaks=9999,
                               numBreakpoints=2)
    irt = ft.getIndex("rt")

    def getrt(t):
        return np.array([r[irt] for r in t.rows])

    # refmap ft should not be changed:
    assert np.all(getrt(ftneu) == getrt(ft))
    # but ft2 should:
    assert np.linalg.norm(getrt(ft2neu) - getrt(ft2)) >= 7.9

    # now ftneu and ft2neu should be very near.
    # remenber: ft2 has not as much rows as ft, so:
    assert np.linalg.norm(getrt(ft2neu) - getrt(ftneu)[:-1]) < 1e-6

    # alignmen should produce alignment map:
    assert osp.exists("temp_output/test_aligned.png")
Exemplo n.º 2
0
def testAlignFeatureTables():
    ft = ms.loadTable("data/features.table")
    irt = ft.getIndex("rt")

    # make copy and shift
    ft2=copy.deepcopy(ft)
    ix = ft2.getIndex("rt")
    for r in ft2.rows:
        r[ix] += 2.0
    # delete one row, so ft should become reference map !
    del ft2.rows[-1]

    ftneu, ft2neu = ms.rtAlign([ft,ft2],
                                          destination="temp_output",
                                          nPeaks=9999,
                                          numBreakpoints=2)
    irt = ft.getIndex("rt")
    def getrt(t):
        return np.array([r[irt] for r in t.rows])

    # refmap ft should not be changed:
    assert np.all(getrt(ftneu) == getrt(ft))
    # but ft2 should:
    assert np.linalg.norm(getrt(ft2neu) - getrt(ft2)) >= 7.9

    # now ftneu and ft2neu should be very near.
    # remenber: ft2 has not as much rows as ft, so:
    assert np.linalg.norm(getrt(ft2neu) - getrt(ftneu)[:-1]) < 1e-6

    # alignmen should produce alignment map:
    assert osp.exists("temp_output/test_aligned.png")
Exemplo n.º 3
0
def testRunnerTable():

    with ExceptionTester():
        Table(["a"],[np.float32],["%f"],[[32.0]])

    #build table
    names="int long float str object array".split()
    types = [int, long, float, str, object, np.ndarray,]
    formats = [ "%3d", "%d", "%.3f", "%s", "%r", "'array(%r)' % (o.shape,)" ]

    row1 = [ 1, 12323L, 1.0, "hi", { 1: 1 },  np.array((1,2,3)) ]
    row2 = [ 2, 22323L, 2.0, "hi2", [2,3,], np.array(((2,3,4),(1,2,3))) ]
    row3 = [ 3, 32323L, 3.0, "hi3", (3,) , np.array(((3,3,4,5),(1,2,3,4))) ]

    rows = [row1, row2, row3]
    t=Table(names, types, formats, rows, "testtabelle", meta=dict(why=42))


    run(t, names, [row1, row2, row3])
    # test pickle
    dat = pickle.dumps(t)
    t = pickle.loads(dat)
    run(t, names, [row1, row2, row3])
    ms.storeTable(t, u"temp_output/test.table")
    try:
        ms.storeTable(t, "temp_output/test.table")
        assert False, "no exception thrown althoug file should exist!"
    except:
        pass
    ms.storeTable(t, "temp_output/test.table", True)
    t = ms.loadTable("temp_output/test.table")
    run(t, names, [row1, row2, row3])
Exemplo n.º 4
0
def testPoseClustering():
    ft = ms.loadTable("data/features.table")
    irt = ft.getIndex("rt")

    # make copy and shift
    ft2 = copy.deepcopy(ft)

    def shift(t, col):
        ix = t.getIndex(col)
        for r in t.rows:
            r[ix] += 2.0 + 0.1 * r[ix] - 0.005 * r[ix] * r[ix]

    shift(ft2, "rt")
    shift(ft2, "rtmin")
    shift(ft2, "rtmax")

    pms = set(ft2.getValue(row, "peakmap") for row in ft2.rows)
    pmrtsbefore = []
    assert len(pms) == 1
    for pm in pms:
        for spec in pm.spectra:
            pmrtsbefore.append(spec.rt)
            spec.rt += 2.0 + 0.1 * spec.rt - 0.005 * spec.rt * spec.rt

    # delete one row, so ft should become reference map !
    del ft2.rows[-1]

    ftneu, ft2neu = ms.rtAlign([ft, ft2],
                               refTable=ft,
                               destination="temp_output",
                               nPeaks=9999,
                               numBreakpoints=5)

    check(ft, ft2, ftneu, ft2neu)

    ft2neu, ftneu = ms.rtAlign([ft2, ft],
                               refTable=ft,
                               destination="temp_output",
                               nPeaks=9999,
                               numBreakpoints=5)

    check(ft, ft2, ftneu, ft2neu)

    ftneu, ft2neu = ms.rtAlign([ft, ft2],
                               destination="temp_output",
                               nPeaks=9999,
                               numBreakpoints=5)

    check(ft, ft2, ftneu, ft2neu)
Exemplo n.º 5
0
def testRunnerTable():

    with ExceptionTester():
        Table(["a"], [np.float32], ["%f"], [[32.0]])

    #build table
    names = "int long float str object array".split()
    types = [
        int,
        long,
        float,
        str,
        object,
        np.ndarray,
    ]
    formats = ["%3d", "%d", "%.3f", "%s", "%r", "'array(%r)' % (o.shape,)"]

    row1 = [1, 12323L, 1.0, "hi", {1: 1}, np.array((1, 2, 3))]
    row2 = [2, 22323L, 2.0, "hi2", [
        2,
        3,
    ], np.array(((2, 3, 4), (1, 2, 3)))]
    row3 = [
        3, 32323L, 3.0, "hi3", (3, ),
        np.array(((3, 3, 4, 5), (1, 2, 3, 4)))
    ]

    rows = [row1, row2, row3]
    t = Table(names, types, formats, rows, "testtabelle", meta=dict(why=42))

    run(t, names, [row1, row2, row3])
    # test pickle
    dat = pickle.dumps(t)
    t = pickle.loads(dat)
    run(t, names, [row1, row2, row3])
    ms.storeTable(t, u"temp_output/test.table")
    try:
        ms.storeTable(t, "temp_output/test.table")
        assert False, "no exception thrown althoug file should exist!"
    except:
        pass
    ms.storeTable(t, "temp_output/test.table", True)
    t = ms.loadTable("temp_output/test.table")
    run(t, names, [row1, row2, row3])
Exemplo n.º 6
0
def testMzAlign():
    tab = ms.loadTable("data/ftab_for_mzalign.table")
    pm = tab.peakmap.values[0]
    s0 = pm.spectra[0].peaks[:,0]
    import os
    print os.getcwd()
    print os.listdir("temp_output")
    tab_aligned = ms.mzAlign(tab, interactive=False, minPoints=4, tol=14*MMU,
                      destination="temp_output")
    after = tab_aligned.mz.values
    pm = tab_aligned.peakmap.values[0]
    s0 = pm.spectra[0].peaks[:,0]
    assert abs(s0[0]-202.121231079) < 1e-5, float(s0[0])
    assert abs(after[0]-272.199238673) < 1e-5, float(after[0])

    assert len(glob.glob("temp_output/2011-10-06_054_PKTB*"))==4

    # former errror: transformation resulted in numpy.float64 values
    assert tab_aligned.get(tab_aligned.colTypes, "mz") == float
    assert tab_aligned.get(tab_aligned.colTypes, "mzmin") == float
    assert tab_aligned.get(tab_aligned.colTypes, "mzmax") == float
Exemplo n.º 7
0
def testPoseClustering():
    ft = ms.loadTable("data/features.table")
    irt = ft.getIndex("rt")

    # make copy and shift
    ft2=copy.deepcopy(ft)
    def shift(t, col):
        ix = t.getIndex(col)
        for r in t.rows:
            r[ix] += 2.0 + 0.1 * r[ix] - 0.005 * r[ix]*r[ix]

    shift(ft2, "rt")
    shift(ft2, "rtmin")
    shift(ft2, "rtmax")

    pms = set(ft2.getValue(row, "peakmap") for row in ft2.rows)
    pmrtsbefore = []
    assert len(pms) == 1
    for pm in pms:
        for spec in pm.spectra:
            pmrtsbefore.append(spec.rt)
            spec.rt += 2.0 + 0.1 * spec.rt - 0.005 * spec.rt * spec.rt

    # delete one row, so ft should become reference map !
    del ft2.rows[-1]

    ftneu, ft2neu = ms.rtAlign([ft,ft2], refTable=ft, destination="temp_output", nPeaks=9999,
                                          numBreakpoints=5)

    check(ft, ft2, ftneu, ft2neu)

    ft2neu, ftneu = ms.rtAlign([ft2,ft], refTable=ft, destination="temp_output", nPeaks=9999,
                                          numBreakpoints=5)

    check(ft, ft2, ftneu, ft2neu)

    ftneu, ft2neu = ms.rtAlign([ft,ft2], destination="temp_output", nPeaks=9999,
                                          numBreakpoints=5)

    check(ft, ft2, ftneu, ft2neu)
Exemplo n.º 8
0
def testMzAlign():
    tab = ms.loadTable("data/ftab_for_mzalign.table")
    pm = tab.peakmap.values[0]
    s0 = pm.spectra[0].peaks[:, 0]
    import os
    print os.getcwd()
    print os.listdir("temp_output")
    tab_aligned = ms.mzAlign(tab,
                             interactive=False,
                             minPoints=4,
                             tol=14 * MMU,
                             destination="temp_output")
    after = tab_aligned.mz.values
    pm = tab_aligned.peakmap.values[0]
    s0 = pm.spectra[0].peaks[:, 0]
    assert abs(s0[0] - 202.121231079) < 1e-5, float(s0[0])
    assert abs(after[0] - 272.199238673) < 1e-5, float(after[0])

    assert len(glob.glob("temp_output/2011-10-06_054_PKTB*")) == 4

    # former errror: transformation resulted in numpy.float64 values
    assert tab_aligned.get(tab_aligned.colTypes, "mz") == float
    assert tab_aligned.get(tab_aligned.colTypes, "mzmin") == float
    assert tab_aligned.get(tab_aligned.colTypes, "mzmax") == float
Exemplo n.º 9
0
def testIntegration():

    # test with and without unicode:
    ft = ms.loadTable(u"data/features.table")
    # an invalid row should not stop integration, but result
    # in None values for ms.integrate generated columns
    ftr = ms.integrate(ft, "trapez")
    assert len(ftr) == len(ft)
    assert "area" in ftr.getColNames()
    assert "rmse" in ftr.getColNames()
    assert ftr.area.values[0] > 0, ftr.area.values[0]
    assert ftr.rmse.values[0] >= 0, ftr.rmse.values[0]
    assert ftr.params.values[0] is not None
    assert ftr.method.values[0] is not None

    ft.setValue(ft.rows[0], "mzmin", None)

    ft._addColumnWithoutNameCheck("mzmin__0", ft.mzmin)
    ft._addColumnWithoutNameCheck("mzmax__0", ft.mzmax)
    ft._addColumnWithoutNameCheck("rtmin__0", ft.rtmin)
    ft._addColumnWithoutNameCheck("rtmax__0", ft.rtmax)
    ft._addColumnWithoutNameCheck("peakmap__0", ft.peakmap)

    ft.addColumn("mzminX", ft.mzmin)
    ft.addColumn("mzmaxX", ft.mzmax)
    ft.addColumn("rtminX", ft.rtmin)
    ft.addColumn("rtmaxX", ft.rtmax)
    ft.addColumn("peakmapX", ft.peakmap)

    ftr = ms.integrate(ft, "trapez")
    ftr.info()
    assert len(ftr) == len(ft)
    assert "area" in ftr.getColNames()
    assert "rmse" in ftr.getColNames()
    assert "area__0" in ftr.getColNames()
    assert "rmse__0" in ftr.getColNames()
    assert "areaX" in ftr.getColNames()
    assert "rmseX" in ftr.getColNames()

    assert ftr.area.values[0] is None
    assert ftr.rmse.values[0] is None
    assert ftr.params.values[0] is None
    assert ftr.method.values[0] is not None

    assert ftr.area.values[1] >= 0
    assert ftr.rmse.values[1] >= 0
    assert ftr.params.values[1] is not None
    assert ftr.method.values[1] is not  None

    assert ftr.area__0.values[0] is None
    assert ftr.rmse__0.values[0] is None
    assert ftr.params__0.values[0] is None
    assert ftr.method__0.values[0] is not None

    assert ftr.params__0.values[1] is not None
    assert ftr.method__0.values[1] is not None
    assert ftr.area__0.values[1] >= 0
    assert ftr.rmse__0.values[1] >= 0

    assert ftr.areaX.values[0] is None
    assert ftr.rmseX.values[0] is None
    assert ftr.paramsX.values[0] is None
    assert ftr.methodX.values[0] is not None

    assert ftr.paramsX.values[1] is not None
    assert ftr.methodX.values[1] is not None
    assert ftr.areaX.values[1] >= 0
    assert ftr.rmseX.values[1] >= 0
Exemplo n.º 10
0
def test_old():
    print >> sys.stderr, "TEST LOADING OF TABLE FROM EMZED BEFORE 1.3.2"
    t = ms.loadTable("feature_table_before_1.3.2.table")
    assert not hasattr(t, "version"),\
                                   "PLEASE READ cocepts/konzept_table_versions"
Exemplo n.º 11
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)
Exemplo n.º 12
0
def test_1_3_8():
    print >> sys.stderr, "TEST LOADING OF TABLE FROM EMZED 1.3.8"
    t = ms.loadTable("feature_table_1.3.8.table")
    assert t.version == "1.3.8", "PLEASE READ cocepts/konzept_table_versions"
Exemplo n.º 13
0
def test_old():
    print >> sys.stderr, "TEST LOADING OF TABLE FROM EMZED BEFORE 1.3.2"
    t = ms.loadTable("feature_table_before_1.3.2.table")
    assert not hasattr(t, "version"),\
                                   "PLEASE READ cocepts/konzept_table_versions"
Exemplo n.º 14
0
def test_1_3_8():
    print >> sys.stderr, "TEST LOADING OF TABLE FROM EMZED 1.3.8"
    t = ms.loadTable("feature_table_1.3.8.table")
    assert t.version == "1.3.8", "PLEASE READ cocepts/konzept_table_versions"
Exemplo n.º 15
0
#encoding: utf-8
import sys
sys.path.insert(0, "..")

import ms

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

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

Exemplo n.º 16
0
Arquivo: tab.py Projeto: burlab/emzed
        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:
            import traceback
            traceback.print_exc()
            print "PARSING",p,"FAILED"
            continue
        name, _ = os.path.splitext(os.path.basename(p))
        name = name.replace(" ","_")
        table.title = name
        table.meta["loaded_from"] = os.path.abspath(p)
        exec("%s=table" % name)
        print "LOADED", name, "FROM", p

elements = Elements()
# next line only valid after execution of 100loadpubchem.py during
# startup:
Exemplo n.º 17
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])
Exemplo n.º 18
0
        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:
            import traceback
            traceback.print_exc()
            print "PARSING", p, "FAILED"
            continue
        name, _ = os.path.splitext(os.path.basename(p))
        name = name.replace(" ", "_")
        table.title = name
        table.meta["loaded_from"] = os.path.abspath(p)
        exec("%s=table" % name)
        print "LOADED", name, "FROM", p

elements = Elements()
# next line only valid after execution of 100loadpubchem.py during
# startup:
Exemplo n.º 19
0
def testIntegration():

    # test with and without unicode:
    ft = ms.loadTable(u"data/features.table")
    # an invalid row should not stop integration, but result
    # in None values for ms.integrate generated columns
    ftr = ms.integrate(ft, "trapez")
    assert len(ftr) == len(ft)
    assert "area" in ftr.getColNames()
    assert "rmse" in ftr.getColNames()
    assert ftr.area.values[0] > 0, ftr.area.values[0]
    assert ftr.rmse.values[0] >= 0, ftr.rmse.values[0]
    assert ftr.params.values[0] is not None
    assert ftr.method.values[0] is not None

    ft.setValue(ft.rows[0], "mzmin", None)

    ft._addColumnWithoutNameCheck("mzmin__0", ft.mzmin)
    ft._addColumnWithoutNameCheck("mzmax__0", ft.mzmax)
    ft._addColumnWithoutNameCheck("rtmin__0", ft.rtmin)
    ft._addColumnWithoutNameCheck("rtmax__0", ft.rtmax)
    ft._addColumnWithoutNameCheck("peakmap__0", ft.peakmap)

    ft.addColumn("mzminX", ft.mzmin)
    ft.addColumn("mzmaxX", ft.mzmax)
    ft.addColumn("rtminX", ft.rtmin)
    ft.addColumn("rtmaxX", ft.rtmax)
    ft.addColumn("peakmapX", ft.peakmap)

    ftr = ms.integrate(ft, "trapez")
    ftr.info()
    assert len(ftr) == len(ft)
    assert "area" in ftr.getColNames()
    assert "rmse" in ftr.getColNames()
    assert "area__0" in ftr.getColNames()
    assert "rmse__0" in ftr.getColNames()
    assert "areaX" in ftr.getColNames()
    assert "rmseX" in ftr.getColNames()

    assert ftr.area.values[0] is None
    assert ftr.rmse.values[0] is None
    assert ftr.params.values[0] is None
    assert ftr.method.values[0] is not None

    assert ftr.area.values[1] >= 0
    assert ftr.rmse.values[1] >= 0
    assert ftr.params.values[1] is not None
    assert ftr.method.values[1] is not None

    assert ftr.area__0.values[0] is None
    assert ftr.rmse__0.values[0] is None
    assert ftr.params__0.values[0] is None
    assert ftr.method__0.values[0] is not None

    assert ftr.params__0.values[1] is not None
    assert ftr.method__0.values[1] is not None
    assert ftr.area__0.values[1] >= 0
    assert ftr.rmse__0.values[1] >= 0

    assert ftr.areaX.values[0] is None
    assert ftr.rmseX.values[0] is None
    assert ftr.paramsX.values[0] is None
    assert ftr.methodX.values[0] is not None

    assert ftr.paramsX.values[1] is not None
    assert ftr.methodX.values[1] is not None
    assert ftr.areaX.values[1] >= 0
    assert ftr.rmseX.values[1] >= 0