Example #1
0
def test_read_index():
    assert_true(os.path.exists(_sidx))
    ibbr = IndexByReadId(_s)
    idx = ibbr.read_index()
    #import pdb; pdb.set_trace()
    assert_true(isinstance(ibbr.idx, OrderedDict))
    assert_equal(ibbr.n_records, 1010)
Example #2
0
def test_first_last():
    ibbr = IndexByReadId(_s)
    first_last = ("SRR043348.1017172", "SRR043396.9722121")
    for t in first_last:
        hits = ibbr.get_reads_by_id(t)
        n = 0
        for h in hits:
            n += 1
            assert_equal(t, h.query_name)
        assert_equal(n, 2)
Example #3
0
def _find_targets(f, targets, expect):
    ibbr = IndexByReadId(f)
    ibbr.read_index()
    for t in targets:
        hits = ibbr.get_reads_by_id(t)
        n = 0
        for h in hits:
            n += 1
            assert_equal(t, h.query_name)
        assert_equal(n, expect)
Example #4
0
def test_sort_creates_index():
    if os.path.exists(_sidx):
        os.remove(_sidx)
    ibbr = IndexByReadId(_f)
    ibbr.sort_bam(outfile=_s, batch_size=100)
    assert_equal(ibbr.bam, _s)
    assert_equal(ibbr.index_file, _sidx)
    ibbr.create_index()
    t = "SRR043372.11318637"
    hits = ibbr.get_reads_by_id(t)
    n = 0
    for h in hits:
        n += 1
        assert_equal(t, h.query_name)
    assert_equal(n, 2)
Example #5
0
def test_create_index():
    if os.path.exists(_sidx):
        os.remove(_sidx)
        assert_false(os.path.exists(_sidx))
    ibbr = IndexByReadId(_s)
    ibbr.create_index(chunk_size=100)
    assert_true(os.path.exists(_sidx))
    ibbr2 = IndexByReadId(_s2)
    ibbr2.create_index()
    assert_true(os.path.exists(_s2idx))
    sibbr = IndexByReadId(_ssam)
    sibbr.create_index(chunk_size=100)
    cribbr = IndexByReadId(_scram)
    assert_raises(NotImplementedError, cribbr.create_index)
Example #6
0
def test_unsorted_error():
    ibbr = IndexByReadId(_f)
    assert_raises(UnsortedBamError, ibbr.create_index)
Example #7
0
def test_sort_input():
    for f in [_s, _s2, _sidx, _s2idx]:
        if os.path.exists(f):
            os.remove(f)
    ibbr = IndexByReadId(_f)
    ibbr.sort_bam(outfile=_s, batch_size=100)
    ibbr2 = IndexByReadId(_f2)
    ibbr2.sort_bam()
    assert_true(os.path.exists(_s2))
    ibbr.sort_bam(outfile=_scram, batch_size=100)
    ibbr.sort_bam(outfile=_ssam, batch_size=100)
Example #8
0
def test_non_existent():
    ibbr = IndexByReadId(_s2)
    hits = ibbr.get_reads_by_id(  #search for non-existent read
        "NZ_GG703879.1_967999_968061_0_1_0_0_4:0:0_1:0:0_62bb")
    assert_equal(len(hits), 0)