Exemplo n.º 1
0
def test_1_3_8(path):
    """
    the internal version of emzed 1.3.8 did not change since 1.3.2 so the "table version"
    is 1.3.2, although the file was created using emzed 1.3.8
    """
    t = loadTable(path("data/table_version_1_3_8.table"))
    assert t.version == "1.3.2"
Exemplo n.º 2
0
    def setUp(self):

        def path():
            import os.path
            here = os.path.dirname(os.path.abspath(__file__))
            def j(*a):
                return os.path.join(here, *a)
            return j
        ft = loadTable(path()("data", "features.table"))

        # make copy and shift
        ft2 = ft.copy()
        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]
        self.ft = ft
        self.ft2 = ft2
Exemplo n.º 3
0
def test_1_3_8(path):
    """
    the internal version of emzed 1.3.8 did not change since 1.3.2 so the "table version"
    is 1.3.2, although the file was created using emzed 1.3.8
    """
    t = loadTable(path("data/table_version_1_3_8.table"))
    assert t.version == "1.3.2"
def test_integrate_empty_table(path, regtest):

    # test with and without unicode:
    ft = io.loadTable(path("data/features.table"))
    ft = ft[:0]
    # an invalid row should not stop integration, but result
    # in None values for emzed.utils.integrate generated columns
    print(ft, file=regtest)
    ftr = utils.integrate(ft, "trapez",  n_cpus=1)
    print(ftr, file=regtest)
    assert len(ftr) == len(ft)
    print(file=regtest)

    ftr = utils.integrate(ft, "trapez",  n_cpus=2)
    print(ftr, file=regtest)
    assert len(ftr) == len(ft)
Exemplo n.º 5
0
def test_2_7_5_table_with_peakmap(path):
    """the table under test had originally attributes rt, polarity, msLevel and peaks
    which are now "proxied" (see impl. Spectrum class).
    We check if this conversion worked.
    """

    from emzed.core.data_types.ms_types import NDArrayProxy

    t = loadTable(path("data/features.table"))
    assert t.version == (2, 7, 5)

    pm = t.peakmap.uniqueValue()
    spec = pm.spectra[0]

    for att in ("rt", "polarity", "msLevel", "precursors"):
        assert hasattr(spec, "_" + att)

    assert isinstance(spec.peaks, NDArrayProxy)
Exemplo n.º 6
0
def test_2_7_5_table_with_peakmap(path):
    """the table under test had originally attributes rt, polarity, msLevel and peaks
    which are now "proxied" (see impl. Spectrum class).
    We check if this conversion worked.
    """

    from emzed.core.data_types.ms_types import NDArrayProxy

    t = loadTable(path("data/features.table"))
    assert t.version == (2, 7, 5)

    pm = t.peakmap.uniqueValue()
    spec = pm.spectra[0]

    for att in ("rt", "polarity", "msLevel", "precursors"):
        assert hasattr(spec, "_" + att)

    assert isinstance(spec.peaks, NDArrayProxy)
def _testIntegration(path, n_cpus, integrator_id, check_values=True):

    # test with and without unicode:
    ft = io.loadTable(path("data/features.table"))
    # an invalid row should not stop integration, but result
    # in None values for emzed.utils.integrate generated columns
    ftr = utils.integrate(ft, integrator_id,  n_cpus=n_cpus, min_size_for_parallel_execution=1)
    assert len(ftr) == len(ft)
    assert "area" in ftr.getColNames()
    assert "rmse" in ftr.getColNames()

    if check_values:
        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 = utils.integrate(ft, integrator_id,  n_cpus=n_cpus, min_size_for_parallel_execution=1)
    assert len(ftr) == len(ft)
    assert "area" in ftr.getColNames()
    assert "rmse" in ftr.getColNames()
    # assert "eic" in ftr.getColNames()
    assert "area__0" in ftr.getColNames()
    assert "rmse__0" in ftr.getColNames()
    # assert "eic__0" in ftr.getColNames()
    assert "areaX" in ftr.getColNames()
    assert "rmseX" in ftr.getColNames()
    assert "rmseX" in ftr.getColNames()
    # assert "eicX" in ftr.getColNames()

    if check_values:
        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.eic.values[0] is None

        assert ftr.area.values[1] is not None
        assert ftr.rmse.values[1] is not None
        assert ftr.params.values[1] is not None
        assert ftr.method.values[1] is not None
        # assert len(ftr.eic.values[1]) == 2

        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.eic__0.values[0] is None

        assert ftr.area__0.values[1] is not None
        assert ftr.rmse__0.values[1] is not None
        assert ftr.params__0.values[1] is not None
        assert ftr.method__0.values[1] is not None
        # assert len(ftr.eic__0.values[1]) == 2

        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.eicX.values[0] is None

        assert ftr.areaX.values[1] is not None
        assert ftr.rmseX.values[1] is not None
        assert ftr.paramsX.values[1] is not None
        assert ftr.methodX.values[1] is not None
        # assert len(ftr.eicX.values[1]) == 2

    # test with empty chromatograms
    s0 = ft.peakmap.values[0].spectra[0]
    rt0 = s0.rt
    pm = PeakMap([s0])
    rts, iis = pm.chromatogram(0, 10000, rt0 + 20, rt0 + 30)
    assert len(rts) == 0
    assert len(iis) == 0
    ft.replaceColumn("peakmap", pm)
    ft.replaceColumn("rtmin", rt0 + 10)
    ft.replaceColumn("rtmax", rt0 + 20)
    ftr2 = utils.integrate(ft, integrator_id,  n_cpus=n_cpus, min_size_for_parallel_execution=1)

    # assert  set(ftr2.eic.values) == {None}

    return ftr
Exemplo n.º 8
0
def test_1_3_8(path):
    print >> sys.stderr, "TEST LOADING OF TABLE FROM EMZED 1.3.8"
    t = loadTable(path("data/feature_table_1.3.8.table"))
    assert t.version == "1.3.8", "PLEASE READ cocepts/konzept_table_versions"
Exemplo n.º 9
0
def test_2_7_5(path):
    """
    in 2.7.5 we switched from cPickle to dill for serialization
    """
    t = loadTable(path("data/table_version_2_7_5.table"))
    assert t.version == (2, 7, 5)
Exemplo n.º 10
0
def test_2_0_2(path):
    t = loadTable(path("data/table_version_2_0_2.table"))
    assert t.version == (2, 0, 2)
Exemplo n.º 11
0
def test_2_7_5(path):
    """
    in 2.7.5 we switched from cPickle to dill for serialization
    """
    t = loadTable(path("data/table_version_2_7_5.table"))
    assert t.version == (2, 7, 5)
Exemplo n.º 12
0
def test_2_0_2(path):
    t = loadTable(path("data/table_version_2_0_2.table"))
    assert t.version == (2, 0, 2)