コード例 #1
0
def test_rampdatacleaning():
    "test RampDataCleaningTask in scripting context"
    filepath = "Ramp-fov5-PBS_AfterDNApol1.pk"
    beadid = 0  # the only bead in the pk-file

    proc_pass = create(
        TrackReaderTask(path=utpath(filepath)),
        RampDataCleaningTask(minpopulation=20,
                             extentoutlierspercentile=90,
                             minextentoutliers=90))
    proc_fail = create(
        TrackReaderTask(path=utpath(filepath)),
        RampDataCleaningTask(minpopulation=100,
                             extentoutlierspercentile=95,
                             minextentoutliers=90,
                             maxhfsigma=.0002))

    data_pass = next(iter(proc_pass.run()))

    num_datapoints = data_pass[beadid].shape[0]
    num_valid_point = np.sum(np.isfinite(data_pass[beadid]))

    assert num_valid_point / data_pass.nframes == pytest.approx(
        10 / 22, rel=1e-4)  # 10/22 cyc pass

    data_fail = next(iter(proc_fail.run()))
    with pytest.raises(
            DataCleaningException,
            match=re.escape('22 cycles: σ[HF] > 0.0002\n' +
                            '12 cycles: Δz-outlier < 90% of Δz-consensus')):
        data_fail[beadid]
コード例 #2
0
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
コード例 #3
0
def test_subtraction_dataframe():
    "test cleanin creation"
    proc = create(TrackReaderTask(path=utpath("fixedbeads.pk")),
                  DataFrameTask(merge=True, measures={'status': True}))
    data = next(iter(proc.run()))
    assert list(data[data.fixed].reset_index().bead) == [4]
    assert 'status' in data.columns
    assert isinstance(data.status.values[0], pd.DataFrame)
    assert data[data.fixed].reset_index().status[0].shape[0] == 0
    assert 'modification' in data.columns
    assert hasattr(data, 'tasklist')

    proc = create(TrackReaderTask(path=utpath("fixedbeads.pk")),
                  DataCleaningTask(),
                  DataFrameTask(merge=True, measures={'status': True}))
    data = next(iter(proc.run()))
    assert list(data[data.fixed].reset_index().bead) == [4]
    assert 'status' in data.columns
    assert isinstance(data.status.values[0], pd.DataFrame)
    assert data[data.fixed].reset_index().status[0].shape[0] != 0

    proc = create(TrackReaderTask(path=utpath("fixedbeads.pk")),
                  DataFrameTask(merge=True, measures={'fixed': True}))
    data = next(iter(proc.run()))
    assert list(data[data.fixed].reset_index().bead) == [4]
    assert 'status' not in data.columns

    proc = create(TrackReaderTask(path=utpath("fixedbeads.pk")),
                  DataCleaningTask(),
                  DataFrameTask(merge=True, measures={'fixed': True}))
    data = next(iter(proc.run()))
    assert list(data[data.fixed].reset_index().bead) == [4]
    assert 'status' not in data.columns
コード例 #4
0
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])
コード例 #5
0
def test_baselinepeak():
    "test single strand peak"
    data = Experiment(baseline=None, thermaldrift=None).track(seed=1)
    track = Track(**data)
    lst = (InMemoryTrackTask(track), EventDetectionTask(), PeakSelectorTask(),
           BaselinePeakTask())
    out1 = [i for i, _ in next(create(*lst).run())[0]]
    out2 = [i for i, _ in next(create(*lst[:-1]).run())[0]]
    assert out1 == out2[1:]
コード例 #6
0
def test_beadprocess():
    "tests that tracks are well simulated"
    pair = create((TrackSimulatorTask(brownian  = 0., events = None),
                   DriftTask(precision = 0.01)))
    cycs = next(i[...,...] for i in pair.run()).withphases(5)
    for _, val in cycs:
        assert_allclose(val[1:-1], val[1:-1].mean(), rtol = 1e-5, atol = 1e-8)

    pair = create((TrackSimulatorTask(brownian  = 0.), DriftTask(precision = 0.01)))
    cycs = next(i[...,...] for i in pair.run()).withphases(5)
    for _, val in cycs:
        val = (val-np.round(val, 1))[1:-1]
        assert_allclose(val-val[0], 0., atol = 1e-2)
