當前位置: 首頁>>代碼示例>>Python>>正文


Python pybedtools.IntervalFile類代碼示例

本文整理匯總了Python中pybedtools.IntervalFile的典型用法代碼示例。如果您正苦於以下問題:Python IntervalFile類的具體用法?Python IntervalFile怎麽用?Python IntervalFile使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了IntervalFile類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testStart

    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))
開發者ID:ffrancis,項目名稱:pybedtools,代碼行數:27,代碼來源:test_cbedtools.py

示例2: testName

 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])
開發者ID:ffrancis,項目名稱:pybedtools,代碼行數:7,代碼來源:test_cbedtools.py

示例3: testSetItem

 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')
開發者ID:ffrancis,項目名稱:pybedtools,代碼行數:7,代碼來源:test_cbedtools.py

示例4: testAppend

 def testAppend(self):
     ivf = IntervalFile(self.file)
     iv = ivf.next()
     print iv.fields
     iv.append('asdf')
     print iv
     self.assertEqual(iv[-1], 'asdf')
開發者ID:ffrancis,項目名稱:pybedtools,代碼行數:7,代碼來源:test_cbedtools.py

示例5: testGetItemNegative

 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())
開發者ID:ffrancis,項目名稱:pybedtools,代碼行數:7,代碼來源:test_cbedtools.py

示例6: testGetItem

 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())
開發者ID:ffrancis,項目名稱:pybedtools,代碼行數:7,代碼來源:test_cbedtools.py

示例7: testGetItemSliceNone

 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)
開發者ID:ffrancis,項目名稱:pybedtools,代碼行數:10,代碼來源:test_cbedtools.py

示例8: testGetItemSlice

    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)
開發者ID:ffrancis,項目名稱:pybedtools,代碼行數:10,代碼來源:test_cbedtools.py

示例9: testSetAttrs

 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])
開發者ID:Fabrices,項目名稱:pybedtools,代碼行數:11,代碼來源:test_cbedtools.py

示例10: IntervalFileTest

class IntervalFileTest(unittest.TestCase):
    file = "data/rmsk.hg18.chr21.small.bed"
    def setUp(self):
        self.file = os.path.join(PATH, self.file)
        self.bed = IntervalFile(self.file)

    def testFileType(self):
        self.assert_(self.bed.file_type == "bed", (self.bed.file_type, self.file))

        gff = os.path.join(PATH, "data/c.gff")
        i = IntervalFile(gff)
        self.assert_(i.file_type == "gff", (i.file_type, gff))

    def testOverlaps(self):
        i    = Interval("chr21", 9719768, 9739768)
        hits = self.bed.all_hits(i)
        self.assertEqual(len(hits), 8)
        for hit in hits:
            self.assert_(hit.start <= 9739768 and hit.end >= 9719768)

    def testStrands(self):
        i = Interval("chr21", 9719768, 9739768, "+")
        hits = self.bed.all_hits(i, same_strand=True)
        for hit in hits:
            self.assert_(hit.strand == '+')

        i = Interval("chr21", 9719768, 9739768, "-")
        hits = self.bed.all_hits(i, same_strand=True)
        for hit in hits:
            self.assert_(hit.strand == '-')

    def testRichCmp(self):
        a = Interval("chr21", 9719768, 9739768)
        b = Interval("chr21", 9719767, 9739768)
        self.assert_(a < b)
        self.assert_(b < a)
        c = Interval("chr21", 9719767, 9739768)
        self.assert_(c == b)
        d = Interval("chr22", 9719767, 9739768)
        self.assert_(c != d)
開發者ID:Fabrices,項目名稱:pybedtools,代碼行數:40,代碼來源:test_cbedtools.py

示例11: setUp

 def setUp(self):
     self.file = os.path.join(PATH, self.file)
     self.bed = IntervalFile(self.file)
開發者ID:PanosFirmpas,項目名稱:pybedtools,代碼行數:3,代碼來源:test_cbedtools.py

示例12: IntervalFileTest

