Exemplo n.º 1
0
 def testGetItemNegative(self):
     "test negative indexes to feature."
     ivf = IntervalFile(self.file)
     iv = ivf.next()
     self.assert_(iv[-self.fieldcount+self.chrpos].startswith("chr"), iv[-self.fieldcount+self.chrpos])
     self.assert_(iv[-self.fieldcount+self.startpos].isdigit(), iv[-self.fieldcount+self.startpos])
     self.assert_(iv[-self.fieldcount+self.stoppos].isdigit())
Exemplo n.º 2
0
 def testGetItem(self):
     "getitem now supports direct access to the line."
     ivf = IntervalFile(self.file)
     iv = ivf.next()
     self.assert_(iv[self.chrpos].startswith("chr"))
     self.assert_(iv[self.startpos].isdigit())
     self.assert_(iv[self.startpos].isdigit())
Exemplo n.º 3
0
    def testStart(self):
        ivf = IntervalFile(self.file)
        iv = ivf.next()
        orig_string = str(iv)

        # 0-based.
        orig_start = iv.start

        # Setting .start always sets 0-based coord.
        iv.start = orig_start

        # But for GFF setting .start should also make the .fields[3] the GFF
        # 1-based coord
        assert iv.start == int(iv.fields[3]) - 1

        second_string = str(iv)
        second_start = iv.start
        iv.start = second_start

        # Check .start and .fields[3] internal consistency again
        assert iv.start == int(iv.fields[3]) - 1

        print '   orig:', '(start=%s)' % orig_start, orig_string
        print ' second:', '(start=%s)' % second_start, second_string
        print 'current:', '(start=%s)' % iv.start, str(iv)
        self.assert_(orig_start == second_start == iv.start)
        self.assert_(orig_string == second_string == str(iv))
Exemplo n.º 4
0
 def testGetItem(self):
     "getitem now supports direct access to the line."
     ivf = IntervalFile(self.file)
     iv = ivf.next()
     self.assert_(iv[self.chrpos].startswith("chr"))
     self.assert_(iv[self.startpos].isdigit())
     self.assert_(iv[self.startpos].isdigit())
Exemplo n.º 5
0
 def testSetItem(self):
     ivf = IntervalFile(self.file)
     iv = ivf.next()
     iv.chrom = 'chrfake'
     print iv.fields
     self.assertEqual(iv['chrom'], 'chrfake')
     self.assertEqual(iv.chrom, 'chrfake')
Exemplo n.º 6
0
    def testStart(self):
        ivf = IntervalFile(self.file)
        iv = ivf.next()
        orig_string = str(iv)

        # 0-based.
        orig_start = iv.start

        # Setting .start always sets 0-based coord.
        iv.start = orig_start

        # But for GFF setting .start should also make the .fields[3] the GFF
        # 1-based coord
        assert iv.start == int(iv.fields[3])-1

        second_string = str(iv)
        second_start = iv.start
        iv.start = second_start

        # Check .start and .fields[3] internal consistency again
        assert iv.start == int(iv.fields[3])-1

        print '   orig:', '(start=%s)'%orig_start, orig_string
        print ' second:', '(start=%s)'%second_start, second_string
        print 'current:', '(start=%s)'%iv.start, str(iv)
        self.assert_(orig_start == second_start == iv.start)
        self.assert_(orig_string == second_string == str(iv))
Exemplo n.º 7
0
 def testAppend(self):
     ivf = IntervalFile(self.file)
     iv = ivf.next()
     print iv.fields
     iv.append('asdf')
     print iv
     self.assertEqual(iv[-1], 'asdf')
Exemplo n.º 8
0
 def testName(self):
     ivf = IntervalFile(self.file)
     iv = ivf.next()
     iv.name = "bart simpson"
     self.assertEqual(iv.name, "bart simpson")
     if iv.file_type == "gff":
         self.assert_("bart" in iv.fields[8])
Exemplo n.º 9
0
 def testSetItem(self):
     ivf = IntervalFile(self.file)
     iv = ivf.next()
     iv.chrom = 'chrfake'
     print iv.fields
     self.assertEqual(iv['chrom'], 'chrfake')
     self.assertEqual(iv.chrom, 'chrfake')
Exemplo n.º 10
0
 def testAppend(self):
     ivf = IntervalFile(self.file)
     iv = ivf.next()
     print iv.fields
     iv.append('asdf')
     print iv
     self.assertEqual(iv[-1], 'asdf')
Exemplo n.º 11
0
 def testName(self):
     ivf = IntervalFile(self.file)
     iv = ivf.next()
     iv.name = "bart simpson"
     self.assertEqual(iv.name, "bart simpson")
     if iv.file_type == "gff":
         self.assert_("bart" in iv.fields[8])
Exemplo n.º 12
0
 def testGetItemNegative(self):
     "test negative indexes to feature."
     ivf = IntervalFile(self.file)
     iv = ivf.next()
     self.assert_(iv[-self.fieldcount + self.chrpos].startswith("chr"),
                  iv[-self.fieldcount + self.chrpos])
     self.assert_(iv[-self.fieldcount + self.startpos].isdigit(),
                  iv[-self.fieldcount + self.startpos])
     self.assert_(iv[-self.fieldcount + self.stoppos].isdigit())
