Esempio n. 1
0
def events_worker(fast5_file_name, section, segmentation, trim, kmer_len, transducer,
                  bad, min_prob, alphabet=DEFAULT_ALPHABET, skip=5.0, trans=None):
    """ Worker function for basecall_network.py for basecalling from events

    This worker used the global variable `calc_post` which is set by
    init_worker. `calc_post` is an unpickled compiled sloika model that
    is used to calculate a posterior matrix over states

    :param section: part of read to basecall, 'template' or 'complement'
    :param segmentation: location of segmentation analysis for extracting target read section
    :param trim: (int, int) events to remove from read beginning and end
    :param kmer_len, min_prob, transducer, bad, trans, skip: see `decode_post`
    :param fast5_file_name: filename for single-read fast5 file with event detection and segmentation
    """
    from sloika import features
    try:
        with fast5.Reader(fast5_file_name) as f5:
            ev = f5.get_section_events(section, analysis=segmentation)
            sn = f5.filename_short
    except Exception as e:
        sys.stderr.write("Error getting events for section {!r} in file {}\n{!r}\n".format(section, fast5_file_name, e))
        return None

    ev = util.trim_array(ev, *trim)
    if ev.size == 0:
        sys.stderr.write("Read too short in file {}\n".format(fast5_file_name))
        return None

    inMat = features.from_events(ev, tag='')[:, None, :]
    score, call = decode_post(calc_post(inMat), kmer_len, transducer, bad, min_prob, skip, trans, nbase=len(alphabet))

    return sn, score, call, inMat.shape[0]
Esempio n. 2
0
pf = network.layers[1].layers[0].p.get_value()

iWb = network.layers[1].layers[1].layer.iW.get_value()
sWb = network.layers[1].layers[1].layer.sW.get_value()
bb = network.layers[1].layers[1].layer.b.get_value()
pb = network.layers[1].layers[1].layer.p.get_value()

with fast5.Reader(fn) as f5:
    ev = f5.get_section_events("template", analysis='Segment_Linear')
    sn = f5.filename_short

ev = ev[50:]
print "Input"
print ev[:10]

features = features.from_events(ev, tag='')
print "Features"
print features[:10]

#  Windowing
w = 3
inMat = features
zeros = np.zeros((w // 2, features.shape[1]))
padMat = np.concatenate([zeros, inMat, zeros], axis=0)
tmp = np.concatenate([padMat[i:1 + i - w] for i in xrange(w - 1)], axis=1)
feature3 = np.concatenate([tmp, padMat[w - 1:]], axis=1)
print "Feature 3"
print feature3[:10]


#  LSTM forward