コード例 #7
0
def test_rawprecisiontask():
    "test raw precision task"
    for i in ('range', 'normalized'):
        # test that track is opened with the correct raw precision computer
        tsk = RawPrecisionTask(computer=i)
        trk = next(iter(create(utpath("big_all"), tsk).run())).track
        assert trk.rawprecision().keyword() == i

        # test that track is copied whenever the requested raw precision
        # computer is different from the original one
        tsk.computer = 'range' if i == 'normalized' else 'normalized'
        trk2 = next(iter(create(utpath("big_all"), tsk).run())).track
        assert trk.rawprecision().keyword() == i
        assert trk2.rawprecision().keyword() == tsk.computer
コード例 #8
0
def test_gels():
    "test min bias alignment of peaks"
    data = Experiment(baseline=None, thermaldrift=None).track(seed=1)
    track = Track(**data)
    lst = (InMemoryTrackTask(track), EventDetectionTask(),
           PeakSelectorTask(peakalign=None), GELSPeakAlignmentTask())
    peaks = next(create(*lst).run())
    _ = peaks[0]  # test everything runs

    cycles = np.array([(1. if i > 5 else 0., 0.) for i in range(10)],
                      dtype=GELSPeakAlignmentTask.DTYPE)
    stats = np.array([np.roll(cycles, i) for i in range(4)],
                     dtype=GELSPeakAlignmentTask.DTYPE)
    for i in range(4):
        stats[i, :]['mean'][:] += i * 10

    truth = np.arange(10, dtype='f4') * .1
    truth -= np.median(truth)
    for i in range(10):
        stats[:, i]['mean'][:] -= truth[i]
    found = lst[-1](stats)

    truth = np.array([
        -0.47142908, -0.37142903, -0.27142864, 0., 0., 0., 0.12857169,
        0.22857153, 0.32857174, 0.4285718
    ],
                     dtype='f4')
    assert_allclose(found, truth)
コード例 #9
0
def test_minbiasalignment():
    "test min bias alignment of peaks"
    data = Experiment(baseline=None, thermaldrift=None).track(seed=1)
    track = Track(**data)
    lst = (InMemoryTrackTask(track), EventDetectionTask(),
           PeakSelectorTask(peakalign=None), MinBiasPeakAlignmentTask())
    peaks = next(create(*lst).run())
    _ = peaks[0]  # test everything runs

    cycles = np.array([(1. if i > 5 else 0., 0.) for i in range(10)],
                      dtype=MinBiasPeakAlignmentTask.DTYPE)
    stats = np.array([np.roll(cycles, i) for i in range(4)],
                     dtype=MinBiasPeakAlignmentTask.DTYPE)
    for i in range(4):
        stats[i, :]['mean'][:] += i * 10

    truth = np.arange(10, dtype='f4') * .1
    truth -= np.median(truth)
    for i in range(10):
        stats[:, i]['mean'][:] -= truth[i]
    found = lst[-1](stats)
    truth = np.array([
        -0.44999883, -0.34998798, -0.24997711, 0., 0., 0., 0., 0.24997902,
        0.34999132, 0.45000142
    ],
                     dtype='f4')
    assert_allclose(found, truth)
コード例 #10
0
def test_singlestrandpeak():
    "test single strand peak"
    data = Experiment(baseline=None, thermaldrift=None).track(seed=1)
    track = Track(**data)
    lst = (InMemoryTrackTask(track), EventDetectionTask(), PeakSelectorTask(),
           SingleStrandTask())
    peaks = next(create(*lst[:-1]).run())
    proc = SingleStrandProcessor()
    ncl = proc.nonclosingramps(peaks, 0)
    truth = np.where(data['truth'][0].strandclosing.duration >=
                     track.phase.duration(..., range(5)))[0]
    assert set(ncl) == set(truth)

    out1 = [i for i, _ in next(create(*lst).run())[0]]
    out2 = [i for i, _ in next(create(*lst[:-1]).run())[0]]
    assert out1 == out2[:-1]
コード例 #11
0
def test_cycleprocess_emptycycles():
    "tests drift removal on cycles"
    tasks = (utpath("big_all"),
             ExtremumAlignmentTask(phase = 'pull', minpopulation = 0.),
             DriftTask(onbeads = False))
    ret = dict(next(i for i in create(tasks).run()))
    assert ret is not None # check that computations don't crash
コード例 #12
0
def test_message_creation():
    "test message creation"
    proc = create(TrackReaderTask(path=utpath("big_legacy")),
                  DataCleaningTask())
    data = next(iter(proc.run()))
    with pytest.raises(DataCleaningException):
        data[5]