Exemplo n.º 13
0
    def testGetItemSlice(self):
        "getitem now supports direct access to the line."
        ivf = IntervalFile(self.file)
        iv = ivf.next()
        seqid, = iv[self.chrpos:self.chrpos + 1]
        start, end = iv[self.startpos:self.stoppos + 1]
        self.assert_(start.isdigit())

        self.assertEqual(int(end), iv.end)
        self.assertEqual(seqid, iv.chrom)
Exemplo n.º 14
0
 def testGetItemSliceNone(self):
     " test support for funky slices."
     ivf = IntervalFile(self.file)
     iv = ivf.next()
     self.assertEqual(len(iv[:3]), 3)
     self.assertEqual(len(iv[3:3]), 0)
     self.assertEqual(len(iv[2:]), self.fieldcount-2, iv[2:])
     
     print len(iv.fields), iv.fields
     self.assertRaises(IndexError, lambda x: iv[x], self.fieldcount+1)
Exemplo n.º 15
0
    def testGetItemSliceNone(self):
        " test support for funky slices."
        ivf = IntervalFile(self.file)
        iv = ivf.next()
        self.assertEqual(len(iv[:3]), 3)
        self.assertEqual(len(iv[3:3]), 0)
        self.assertEqual(len(iv[2:]), self.fieldcount - 2, iv[2:])

        print len(iv.fields), iv.fields
        self.assertRaises(IndexError, lambda x: iv[x], self.fieldcount + 1)
Exemplo n.º 16
0
    def testGetItemSlice(self):
        "getitem now supports direct access to the line."
        ivf = IntervalFile(self.file)
        iv = ivf.next()
        seqid, = iv[self.chrpos:self.chrpos+1]
        start, end = iv[self.startpos:self.stoppos+1]
        self.assert_(start.isdigit())

        self.assertEqual(int(end), iv.end)
        self.assertEqual(seqid, iv.chrom)
Exemplo n.º 17
0
 def testSetAttrs(self):
     ivf = IntervalFile(self.file)
     iv = ivf.next()
     if iv.file_type != 'gff':
         self.assertRaises(ValueError, iv.attrs.__setitem__, 'a','b')
         return
     iv.attrs['ID'] = 'fake'
     iv.attrs['field0'] = 'asdf'
     self.assertEqual(str(iv.attrs), iv[8])
     self.assert_('field0=asdf' in iv[8])
     self.assert_('ID=fake' in iv[8])
Exemplo n.º 18
0
 def testSetAttrs(self):
     ivf = IntervalFile(self.file)
     iv = ivf.next()
     if iv.file_type != 'gff':
         self.assertRaises(ValueError, iv.attrs.__setitem__, 'a', 'b')
         return
     iv.attrs['ID'] = 'fake'
     iv.attrs['field0'] = 'asdf'
     self.assertEqual(str(iv.attrs), iv[8])
     self.assert_('field0=asdf' in iv[8])
     self.assert_('ID=fake' in iv[8])
Exemplo n.º 19
0
 def testStart(self):
     ivf = IntervalFile(self.file)
     iv = ivf.next()
     orig_string = str(iv)
     orig_start = iv.start
     iv.start = orig_start
     second_string = str(iv)
     second_start = iv.start
     iv.start = second_start
     print '   orig:', '(start=%s)' % orig_start, orig_string
     print ' second:', '(start=%s)' % second_start, second_string
     print 'current:', '(start=%s)' % iv.start, str(iv)
     self.assert_(orig_start == second_start == iv.start)
     self.assert_(orig_string == second_string == str(iv))
Exemplo n.º 20
0
 def testStart(self):
     ivf = IntervalFile(self.file)
     iv = ivf.next()
     orig_string = str(iv)
     orig_start = iv.start
     iv.start = orig_start
     second_string = str(iv)
     second_start = iv.start
     iv.start = second_start
     print '   orig:', '(start=%s)'%orig_start, orig_string
     print ' second:', '(start=%s)'%second_start, second_string
     print 'current:', '(start=%s)'%iv.start, str(iv)
     self.assert_(orig_start == second_start == iv.start)
     self.assert_(orig_string == second_string == str(iv))
Exemplo n.º 21
0
 def testGetItemString(self):
     ivf = IntervalFile(self.file)
     iv = ivf.next()
     self.assertEqual(iv['chrom'], iv.chrom)
     self.assertEqual(iv['start'], iv.start)
     self.assertEqual(iv['end'], iv.end)
Exemplo n.º 22
0
 def testSetItemString(self):
     ivf = IntervalFile(self.file)
     iv = ivf.next()
     iv['chrom'] = 'fake'
     self.assertEqual(iv['chrom'], 'fake')
     self.assertEqual(iv.chrom, 'fake')
Exemplo n.º 23
0
 def testSetItemString(self):
     ivf = IntervalFile(self.file)
     iv = ivf.next()
     iv['chrom'] = 'fake'
     self.assertEqual(iv['chrom'], 'fake')
     self.assertEqual(iv.chrom, 'fake')
Exemplo n.º 24
0
 def testGetItemString(self):
     ivf = IntervalFile(self.file)
     iv = ivf.next()
     self.assertEqual(iv['chrom'], iv.chrom)
     self.assertEqual(iv['start'], iv.start)
     self.assertEqual(iv['end'], iv.end)