class IntervalFileTest(unittest.TestCase):
    file = "data/rmsk.hg18.chr21.small.bed"
    def setUp(self):
        self.file = os.path.join(PATH, self.file)
        self.bed = IntervalFile(self.file)

    def testFileType(self):
        self.assert_(self.bed.file_type == "bed", (self.bed.file_type, self.file))

        gff = os.path.join(PATH, "data/c.gff")
        i = IntervalFile(gff)
        self.assert_(i.file_type == "gff", (i.file_type, gff))

    def testOverlaps(self):
        i    = Interval("chr21", 9719768, 9739768)
        hits = self.bed.all_hits(i)
        self.assertEqual(len(hits), 8)
        for hit in hits:
            self.assert_(hit.start <= 9739768 and hit.end >= 9719768)

    def testStrands(self):
        i = Interval("chr21", 9719768, 9739768, "+")
        hits = self.bed.all_hits(i, same_strand=True)
        for hit in hits:
            self.assert_(hit.strand == '+')

        i = Interval("chr21", 9719768, 9739768, "-")
        hits = self.bed.all_hits(i, same_strand=True)
        for hit in hits:
            self.assert_(hit.strand == '-')

    def testRichCmp(self):

        # be obsessive . . .
        #
        # ==
        a = Interval("chr21", 100, 200)
        b = Interval("chr21", 100, 200)
        self.assert_(a == b)
        self.assertFalse(a != b)
        self.assert_(a <= b)
        self.assert_(a >= b)
        self.assertFalse(a < b)
        self.assertFalse(a > b)

        a = Interval("chr21", 100, 100)
        b = Interval("chr21", 100, 100)
        self.assert_(a == b)
        self.assertFalse(a != b)
        self.assert_(a <= b)
        self.assert_(a >= b)
        self.assertFalse(a < b)
        self.assertFalse(a > b)


        # != because of strand
        a = Interval("chr21", 100, 200, strand='+')
        b = Interval("chr21", 100, 200, strand='-')
        self.assertFalse(a == b)
        self.assert_(a != b)
        self.assertFalse(a <= b)
        self.assertFalse(a >= b)
        self.assertFalse(a < b)
        self.assertFalse(a > b)

        # a >= b
        a = Interval("chr21", 100, 300)
        b = Interval("chr21", 100, 200)
        self.assertFalse(a == b)
        self.assert_(a != b)
        self.assertFalse(a <= b)
        self.assert_(a >= b)
        self.assertFalse(a < b)
        self.assertFalse(a > b)

        # a <= b
        a = Interval("chr21", 100, 300)
        b = Interval("chr21", 300, 300)
        self.assertFalse(a == b)
        self.assert_(a != b)
        self.assert_(a <= b)
        self.assertFalse(a >= b)
        self.assertFalse(a < b)
        self.assertFalse(a > b)


        # a <= b
        a = Interval("chr21", 100, 300)
        b = Interval("chr21", 250, 300)
        self.assertFalse(a == b)
        self.assert_(a != b)
        self.assert_(a <= b)
        self.assertFalse(a >= b)
        self.assertFalse(a < b)
        self.assertFalse(a > b)

        # a < b
        a = Interval("chr21", 100, 200)
        b = Interval("chr21", 201, 300)
        self.assertFalse(a == b)
#.........這裏部分代碼省略.........
開發者ID:PanosFirmpas,項目名稱:pybedtools,代碼行數:101,代碼來源:test_cbedtools.py

示例13: testSetItemString

 def testSetItemString(self):
     ivf = IntervalFile(self.file)
     iv = ivf.next()
     iv['chrom'] = 'fake'
     self.assertEqual(iv['chrom'], 'fake')
     self.assertEqual(iv.chrom, 'fake')
開發者ID:ffrancis,項目名稱:pybedtools,代碼行數:6,代碼來源:test_cbedtools.py

示例14: testGetItemString

 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)
開發者ID:ffrancis,項目名稱:pybedtools,代碼行數:6,代碼來源:test_cbedtools.py

示例15: size

1 = start_byte,
2 = end_byte,
3 = num_records,
4 = max_interval size (future, for binary search)
"""

    # what are the BED files
    A_file = sys.argv[1]
    B_file = sys.argv[2]

    # expected index file name
    A_idx_file = A_file + ".idx"
    B_idx_file = B_file + ".idx"

    # open up the BED files.
    A = IntervalFile(A_file) # The Query File
    B = IntervalFile(B_file) # The Database File
    
    # create index files if they don't yet exist
    if not os.path.exists(A_idx_file):
        index_bed.index(A_file)
    if not os.path.exists(B_idx_file):
        index_bed.index(B_file)
    
    # load the indices for A and B
    A_map = [] # list of chrom/offset tuples
    for line in open(A_idx_file):
        fields = line.strip().split("\t")
        A_map.append((fields[0], int(fields[1]), int(fields[2]), int(fields[3]), int(fields[4])))
    B_map = [] # list of chrom/offset tuples
    for line in open(B_idx_file):
開發者ID:arq5x,項目名稱:chrom_sweep,代碼行數:31,代碼來源:chrom_sweep_with_index.py


注:本文中的pybedtools.IntervalFile類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。