コード例 #13
0
def test_precision():
    "tests that peaks can be found with a given precision"
    sim = dict(durations=[15, 30, 15, 60, 60, 200, 15, 100],
               drift=None,
               baseline=None,
               framerate=1.,
               poisson=dict(rates=[.05, .05, .1, .1, .2, .2],
                            sizes=[20, 10, 20, 10, 20, 10],
                            peaks=[0.1, 0.2, 0.3, 0.4, 0.5, 0.6],
                            store=['sizes']),
               seed=0,
               nbeads=2,
               ncycles=100)

    pair = create(TrackSimulatorTask(**sim),
                  EventDetectionTask(filter=NonLinearFilter()),
                  PeakSelectorTask(), PeakProbabilityTask())
    tmp = next(pair.run())
    sim = tmp.track.simulator[0]['sizes']
    vals = tuple(tmp[0])

    peaks = np.array([i for i, _ in vals])
    assert_allclose(peaks, [0., .1, .2, .3, .4, .5, .6], rtol=1e-3, atol=1e-3)

    truth = np.sum(sim >= 5, 0) / 100.  # type: ignore
    exp = np.array([i.hybridisationrate for _, i in vals[1:]])
    assert_allclose(exp, truth, rtol=1e-3, atol=1e-3)

    truth = [np.mean(i[i >= 5]) for i in cast(np.ndarray, sim).T]
    exp = np.array([i.averageduration for _, i in vals[1:]])
    assert np.all(np.abs(exp - truth) < 2)
コード例 #14
0
def test_toref_frompeaks():
    "tests reference comparison"
    pair = create(utpath("big_selected"), EventDetectionTask(), PeakSelectorTask())
    pks  = {i: tuple(j) for i, j in next(iter(pair.run()))}
    res  = HistogramFit().frompeaks(next(iter(pks.values())))
    ret  = HistogramFit().optimize(res, HistogramData(res.histogram,
                                                      res.minvalue+.01,
                                                      res.binwidth/1.01))

    assert_allclose(ret[1:], [1.01, .01], rtol = 5e-4, atol = 5e-4)

    pair = create(utpath("big_selected"), EventDetectionTask(), PeakSelectorTask())
    pks  = {i: tuple(j) for i, j in next(iter(pair.run()))}
    res  = ReferencePeaksFit().frompeaks(next(iter(pks.values())))
    ret  = ReferencePeaksFit().optimize(res, res/1.01+0.1)
    assert_allclose(ret[1:], [1.01, .1], rtol = 5e-4, atol = 1e-2)
コード例 #15
0
def test_control():
    u"tests BeadsByHairpinTask using the controller"
    peaks = np.array([0.,  .1, .5, .6, 1.], dtype = 'f4')
    truth = [np.array([0., .1, .5, 1.,       1.5], dtype = 'f4')/8.8e-4,
             np.array([0.,     .5,      1.2, 1.5], dtype = 'f4')/8.8e-4]
    hpins = {'hp100': GaussianProductFit(peaks = truth[0]),
             'hp101': GaussianProductFit(peaks = truth[1])}
    pair  = create((ByPeaksEventSimulatorTask(bindings       = peaks[::-1],
                                              brownianmotion = .01,
                                              baseline       = None,
                                              onrates        = 1.,
                                              nbeads         = 1,
                                              ncycles        = 5),
                    BeadsByHairpinTask(fit = hpins)))

    beads = tuple(i for i in pair.run())[0]
    assert tuple(beads.keys()) == ('hp100',)

    pair.clear()
    beads = tuple(i for i in pair.run(pool = DummyPool()))[0]
    assert tuple(beads.keys()) == ('hp100',)

    pair.clear()
    with ProcessPoolExecutor(2) as pool:
        beads = tuple(i for i in pair.run(pool = pool))[0]
        assert tuple(beads.keys()) == ('hp100',)
コード例 #16
0
def test_cleaning_dataframe():
    "test cleanin creation"
    proc = create(TrackReaderTask(path=utpath("big_legacy")),
                  DataCleaningTask(), DataFrameTask(merge=True))
    data = next(iter(proc.run()))
    assert list(data.reset_index(0).loc[5].bad.unique()) == [True]
    assert list(data.reset_index(0).loc[0].bad.unique()) == [False]
    assert 'modification' in data.columns
    assert hasattr(data, 'tasklist')
