コード例 #1
0
ファイル: test_location.py プロジェクト: yatisht/pycogent
 def test_contains(self):
     """Range contains an item if any span contains it"""
     self.assertContains(self.one, 50)
     self.assertContains(self.one, 0)
     self.assertContains(self.one, 99)
     self.assertNotContains(self.one, 100)
     self.assertContains(self.three, 6)
     self.assertNotContains(self.three, 7)
     self.assertNotContains(self.three, 8)
     self.assertNotContains(self.three, 14)
     self.assertContains(self.three, 15)
     self.assertNotContains(self.three, 29)
     self.assertContains(self.three, 30)
     self.assertContains(self.three, 34)
     self.assertNotContains(self.three, 35)
     self.assertNotContains(self.three, 40)
     #should work if a span is added
     self.three.Spans.append(40)
     self.assertContains(self.three, 40)
     #should work for spans
     self.assertContains(self.three, Span(31, 33))
     self.assertNotContains(self.three, Span(31, 37))
     #span contains itself
     self.assertContains(self.two, self.twocopy)
     #should work for ranges
     self.assertContains(self.three, Range([6, Span(15, 16), Span(30, 33)]))
     #should work for copy, except when extra piece added
     threecopy = Range(self.three)
     self.assertContains(self.three, threecopy)
     threecopy.Spans.append(1000)
     self.assertNotContains(self.three, threecopy)
     self.three.Spans.append(Span(950, 1050))
     self.assertContains(self.three, threecopy)
     self.assertNotContains(threecopy, self.three)
コード例 #2
0
ファイル: test_location.py プロジェクト: yatisht/pycogent
 def test_init(self):
     self.assertEqual(RangeFromString(''), Range())
     self.assertEqual(RangeFromString('  3  , 4\t, ,, 10  ,'),
                      Range([3, 4, 10]))
     self.assertEqual(RangeFromString('3,4-10,1-5'),
                      Range([Span(3), Span(4, 10),
                             Span(1, 5)]))
コード例 #3
0
 def test_mapping(self):
     """Histogram Mapping should apply correct function to values"""
     # bins, data, mapping
     data = ['A','AAA','CCCCC','GGGGGGGGGGGGGG']
     bins = [Span(0,2),Span(2,4),Span(4,6)]
     mapping = Histogram(data=data,bins=bins,Mapping=len)
     self.assertEqual(mapping._values, [['A'],['AAA'],['CCCCC']])
     self.assertEqual(mapping.Other,['GGGGGGGGGGGGGG'])
コード例 #4
0
 def test_init_bins_data(self):
     """Histogram should fill bins with data if supplied"""
     # most basic histogram, bins and data
     data = [1,3,5,'A']
     bins = [Span(0,2),Span(2,4),Span(4,6)]
     data_and_bins = Histogram(data=data,bins=bins)
     self.assertEqual(data_and_bins._bins,bins)
     self.assertEqual(data_and_bins._values,[[1],[3],[5]])
     self.assertEqual(data_and_bins.Other,['A'])
コード例 #5
0
 def test_call(self):
     """Histogram __call__ should update with new data"""
     data = [1,3,5,'A']
     bins = [Span(0,2),Span(2,4),Span(4,6)]
     data_and_bins = Histogram(data=data,bins=bins)
     #update the histogram
     data_and_bins([4,5,6,7])
     self.assertEqual(data_and_bins._values,[[1],[3],[5,4,5]])
     self.assertEqual(data_and_bins.Other,['A',6,7])
コード例 #6
0
ファイル: test_annotation.py プロジェクト: miklou/pycogent
 def test_map(self):
     """reversing a map with multiple spans should preserve span relative
     order"""
     forward = [Span(20, 30), Span(40, 50)]
     fmap = Map(spans=forward, parent_length=100)
     fmap_reversed = fmap.nucleicReversed()
     reverse = [Span(70, 80, Reverse=True), Span(50, 60, Reverse=True)]
     rmap = Map(spans=reverse, parent_length=100)
     for i in range(2):
         self.assertEquals(fmap_reversed.spans[i], rmap.spans[i])
コード例 #7
0
 def test_clear(self):
     """Histogram clear should reset all data"""
     data = [1,3,5,'A']
     bins = [Span(0,2),Span(2,4),Span(4,6)]
     data_and_bins = Histogram(data=data,bins=bins)
     self.assertEqual(data_and_bins._bins,bins)
     self.assertEqual(data_and_bins._values,[[1],[3],[5]])
     self.assertEqual(data_and_bins.Other,['A'])
     data_and_bins.clear()
     self.assertEqual(data_and_bins._values,[[],[],[]])
     self.assertEqual(data_and_bins.Other,[])
