How to use the cogent3.core.location.Span function in cogent3

To help you get started, we’ve selected a few cogent3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cogent3 / cogent3 / tests / test_maths / test_stats / test_histogram.py View on Github external
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)
github cogent3 / cogent3 / tests / test_maths / test_stats / test_histogram.py View on Github external
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'])
github cogent3 / cogent3 / tests / test_core / test_location.py View on Github external
def test_ends_inside(self):
        """Span ends_inside should return True if input ends inside span"""
        e, f, i, o = self.empty, self.full, self.inside, self.overlapping
        self.assertFalse(e.ends_inside(0))
        self.assertFalse(f.ends_inside(30))
        self.assertFalse(f.ends_inside(34))
        self.assertFalse(f.ends_inside(35))
        self.assertFalse(e.ends_inside(f))
        self.assertTrue(i.ends_inside(f))
        self.assertFalse(f.ends_inside(i))
        self.assertFalse(o.ends_inside(f))
        self.assertFalse(o.ends_inside(i))
        self.assertTrue(e.ends_inside(Span(-1, 1)))
        self.assertTrue(e.ends_inside(Span(0, 1)))
        self.assertFalse(e.ends_inside(Span(-1, 0)))
github cogent3 / cogent3 / tests / test_maths / test_stats / test_histogram.py View on Github external
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])
github cogent3 / cogent3 / tests / test_core / test_location.py View on Github external
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)
github cogent3 / cogent3 / tests / test_core / test_location.py View on Github external
# 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)
github cogent3 / cogent3 / tests / test_core / test_location.py View on Github external
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())
github cogent3 / cogent3 / tests / test_maths / test_stats / test_histogram.py View on Github external
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,[])
github cogent3 / cogent3 / tests / test_maths / test_stats / test_histogram.py View on Github external
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)