def test_dataframe(): "tests dataframe production" data = next( create(utfilepath('big_selected'), EventDetectionTask(), PeakSelectorTask(), DataFrameTask(merge=True, measures=dict(dfevents=True))).run()) assert isinstance(data, pd.DataFrame) assert 'track' in data.index.names assert 'bead' in data.index.names assert 'peakposition' in data assert 'events' in data assert isinstance(data.events[0], pd.DataFrame) data = next( create(utfilepath('big_selected'), EventDetectionTask(), PeakSelectorTask(), DataFrameTask(merge=True)).run()) assert isinstance(data, pd.DataFrame) assert 'track' in data.index.names assert 'bead' in data.index.names assert 'cycle' not in data.index.names assert 'peakposition' in data data = next( create(utfilepath('big_selected'), EventDetectionTask(), PeakSelectorTask(), DataFrameTask(merge=True, measures=dict(events=True))).run()) assert isinstance(data, pd.DataFrame) assert 'track' in data.index.names assert 'bead' in data.index.names assert 'cycle' in data.index.names assert 'peakposition' in data
def test_reporting(): "tests processor" for path in Path(gettempdir()).glob("*_peakfindingtest*.xlsx"): path.unlink() out = mktemp() + "_peakfindingtest3.xlsx" fname = Path(cast(str, utfilepath("big_legacy"))).parent / "*.trk" tasks = computereporters( dict(track=(fname, cast(str, utfilepath("CTGT_selection"))), reporting=out)) _ = next(tasks) assert Path(out).exists()
def test_reporting(): "tests processor" for path in Path(gettempdir()).glob("*_hybridstattest*.*"): path.unlink() out = mktemp() + "_hybridstattest5.xlsx" tasks = computereporters( dict(track=(Path(utfilepath("big_legacy")).parent / "*.trk", utfilepath("CTGT_selection")), reporting=out, sequence=utfilepath("hairpins.fasta"))) _ = next(tasks) assert Path(out).exists()
def test_processor(): "tests processor" for path in Path(gettempdir()).glob("*_hybridstattest*.xlsx"): path.unlink() out = mktemp() + "_hybridstattest3.xlsx" task = HybridstatBatchTask() task.addpaths(track=(Path(utfilepath("big_legacy")).parent / "*.trk", utfilepath("CTGT_selection")), reporting=out, sequence=utfilepath("hairpins.fasta")) pair = create((task, )) assert not Path(out).exists() pair.run() assert Path(out).exists()
def test_control(): "tests task controller" peaks = [1., 5., 10., 20.] pair = create((EventSimulatorTask(peaks=peaks, brownian=.01, stretch=None, bias=None, rates=None, baselineargs=None, nbeads=2, ncycles=20), PeakSelectorTask())) beads = tuple(tuple(i) for i in pair.run())[0] assert tuple(i[0] for i in beads) == (0, 1) vals = tuple(beads[0][1]) assert_allclose([i for i, _ in vals], [0.] + peaks, atol=.01, rtol=1e-2) for peak, evts in vals: assert evts.dtype == 'O' assert all(i.dtype == EVENTS_DTYPE for i in evts) tmp = [i[0]['data'].min() for i in evts] assert_allclose(tmp, (peak, ) * 20, atol=0.1) tmp = [i[0]['data'].max() for i in evts] assert_allclose(tmp, (peak, ) * 20, atol=0.1) # test that things don't crash pair = create(utfilepath('big_selected'), EventDetectionTask(), PeakSelectorTask()) beads = tuple(next(pair.run())[0])
def test_hybridstat_xlsxio(): "tests xlxs production" from tornado.ioloop import IOLoop # noqa: E402 from tornado.platform.asyncio import AsyncIOMainLoop # noqa: E402 from tests.testingcore import path as utfilepath # noqa: E402 from hybridstat.reporting.batch import createmodels as _hmodels # noqa: E402 from hybridstat.view._io import ConfigXlsxIO # noqa: E402 asyncio.set_event_loop(asyncio.new_event_loop()) AsyncIOMainLoop().make_current() path = cast(Path, utfilepath("big_legacy")) track = Path(path).parent/"*.trk", utfilepath("CTGT_selection") itr = _hmodels(dict(track = track, # type: ignore sequence = utfilepath("hairpins.fasta"))) mdl = next(itr) for path in Path(gettempdir()).glob("*_hybridstattest*.*"): path.unlink() out = mktemp()+"_hybridstattest4.xlsx" assert not Path(out).exists() # pylint: disable=protected-access ConfigXlsxIO._run(dict(path = out, oligos = 'CTGT', sequences = utfilepath('hairpins.fasta')), mdl) cnt = 0 async def _run(): nonlocal cnt for i in range(50): if ConfigXlsxIO.RUNNING is False: break cnt = i await asyncio.sleep(.5) try: IOLoop.current().run_sync(_run) assert Path(out).exists() assert cnt > 0 finally: ConfigXlsxIO.RUNNING = False
def test_dataframe(): "tests dataframe production" data = next( create(utfilepath('big_selected'), EventDetectionTask(), DataFrameTask(merge=True)).run()) assert isinstance(data, pd.DataFrame) assert 'track' in data.index.names assert 'bead' in data.index.names assert 'cycle' in data.index.names assert 'event' in data.index.names assert 'avg' in data assert 'modification' in data.columns assert hasattr(data, 'tasklist')
def test_population_merge(): "tests population merge" data = np.arange(100, dtype='f4') intervals = np.array([(0, 10), (5, 17), (8, 20), (30, 40), (37, 41)], dtype='i4') merged = PopulationMerger(percentile=75.)(data, intervals) assert tuple(tuple(i) for i in merged) == ((0, 10), (5, 20), (30, 41)) data = pickle.load(open(cast(str, utfilepath("eventsdata.pk")), 'rb')) intervals = np.array([[1, 11], [12, 15], [16, 25], [26, 52], [55, 121], [125, 136], [138, 453]], dtype='i4') merged = PopulationMerger()(data, intervals) assert tuple(tuple(i) for i in merged) == ((1, 52), (55, 121), (125, 136), (138, 453))
def test_ids(): "tests identifications" for path in Path(gettempdir()).glob("*_hybridstattest*.xlsx"): path.unlink() out = mktemp() + "_hybridstattest10.xlsx" assert not Path(out).exists() writeparams(out, [('hp1', (1, 3, 5)), ('hp2', (10, )), ('hp3', tuple())]) assert Path(out).exists() res = readparams(out) assert set(i[:2] for i in res) == {(1, 'hp1'), (3, 'hp1'), (5, 'hp1'), (10, 'hp2')} res = readparams(utfilepath('hybridstat_report.xlsx')) assert len(res) == 2 val = next(i for i in res if i[0] == 0) assert val[:2] == (0, 'GF4') assert_allclose(val[2:], [1173.87, 1.87], atol=2e-2)
def test_task(): "test task" data = next(create(utfilepath('big_selected'), PeakProjectorTask()).run()) bead = data[0] assert isinstance(bead, PeakListArray)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Tests for detection of peaks will be expanded to include different methods """ import pickle import numpy as np from numpy.testing import assert_allclose from peakfinding.groupby import MaxCov from tests.testingcore import path as utfilepath EMFITTER = MaxCov() DATA = pickle.load(open(utfilepath('smallemdata'), "rb")) def test_ztscore(): 'tests the score method' data = np.array([[0, 0], [10, 0], [0, 1]]) params = np.array([[0, 1, 0, 1], [10., 0.1**2, 0, 2], [5, 100, 0, 1], [0, 100, 0.5, 1]]) score = EMFITTER.score(data, params) assert_allclose(score, np.array([[0.3989, 0, 0.1468], [0, 1.995, 0], [0.0352, 0.0352, 0.0129], [0, 0, 0.0242]]), rtol=1e-2, atol=1e-2)