コード例 #8
0
 def test_multi(self):
     """Histogram Multi should allow values to match multiple bins"""
     #bins, data, multi=True
     bins2 = [Span(0,5),Span(3,8),Span(6,10)]
     data2 = [0,1,2,3,4,5,6,7,8,9,10]
     not_multi = Histogram(data2,bins2)
     self.assertEqual(not_multi._values,[[0,1,2,3,4],[5,6,7],[8,9]])
     self.assertEqual(not_multi.Other,[10])
     multi = Histogram(data2,bins2,Multi=True)
     self.assertEqual(multi._values,[[0,1,2,3,4],[3,4,5,6,7],[6,7,8,9]])
     self.assertEqual(multi.Other,[10])
コード例 #9
0
ファイル: test_location.py プロジェクト: yatisht/pycogent
 def setUp(self):
     """Set up a few standard ranges."""
     self.one = Range(Span(0, 100))
     self.two = Range([Span(3, 5), Span(8, 11)])
     self.three = Range([Span(6, 7), Span(15, 17), Span(30, 35)])
     self.overlapping = Range([Span(6, 10), Span(7, 3)])
     self.single = Range(0)
     self.singles = Range([3, 11])
     self.twocopy = Range(self.two)
     self.twothree = Range([self.two, self.three])
     self.empty = Range([Span(6, 6), Span(8, 8)])
コード例 #10
0
ファイル: test_location.py プロジェクト: yatisht/pycogent
 def test_cmp(self):
     """Ranges should compare equal if they have the same spans"""
     self.assertEqual(
         self.twothree,
         Range([
             Span(3, 5),
             Span(8, 11),
             Span(6, 7),
             Span(15, 17),
             Span(30, 35)
         ]))
     self.assertEqual(Range(), Range())
コード例 #11
0
ファイル: test_location.py プロジェクト: yatisht/pycogent
 def test_endsAt(self):
     """Span endsAt should return True if input matches"""
     e, f = self.empty, self.full
     s = Span(30, 1000)
     t = Span(-100, 35)
     self.assertTrue(e.endsAt(0))
     self.assertTrue(f.endsAt(35))
     self.assertTrue(s.endsAt(1000))
     self.assertFalse(f.endsAt(s))
     self.assertFalse(s.endsAt(f))
     self.assertTrue(f.endsAt(t))
     self.assertTrue(t.endsAt(f))
コード例 #12
0
ファイル: test_location.py プロジェクト: yatisht/pycogent
 def test_endsInside(self):
     """Span endsInside should return True if input ends inside span"""
     e, f, i, o = self.empty, self.full, self.inside, self.overlapping
     self.assertFalse(e.endsInside(0))
     self.assertFalse(f.endsInside(30))
     self.assertFalse(f.endsInside(34))
     self.assertFalse(f.endsInside(35))
     self.assertFalse(e.endsInside(f))
     self.assertTrue(i.endsInside(f))
     self.assertFalse(f.endsInside(i))
     self.assertFalse(o.endsInside(f))
     self.assertFalse(o.endsInside(i))
     self.assertTrue(e.endsInside(Span(-1, 1)))
     self.assertTrue(e.endsInside(Span(0, 1)))
     self.assertFalse(e.endsInside(Span(-1, 0)))
コード例 #13
0
ファイル: test_location.py プロジェクト: yatisht/pycogent
 def test_Extent(self):
     """Range extent should span limits of range"""
     self.assertEqual(self.one.Extent, Span(0, 100))
     self.assertEqual(self.three.Extent, Span(6, 35))
     self.assertEqual(self.singles.Extent, Span(3, 12))
     self.assertEqual(self.single.Extent, Span(0, 1))
     self.three.Spans.append(Span(100, 105, Reverse=True))
     self.assertEqual(self.three.Extent, Span(6, 105))
     self.three.Spans.append(Span(-100, -1000))
     self.assertEqual(self.three.Extent, Span(-1000, 105))
コード例 #14
0
ファイル: test_location.py プロジェクト: yatisht/pycogent
 def setUp(self):
     """Define some standard Spans"""
     self.empty = Span(0, 0)
     self.full = Span(35, 30)  #will convert to (30, 35) internally
     self.overlapping = Span(32, 36)
     self.inside = Span(31, 32)
     self.before = Span(25, 30)
     self.after = Span(35, 40)
     self.reverse = Span(30, 35, Reverse=True)
     self.spans_zero = Span(-5, 5)
コード例 #15
0
 def test_toFreqs(self):
     """Histogram toFreqs() should return a Freqs object"""
     h = Histogram(list(range(0,20)),bins=[Span(0,3),Span(3,10),
         Span(10,18),Span(18,20)])
     constructor=str
     f = h.toFreqs()
     self.assertEqual(f[constructor(Span(0,3))],3)
     self.assertEqual(f[constructor(Span(3,10))],7)
     self.assertEqual(f[constructor(Span(10,18))],8)
     self.assertEqual(f[constructor(Span(18,20))],2)
