from oldowan.mtconvert.coverage import calc_coverage
from oldowan.mtconvert.coverage import Coverage
from oldowan.mtconvert.sites2seq import sites2seq

def test_single_rcrs_segment():
    ranges = [(16024,16365),
              (73,340),
              (16000,340),
              (16000,577),
              (577,15992),
              (16000,16569),
             ]
    for item in ranges:
        should_cover = Coverage(item)
        seq = sites2seq('', region=should_cover)
        covers = calc_coverage(seq)
        assert should_cover == covers

def test_gapped_rcrs_segments():
    ranges = [ [(16024,16365), (73,340) ],
               [(16024,16569), (73,340) ],
               [(16024,16569), (73,577) ],
               [(16024,16400), (1,577) ],
             ]
    for pair in ranges:
        should_cover = Coverage(*pair)
        seq = sites2seq('', region=should_cover)
        covers = calc_coverage(seq)
        print should_cover, covers
        assert should_cover == covers

def test_single_variant_segments():
    should_cover = Coverage((16024,16365))
    variants = ['16311',
                '16223 16265T',
                '16223 16260 16270 16287 16311',
                '16148 16172 16187 16188G 16189 16209 16223 16230 16311 16320',
                '16024', # tricky, first site is a variant
                '16365', # tricky, last site is a variant
                '16024 16365', # tricky, both first and last sites are variants
                '16363 16364 16365', # tricky, last few sites are variants
               ]
    for v in variants:
        seq = sites2seq(v, region=should_cover)
        covers = calc_coverage(seq)
        print "should cover: '%s' - does cover: '%s'" % (should_cover, covers)
        assert should_cover == covers

@@ -494,32 +494,111 @@
 c_coverage(seq)%0A
+        print %22should cover: '%25s' - does cover: '%25s'%22 %25 (should_cover, covers)%0A
         assert s
@@ -611,32 +611,32 @@
 cover == covers%0A
-
 %0Adef test_gapped
@@ -1001,16 +1001,59 @@
   print 
+%22should cover: '%25s' - does cover: '%25s'%22 %25 (
 should_c
@@ -1064,16 +1064,17 @@
 , covers
+)
 %0A       
@@ -1837,32 +1837,32 @@
 _cover, covers)%0A
-
         assert s
@@ -1863,28 +1863,989 @@
 sert should_cover == covers%0A
+%0Adef test_gapped_variant_segments():%0A    should_cover = Coverage((16024,16365),(73,340))%0A    variants = %5B'16311 263 311',%0A                '16024 73', # little bit tricky - first site from second chunk is variant %0A                # '16365', # impossible, middle site is a variant%0A               %5D%0A    for v in variants:%0A        seq = sites2seq(v, region=should_cover)%0A        covers = calc_coverage(seq)%0A        print %22should cover: '%25s' - does cover: '%25s'%22 %25 (should_cover, covers)%0A        assert should_cover == covers%0A%0Adef test_more_than_two_gapped_segments():%0A    sets = %5B %5B(16024,16365),(73,340),(577,1000)%5D,%0A             %5B(16024,16365),(16300,340),(577,1000)%5D, # overlapping segments%0A           %5D%0A    for s in sets:%0A        should_cover = Coverage(*s)%0A        seq = sites2seq('', region=should_cover)%0A        covers = calc_coverage(seq)%0A        print %22should cover: '%25s' - does cover: '%25s'%22 %25 (should_cover, covers)%0A        assert should_cover == covers%0A%0A%0A

test for multiple segments