コード例 #17
0
def test_hp_dataframe(record):
    "test fit to hp dataframe"
    pair = next(iter(create(
        TrackReaderTask(path = utpath("big_legacy")),
        EventDetectionTask(),
        PeakSelectorTask(),
        FitToHairpinTask(
            sequence = utpath("hairpins.fasta"),
            oligos   = "4mer",
            fit      = ChiSquareFit()
        ),
        DataFrameTask(merge = True, measures = dict(
            peaks = dict(missing = True, peakhfsigma = True)
        )),
    ).run()))
    assert pair.shape == (102, 29)
    assert 'falseneg' in pair.peaks[1].status.unique()
    assert pair.index.names == ['hpin', 'track', 'bead']
    assert isinstance(pair.peaks.values[0], pd.DataFrame)
    assert 'modification' in pair.columns
    assert hasattr(pair, 'tasklist')
    assert record["withmissing"].approx(
        pair.drop(columns = ['peaks', 'cost', 'modification']).iloc[:5],
        atol = 5e-4
    )
    assert record["peakswithmissing"].approx(
        pair.peaks[1].iloc[:5], atol = 5e-4
    )

    pair = next(iter(create(
        TrackReaderTask(path = utpath("big_legacy")),
        EventDetectionTask(),
        PeakSelectorTask(),
        FitToHairpinTask(
            sequence = utpath("hairpins.fasta"),
            oligos   = "4mer",
            fit      = ChiSquareFit()
        ),
        DataFrameTask(merge = True),
    ).run()))
    assert pair.shape == (102, 26)
    assert pair.index.names == ['hpin', 'track', 'bead']
    assert 'modification' in pair.columns
    assert hasattr(pair, 'tasklist')
コード例 #18
0
def test_fixedbeadsorting():
    "test fixed bead detection"
    import cleaning.beadsubtraction as B
    B.BeadSubtractionTask = BeadSubtractionTask
    beads = next(
        iter(create(TrackReaderTask(path=utpath("fixedbeads.pk"))).run()))
    lst = FixedBeadDetection()(beads)
    assert len(lst) == 1
    assert lst[0][-1] == 4
    frames = FixedBeadDetection().dataframe(beads)
    assert frames.shape == (4, 16)
    assert set(frames[frames.good].bead.values) == {4}
コード例 #19
0
def test_cycleprocess():
    "tests drift removal on cycles"
    pair = create((TrackSimulatorTask(brownian  = 0.,
                                      events    = None,
                                      nbeads    = 30,
                                      ncycles   = 1),
                   DriftTask(onbeads = False, precision = 0.01)))
    cycs = next(i for i in pair.run())
    for _, val in cycs:
        val  = val[34:132]
        assert_allclose(val, val.mean(), atol = 1e-5)

    pair = create((TrackSimulatorTask(brownian  = 0.,
                                      nbeads    = 30,
                                      ncycles   = 1),
                   DriftTask(onbeads = False, precision = 0.01)))
    cycs = next(i for i in pair.run())
    for _, val in cycs:
        val  = val[34:132]
        val -= np.round(val, 1)
        assert_allclose(val-val[0], 0., atol = 1e-2)
コード例 #20
0
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')
コード例 #21
0
def test_dataframe():
    "test ramp dataframe"
    add = {'fixed', 'status', 'good', 'track', 'modification'}
    out = next(
        create(TrackReaderTask(path=path("ramp_legacy")),
               RampStatsTask()).run())
    assert set(out.columns) == set(RampCycleTuple.fields()) | add

    out = next(
        create(TrackReaderTask(path=path("ramp_legacy")),
               RampStatsTask(events=True)).run())
    assert set(out.columns) == set(RampEventTuple.fields()) | add

    out = next(
        create(TrackReaderTask(path=path("ramp_Hela_mRNA_CIP_4ul_F9.trk")),
               RampStatsTask()).run())
    assert set(out.columns) == set(RampCycleTuple.fields()) | add

    status = out.reset_index().groupby("status").bead.unique()
    assert sorted(status.loc['ok']) == [1, 2, 3, 4, 7, 8, 9, 11, 12]
    assert sorted(status.loc['fixed']) == [0, 5, 10, 13]
    assert sorted(status.loc['bad']) == [6]