コード例 #16
0
ファイル: test_location.py プロジェクト: yatisht/pycogent
 def setUp(self):
     """Define some standard Spans"""
     self.empty = Range(Span(0, 0))
     self.full = Range(Span(30, 35))
     self.overlapping = Range(Span(32, 36))
     self.inside = Range(Span(31, 32))
     self.before = Range(Span(25, 30))
     self.after = Range(Span(35, 40))
     self.reverse = Range(Span(30, 35, Reverse=True))
     self.spans_zero = Range(Span(-5, 5))
コード例 #17
0
ファイル: test_location.py プロジェクト: yatisht/pycogent
 def test_Reverse(self):
     """Range Reverse property should return True if any span reversed"""
     self.assertFalse(self.one.Reverse)
     self.one.reverse()
     self.assertTrue(self.one.Reverse)
     self.assertFalse(self.two.Reverse)
     self.two.Spans.append(Span(0, 100, Reverse=True))
     self.assertTrue(self.two.Reverse)
     self.two.reverse()
     self.assertTrue(self.two.Reverse)
コード例 #18
0
ファイル: test_location.py プロジェクト: yatisht/pycogent
 def test_init(self):
     """Span object should init with Start, End, and Length"""
     s = Span(0)
     self.assertEqual(s.Start, 0)
     self.assertEqual(s.End, 1)
     self.assertEqual(s.Reverse, False)
     #to get an empty interval, must specify start and end explicitly
     t = Span(0, 0)
     self.assertEqual(t.Start, 0)
     self.assertEqual(t.End, 0)
     self.assertEqual(t.Reverse, False)
     #should be able to specify direction also
     u = Span(5, 15, Reverse=True)
     self.assertEqual(u.Start, 5)
     self.assertEqual(u.End, 15)
     self.assertEqual(u.Reverse, True)
     #should be able to init from another span
     v = Span(u)
     self.assertEqual(v.Start, 5)
     self.assertEqual(v.End, 15)
     self.assertEqual(v.Reverse, True)
コード例 #19
0
ファイル: test_location.py プロジェクト: yatisht/pycogent
 def test_reverse(self):
     """Range reverse method should reverse each span"""
     for s in self.overlapping.Spans:
         self.assertFalse(s.Reverse)
     self.overlapping.reverse()
     for s in self.overlapping.Spans:
         self.assertTrue(s.Reverse)
     self.overlapping.Spans.append(Span(0, 100))
     self.overlapping.reverse()
     for s in self.overlapping.Spans[0:1]:
         self.assertFalse(s.Reverse)
     self.assertTrue(self.overlapping.Spans[-1].Reverse)
コード例 #20
0
ファイル: test_location.py プロジェクト: yatisht/pycogent
 def test_startsAt(self):
     """Span startsAt should return True if input matches"""
     e, f = self.empty, self.full
     s = Span(30, 1000)
     self.assertTrue(e.startsAt(0))
     self.assertTrue(f.startsAt(30))
     self.assertTrue(s.startsAt(30))
     self.assertTrue(f.startsAt(s))
     self.assertTrue(s.startsAt(f))
     self.assertFalse(e.startsAt(f))
     self.assertFalse(e.startsAt(-1))
     self.assertFalse(e.startsAt(1))
     self.assertFalse(f.startsAt(29))
コード例 #21
0
def cigar_to_map(cigar_text):
    """convert cigar string into Map"""
    assert 'I' not in cigar_text
    spans, posn = [], 0
    for n, c in pattern.findall(cigar_text):
        if n:
            n = int(n)
        else:
            n = 1

        if c == 'M':
            spans.append(Span(posn, posn + n))
            posn += n
        else:
            spans.append(LostSpan(n))
    map = Map(spans=spans, parent_length=posn)
    return map
コード例 #22
0
ファイル: test_location.py プロジェクト: yatisht/pycogent
    def test_cmp(self):
        """Span cmp should support sort by 1st/2nd index and direction"""
        s, e, f, r, i, o = self.spans_zero, self.empty, self.full, \
            self.reverse, self.inside, self.overlapping

        n = Span(30, 36)

        expected_order = [s, e, f, r, n, i, o]
        first = expected_order[:]
        first.sort()
        second = [r, o, f, s, e, i, n]
        second.sort()
        for i, j in zip(first, second):
            self.assertSameObj(i, j)

        for i, j in zip(first, expected_order):
            self.assertSameObj(i, j)
