当前位置: 首页>>代码示例>>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;未经允许,请勿转载。