コード例 #22
0
def test_cycletable(bead: int, taskcount: int):
    "test rescaling"
    from eventdetection.processor import ExtremumAlignmentTask
    from cleaning.view._plot import GuiDataCleaningProcessor
    tasks: Tuple[Task, ...] = (
        TrackReaderTask(path=utpath("big_legacy")),
        DataCleaningTask(),
    )
    if taskcount in (1, 2):
        tasks += (ExtremumAlignmentTask(), )
    if taskcount in (-2, 2):
        tasks += (ClippingTask(), )

    find = lambda tpe: next(
        (i for i in tasks if isinstance(i, tpe)), None)  # noqa

    ctrl = create(tasks)
    _ = next(iter(ctrl.run()))[0]  # get the track
    track = ctrl.data.getcache(tasks[0])()

    GuiDataCleaningProcessor.computeall(bead,
                                        ctrl,
                                        cleaning=find(DataCleaningTask),
                                        alignment=find(ExtremumAlignmentTask),
                                        clipping=find(ClippingTask))

    info = {
        i.name: i.values
        for i in ctrl.data.getcache(DataCleaningTask)()[bead][0]
    }
    applied_rules = set(info.keys())
    assert applied_rules == {
        'population', 'hfsigma', 'extent', 'pingpong', 'saturation',
        'discarded', 'alignment', 'clipping'
    }
    assert 'phasejump' not in applied_rules  # 'phasejump'-rule must *only* act on SDI-experiments

    assert all(len(i) == track.ncycles for i in info.values())

    if find(ExtremumAlignmentTask):
        nans = np.isnan(info['alignment'])
        assert nans.sum() == {0: 0, 11: 0, 15: 23}[bead]
        assert_equal(info['discarded'][nans], np.ones(nans.sum(), dtype='f4'))
    else:
        assert_equal(info['alignment'], np.zeros(track.ncycles, dtype='f4'))

    if find(ClippingTask):
        assert ((info['discarded'][np.isfinite(info['clipping'])] + 1e-5) <
                info['clipping'][np.isfinite(info['clipping'])]).sum() == 0
    else:
        assert_equal(info['clipping'], np.zeros(track.ncycles, dtype='f4'))
コード例 #23
0
def test_toref_dataframe():
    "tests reference comparison"
    peaks = np.array([.1, .5, .6, 1.], dtype = 'f4')
    root  = ByPeaksEventSimulatorTask(bindings       = peaks[::-1],
                                      brownianmotion = .01,
                                      onrates        = 1.,
                                      baseline       = None,
                                      nbeads         = 1,
                                      ncycles        = 5)
    ref   = tuple(create(root).run())[0]
    tsk   = FitToReferenceTask(fitalg  = ChiSquareHistogramFit())
    tsk.frompeaks(ref)

    root.bindings = peaks[::-1]/.99 + .05
    pair          = create(root, tsk)

    beads = tuple(i for i in pair.run())[0][0]
    assert_allclose(beads.params, [.99, 0.05], rtol = 5e-3, atol = 5e-3)
    assert beads['peaks'][0] < 0
    assert beads['peaks'][1] < .17

    pair  = create(root, tsk, DataFrameTask(measures = dict(std1 = 'std',
                                                            std2 = ('std', 'mean'),
                                                            std3 = 'resolution')))
    beads = tuple(i for i in pair.run())[0][0]
    assert set(beads.index.names) == {'track', 'bead'}
    assert set(beads.columns)     == {
        'peakposition', 'averageduration', 'hybridisationrate', 'eventcount',
        'referenceposition', 'std1', 'std2', 'std3', 'modification', 'status'
    }

    pair  = create(root, tsk, DataFrameTask(measures = dict(events = True)))
    beads = tuple(i for i in pair.run())[0][0]
    assert set(beads.index.names) == {'track', 'bead', 'cycle'}
    assert set(beads.columns)     == {
        'peakposition',      'averageduration', 'hybridisationrate', 'eventcount',
        'referenceposition', 'avg', 'length', 'start', 'modification', 'status'
    }
