def testSplitBy(): t = ms.toTable("a", [1, 1, 3, 4]) t.addColumn("b", [1, 1, 3, 3]) t.addColumn("c", [1, 2, 1, 4]) t._print() subts = t.splitBy("a") assert len(subts) == 3 res = ms.mergeTables(subts) assert len(res) == len(t) subts[0]._print() assert res.a.values == t.a.values assert res.b.values == t.b.values assert res.c.values == t.c.values # check if input tables are not altered for subt in subts: assert subt.getColNames() == ["a", "b", "c"] subts = t.splitBy("a", "c") assert len(subts) == 4 res = ms.mergeTables(subts) assert res.a.values == t.a.values assert res.b.values == t.b.values assert res.c.values == t.c.values # check if input tables are not altered for subt in subts: assert subt.getColNames() == ["a", "b", "c"]
def testSplitBy(): t = ms.toTable("a", [1,1,3,4]) t.addColumn("b", [1,1,3,3]) t.addColumn("c", [1,2,1,4]) t._print() subts = t.splitBy("a") assert len(subts) == 3 res = ms.mergeTables(subts) assert len(res) == len(t) subts[0]._print() assert res.a.values == t.a.values assert res.b.values == t.b.values assert res.c.values == t.c.values # check if input tables are not altered for subt in subts: assert subt.getColNames() == [ "a", "b", "c"] subts = t.splitBy("a", "c") assert len(subts) == 4 res = ms.mergeTables(subts) assert res.a.values == t.a.values assert res.b.values == t.b.values assert res.c.values == t.c.values # check if input tables are not altered for subt in subts: assert subt.getColNames() == [ "a", "b", "c"]
def integrate_matching_fragments(tables, transitions, delta_mz): """extracts mass transitions defined in transition table 'transitions' with column names 'name', 'precursor', 'fragment', 'rtmin', 'rtmax'. Detecting the peaks does not use a peak detector as centWave, but uses mz and rt ranges to fit a EMG model to the underlying raw peaks m/z traces. This avoids cumbersome parameter optimization of a peak detector and returns all peaks irrespective of filtering according to some heuristic criterion for peak quality. """ table = ms.mergeTables(tables) # To shorten the name in commands we introduce abbreviations trans = transitions t = table # table has columns # # precursor fragment peakmap mzmin mzmax # # and transitions: # # name precursor fragment rtmin rtmax # find candidates defined in parameter table transitions identified = t.join(trans, trans.precursor.approxEqual(t.precursor, delta_mz)\ & trans.fragment.approxEqual(t.fragment, delta_mz)) # identified has columns: # precursor fragment peakman mzmin mzmax name__0 precursor__0 # ... fragment__0 rtmin__0 rtmax__0 identified.renameColumns(name__0="name", rtmin__0="rtmin", rtmax__0="rtmax") identified = identified.extractColumns("name", "precursor", "fragment", "mzmin", "mzmax", "rtmin", "rtmax", "peakmap") # now we have columns mzmin, mzmax, rtmin, rtmax and peakmap which we # need for fitting EMG model with ms.integrate: identified = ms.integrate(identified, "emg_exact", msLevel=2) return identified.splitBy("name")
def process_srm_data(peakmap, n_digits): tables = split_srm_peakmap_to_tables(peakmap, n_digits) # Each table in tables now contains chromatograms for each precursor # We flatten each of these tables to one row tables, so that # the table explorer overlays these chromatograms if you select # a specific row. flattened_tables = [flatten(t) for t in tables] # Concatenate all these one row table to one big result table: merged = ms.mergeTables(flattened_tables) # For later visual inspection with the table explorer a title is helpful. # Here we use the name of the peakmap file: merged.title = "SRM/MRM analysis of %s" % peakmap.meta["source"] return merged
def testMerge(): t1 = ms.toTable("a", [1]) t1.addColumn("b", [2]) t1.addColumn("c", [3]) t2 = ms.toTable("a", [1,2]) t2.addColumn("c", [1,3]) t2.addColumn("d", [1,4]) tn = ms.mergeTables([t1, t2]) assert tn.a.values == [1, 1, 2] assert tn.b.values == [2, None, None] assert tn.c.values == [3, 1, 3] assert tn.d.values == [None, 1, 4] # check if input tables are not altered assert t1.getColNames() == [ "a", "b", "c"] assert t2.getColNames() == [ "a", "c", "d"]
def testMerge(): t1 = ms.toTable("a", [1]) t1.addColumn("b", [2]) t1.addColumn("c", [3]) t2 = ms.toTable("a", [1, 2]) t2.addColumn("c", [1, 3]) t2.addColumn("d", [1, 4]) tn = ms.mergeTables([t1, t2]) assert tn.a.values == [1, 1, 2] assert tn.b.values == [2, None, None] assert tn.c.values == [3, 1, 3] assert tn.d.values == [None, 1, 4] # check if input tables are not altered assert t1.getColNames() == ["a", "b", "c"] assert t2.getColNames() == ["a", "c", "d"]
def process_srm_data(peakmap, transitions, delta_mz): tables = split_srm_peakmap_by_precursors_to_tables(peakmap, delta_mz) # Each table in tables now contains chromatograms for each precursor # We flatten each of these tables to one row tables, so that # the table explorer overlays these chromatograms if you select # a specific row. if transitions is not None: tables = integrate_matching_fragments(tables, transitions, delta_mz) else: tables = integrate_fragments(tables) flattened_tables = [flatten(t) for t in tables] # Concatenate all these one row table to one big result table: merged = ms.mergeTables(flattened_tables) # For later visual inspection with the table explorer a title is helpful. # Here we use the name of the peakmap file: merged.title = "SRM peaks of %s" % peakmap.meta["source"] return merged