コード例 #23
0
 def test_spans(self):
     # a simple two part map of length 10
     map = Map([(0, 5), (5, 10)], parent_length=10)
     # try different spans on the above map
     for ((start, end), expected) in [
         ((0, 4), "[0:4]"),
         ((0, 5), "[0:5]"),
         ((0, 6), "[0:5, 5:6]"),
         ((5, 10), "[5:10]"),
         ((-1, 10), "[-1-, 0:5, 5:10]"),
         ((5, 11), "[5:10, -1-]"),
         ((0, 10), "[0:5, 5:10]"),
         ((10, 0), "[10:5, 5:0]"),
     ]:
         r = repr(Span(start, end, Reverse=start > end).remapWith(map))
         #print (start, end), r,
         if r != expected:
             self.fail(repr((r, expected)))
コード例 #24
0
ファイル: test_location.py プロジェクト: yatisht/pycogent
 def test_iter(self):
     """Range iter should iterate through each span in turn"""
     self.assertEqual(list(iter(self.two)), [3, 4, 8, 9, 10])
     self.two.Spans.insert(1, Span(103, 101, Reverse=True))
     self.assertEqual(list(iter(self.two)), [3, 4, 102, 101, 8, 9, 10])
コード例 #25
0
ファイル: test_location.py プロジェクト: yatisht/pycogent
 def test_init(self):
     """Range init from Spans, numbers, or Ranges should work OK."""
     #single span
     self.assertEqual(self.one, Span(0, 100))
     #list of spans
     self.assertEqual(self.two.Spans, [Span(3, 5), Span(8, 11)])
     #another range
     self.assertEqual(self.two, self.twocopy)
     #list of ranges
     self.assertEqual(
         self.twothree.Spans,
         [Span(3, 5),
          Span(8, 11),
          Span(6, 7),
          Span(15, 17),
          Span(30, 35)])
     #list of numbers
     self.assertEqual(self.singles.Spans, [Span(3, 4), Span(11, 12)])
     #single number
     self.assertEqual(self.single.Spans, [Span(0, 1)])
     #nothing
     self.assertEqual(Range().Spans, [])
コード例 #26
0
ファイル: test_location.py プロジェクト: yatisht/pycogent
 def test_sort(self):
     """Range sort should sort component spans"""
     one = self.one
     one.sort()
     self.assertEqual(one.Spans, [Span(100, 0)])
     one.Spans.append(Span(-20, -10))
     self.assertEqual(one.Spans, [Span(0, 100), Span(-20, -10)])
     one.sort()
     self.assertEqual(one.Spans, [Span(-20, -10), Span(0, 100)])
     one.Spans.append(Span(-20, -10, Reverse=True))
     self.assertEqual(
         one.Spans,
         [Span(-20, -10),
          Span(0, 100),
          Span(-20, -10, Reverse=True)])
     one.sort()
     self.assertEqual(
         one.Spans,
         [Span(-20, -10),
          Span(-20, -10, Reverse=True),
          Span(0, 100)])
コード例 #27
0
ファイル: test_location.py プロジェクト: yatisht/pycogent
 def test_simplify(self):
     """Range reduce should group overlapping ranges"""
     #consolidate should have no effect when no overlap
     r = self.two
     r.simplify()
     self.assertEqual(r.Spans, [Span(3, 5), Span(8, 11)])
     #should consolidate an overlap of the same direction
     r.Spans.append(Span(-1, 4))
     r.simplify()
     self.assertEqual(r.Spans, [Span(-1, 5), Span(8, 11)])
     #should also consolidate _adjacent_ spans of the same direction
     r.Spans.append(Span(11, 14))
     r.simplify()
     self.assertEqual(r.Spans, [Span(-1, 5), Span(8, 14)])
     #bridge should cause consolidations
     s = Range(r)
     s.Spans.append(Span(5, 8))
     s.simplify()
     self.assertEqual(s.Spans, [Span(-1, 14)])
     #ditto for bridge that overlaps everything
     s = Range(r)
     s.Spans.append(Span(-100, 100))
     s.simplify()
     self.assertEqual(s.Spans, [Span(-100, 100)])
     #however, can't consolidate span in other orientation
     s = Range(r)
     s.Spans.append(Span(-100, 100, Reverse=True))
     self.assertEqual(s.Spans, [Span(-1,5), Span(8,14), \
         Span(-100,100,Reverse=True)])
コード例 #28
0
ファイル: test_annotation.py プロジェクト: miklou/pycogent
 def test_span(self):
     length = 100
     forward = Span(20, 30)
     reverse = Span(70, 80, Reverse=True)
     assert forward.reversedRelativeTo(100) == reverse
     assert reverse.reversedRelativeTo(100) == forward
コード例 #29
0
 def test_init_bins(self):
     """Histogram should set _bins property correctly"""
     bins = [Span(0,2),Span(2,4),Span(4,6)]
     bins_only = Histogram(bins=bins)
     self.assertEqual(bins_only._bins, bins)