コード例 #24
0
def test_diskcache_clear(tmp_path):
    reader = TrackReaderTask(path=utpath("big_legacy"))
    tasks = [
        create(reader, UndersamplingTask(), DataFrameTask()),
        create(reader, DataFrameTask())
    ]
    for i, procs in enumerate(tasks):
        procs.data.setcache(DataFrameTask, {'index': i})

    cnf = DiskCacheConfig(path=str(tmp_path / "cache"))
    assert not Path(cnf.path).exists()

    cnf.insert(tasks, 10001)
    assert Path(cnf.path).exists()

    cnf.clear(complete=True)
    with DiskCache(cnf.path) as cache:
        assert sum(1 for _ in cache.iterkeys()) == 1
        assert cache.get(VERSION_KEY) == VERSION

    for i, procs in enumerate(tasks):
        procs.data.setcache(DataFrameTask, {'index': -1})
    cnf.insert(tasks, 10001)
    assert Path(cnf.path).exists()

    for i, procs in enumerate(tasks):
        procs.data.setcache(DataFrameTask, {'index': -2})
    cnf.update(tasks, 10001)
    assert tasks[0].data.getcache(DataFrameTask)()['index'] == -1
    assert tasks[1].data.getcache(DataFrameTask)()['index'] == -1

    for i, procs in enumerate(tasks):
        procs.data.setcache(DataFrameTask, {'index': -2})
    cnf.clear(processors=tasks)
    assert Path(cnf.path).exists()
    cnf.update(tasks, 10001)
    assert tasks[0].data.getcache(DataFrameTask)()['index'] == -2
    assert tasks[1].data.getcache(DataFrameTask)()['index'] == -2
コード例 #25
0
    def _do(pool, drift = True):
        tasks = (utpath("big_all"),
                 DataSelectionTask(cycles = slice(2)),
                 ExtremumAlignmentTask(phase = 'onlyinitial', minpopulation = 0.),
                 DriftTask(onbeads = False))
        pair = create(tasks[:4 if drift else 3])
        ret  = dict(next(i for i in pair.run(pool = pool))[0,...].withphases(5))
        ret  = {i: j - j.mean() for i, j in ret.items()}

        cache = pair.data.getcache(-1)()
        if cache is not None:
            cache = {i[1] if isinstance(i, tuple) else i: j.value - j.value.mean()
                     for i, j in cache.items()}
        return ret, cache
コード例 #26
0
def test_diskcache_insert(tmp_path):
    reader = TrackReaderTask(path=utpath("big_legacy"))
    tasks = [
        create(reader, UndersamplingTask(), DataFrameTask()),
        create(reader, DataFrameTask())
    ]
    for i, procs in enumerate(tasks):
        procs.data.setcache(DataFrameTask, {'index': i})

    cnf = DiskCacheConfig(path=str(tmp_path / "cache"))
    cnf.clear()
    cnf.insert(tasks, 10001)
    assert cnf.get(tasks[0], 10001)['index'] == 0
    assert cnf.get(tasks[1], 10001)['index'] == 1

    for i, procs in enumerate(tasks):
        procs.data.setcache(DataFrameTask, {'index': i * 2 + 1})

    cnf.insert(tasks, 10002)
    assert cnf.get(tasks[0], 10002)['index'] == 1
    assert cnf.get(tasks[1], 10002)['index'] == 3

    tasks = [
        create(reader, UndersamplingTask(), DataFrameTask()),
        create(reader, DataFrameTask())
    ]
    for i, procs in enumerate(tasks):
        procs.data.setcache(DataFrameTask, {'index': -1})

    cnf.update(tasks, 10001)
    assert tasks[0].data.getcache(DataFrameTask)()['index'] == -1
    assert tasks[1].data.getcache(DataFrameTask)()['index'] == -1

    cnf.update(tasks, 10002)
    assert tasks[0].data.getcache(DataFrameTask)()['index'] == 1
    assert tasks[1].data.getcache(DataFrameTask)()['index'] == 3
コード例 #27
0
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()
コード例 #28
0
    def newtasks(mdl, beads=None, withhp=False):
        "add a list of tasks to the model"
        lst = [
            TrackReaderTask(path=utpath("big_legacy")),
            DataCleaningTask(),
            ClippingTask(),
            ExtremumAlignmentTask(),
            EventDetectionTask(),
            PeakSelectorTask()
        ]
        if beads:
            lst.insert(1, DataSelectionTask(selected=list(beads)))
        if withhp:
            lst.append(
                FitToHairpinTask(sequences=utpath("hairpins.fasta"),
                                 oligos="kmer"))

        mdl.tasks.tasks.tasks.add(create(lst))
コード例 #29
0
def test_task():
    "test task"
    data = next(create(utfilepath('big_selected'), PeakProjectorTask()).run())
    bead = data[0]
    assert isinstance(bead, PeakListArray)
コード例 #30
0
def test_processor2():
    "test processor"
    proc = create(utpath("big_all"), DataCleaningTask())
    _ = next(iter(proc.run()))[0]
    cache = proc.data[1].cache()
    assert list(cache) == [0]