def testCompress(): t = ms.toTable("a", []) from libms.DataStructures.Table import compressPeakMaps from libms.DataStructures.MSTypes import PeakMap, Spectrum import numpy compressPeakMaps(t) s = Spectrum(numpy.arange(12).reshape(-1,2), 1.0, 1, "+") pm = PeakMap([s]) s = Spectrum(numpy.arange(12).reshape(-1,2), 1.0, 1, "+") pm2 = PeakMap([s]) t = ms.toTable("pm", [pm, pm2]) assert len(set(map(id, t.pm.values))) == 2 compressPeakMaps(t) assert len(set(map(id, t.pm.values))) == 1
def testCompress(): t = ms.toTable("a", []) from libms.DataStructures.Table import compressPeakMaps from libms.DataStructures.MSTypes import PeakMap, Spectrum import numpy compressPeakMaps(t) s = Spectrum(numpy.arange(12).reshape(-1, 2), 1.0, 1, "+") pm = PeakMap([s]) s = Spectrum(numpy.arange(12).reshape(-1, 2), 1.0, 1, "+") pm2 = PeakMap([s]) t = ms.toTable("pm", [pm, pm2]) assert len(set(map(id, t.pm.values))) == 2 compressPeakMaps(t) assert len(set(map(id, t.pm.values))) == 1
def loadTable(path=None): """ load pickled table If *path* is missing, a dialog for file selection is opened instead. """ # local import in order to keep namespaces clean import ms import sys from libms.DataStructures.Table import Table, compressPeakMaps if isinstance(path, unicode): path = path.encode(sys.getfilesystemencoding()) elif path is None: path = ms.askForSingleFile(extensions=["table"]) if path is None: return None result = Table.load(path) compressPeakMaps(result) return result
def storeTable(tab, path=None, forceOverwrite=False): """ Saves *tab* in a binary ``.table`` file. If *path* is not provided, a file dialog opens for choosing the files name and location. *path* must have file extension ``.table``. """ # local import in order to keep namespaces clean import ms import sys from libms.DataStructures.Table import compressPeakMaps compressPeakMaps(tab) if isinstance(path, unicode): path = path.encode(sys.getfilesystemencoding()) elif path is None: startAt = tab.meta.get("loaded_from", "") path = ms.askForSave(extensions=["table"], startAt=startAt) if path is None: return None tab.store(path, forceOverwrite)