本文整理汇总了Python中pybedtools.create_interval_from_list函数的典型用法代码示例。如果您正苦于以下问题:Python create_interval_from_list函数的具体用法?Python create_interval_from_list怎么用?Python create_interval_from_list使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_interval_from_list函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pickleable
def test_pickleable():
interval = pybedtools.create_interval_from_list(
['chr1', '1', '100', 'asdf'])
fn = pybedtools.BedTool._tmp()
import pickle
out = open(fn, 'w')
pickle.dump(interval, out)
out.close()
new_interval = pickle.load(open(fn))
assert str(interval) == str(new_interval)
interval = pybedtools.create_interval_from_list(
['chr1', '1', '100'])
fn = pybedtools.BedTool._tmp()
import pickle
out = open(fn, 'w')
pickle.dump(interval, out)
out.close()
new_interval = pickle.load(open(fn))
assert str(interval) == str(new_interval)
interval = pybedtools.create_interval_from_list(
"chr2L . UTR 41 70 0 + . ID=mRNA:xs2:UTR:41-70;Parent=mRNA:xs2;".split('\t'))
fn = pybedtools.BedTool._tmp()
import pickle
out = open(fn, 'w')
pickle.dump(interval, out)
out.close()
new_interval = pickle.load(open(fn))
assert str(interval) == str(new_interval)
示例2: test_RNA_position_placement
def test_RNA_position_placement(self):
"""
Makes sure that the placement within a region or list of regions is correct
"""
tool = pybedtools.create_interval_from_list("chr1 50 60 ENSMUSG1_1_83;ENSMUSG1_6_83 0 + 60 60".split())
location_dict = {"ENSMUSG1" : {"strand" : "+", "regions" : [(0,100),
]
}
}
self.assertEqual(RNA_position(tool, location_dict), (.60, .60))
tool = pybedtools.create_interval_from_list("chr1 50 60 ENSMUSG1_1_83;ENSMUSG1_6_83 0 - 60 60".split())
location_dict = {"ENSMUSG1" : {"strand" : "-", "regions" : [(0,100),
]
}
}
#individual_fraction, total_fraction
self.assertEqual(RNA_position(tool, location_dict), (.4, .4))
示例3: string_to_interval
def string_to_interval(s):
"""
Convert string of the form "chrom:start-stop" or "chrom:start-stop[strand]" to an interval.
Assumes zero-based coords.
If it's already an interval, then return it as-is.
"""
if isinstance(s, basestring):
m = coord_re.search(s)
if m.group('strand'):
return pybedtools.create_interval_from_list([
m.group('chrom'),
m.group('start'),
m.group('stop'),
'.',
'0',
m.group('strand')])
else:
return pybedtools.create_interval_from_list([
m.group('chrom'),
m.group('start'),
m.group('stop'),
])
return s
示例4: test_convert_to_mRNA_position_placement
def test_convert_to_mRNA_position_placement(self):
"""
Makes sure that the placement within a region or list of regions is correct
"""
return
interval = pybedtools.create_interval_from_list("ENSMUSG1 50 60 ENSMUSG1_1_83;ENSMUSG1_6_83 0 + 60 60".split())
location_dict = {"ENSMUSG1" : {"strand" : "+", "regions" : [(0,100),
]
}
}
correct_tool = pybedtools.create_interval_from_list("ENSMUSG1 50 60 ENSMUSG1_1_83;ENSMUSG1_6_83 0 + 60 60".split())
self.assertEqual(convert_to_mRNA_position(interval, location_dict), correct_tool)
interval = pybedtools.create_interval_from_list("ENSMUSG1 50 60 ENSMUSG1_1_83;ENSMUSG1_6_83 0 -".split())
location_dict = {"ENSMUSG1" : {"strand" : "-", "regions" : [(0,100),
]
}
}
#individual_fraction, total_fraction
correct_tool = pybedtools.create_interval_from_list("ENSMUSG1 40 50 ENSMUSG1_1_83;ENSMUSG1_6_83 0 -".split())
x = convert_to_mRNA_position(interval, location_dict)
print x
self.assertEqual(x, correct_tool)
示例5: test_convert_to_mRNA_position_placement_split
def test_convert_to_mRNA_position_placement_split(self):
"""
Makes sure that lists of regions works for both positive and negative strands
"""
return
tool = pybedtools.create_interval_from_list("ENSMUSG1 125 127 ENSMUSG1_1_83;ENSMUSG1_6_83 0 + 125 125".split())
location_dict = {"ENSMUSG1" : {"strand" : "+", "regions" : [(0, 50),
(100, 150),
]
}
}
correct_tool = pybedtools.create_interval_from_list("ENSMUSG1 75 77 ENSMUSG1_1_83;ENSMUSG1_6_83 0 + 125 125".split())
self.assertEqual(convert_to_mRNA_position(tool, location_dict), correct_tool )
tool = pybedtools.create_interval_from_list("ENSMUSG1 25 27 ENSMUSG1_1_83;ENSMUSG1_6_83 0 - 25 25".split())
location_dict = {"ENSMUSG1" : {"strand" : "-", "regions" : [(100, 150),
(0, 50),
]
}
}
correct_tool = pybedtools.create_interval_from_list("ENSMUSG1 73 75 ENSMUSG1_1_83;ENSMUSG1_6_83 0 - 25 25".split())
self.assertEqual(convert_to_mRNA_position(tool, location_dict), correct_tool)
示例6: finder
def finder(self, region):
s = ['.' for i in self.current_seq]
for hit in self.regex_plus.finditer(self.current_seq):
start, stop = hit.span()
s[start:stop] = hit.group()
strand = ' (+)'
s[stop:len(strand)] = strand
self.intervals.append(pybedtools.create_interval_from_list([
region.chrom,
str(region.start + start),
str(region.start + stop),
hit.group(),
'0',
'+']))
for hit in self.regex_minus.finditer(self.current_seq):
start, stop = hit.span()
s[start:stop] = Seq(hit.group()).reverse_complement()
strand = ' (-)'
s[stop:len(strand)] = strand
self.intervals.append(pybedtools.create_interval_from_list([
region.chrom,
str(region.start + start),
str(region.start + stop),
hit.group(),
'0',
'-']))
yield ''.join(s)
示例7: test_RNA_position_placement_split
def test_RNA_position_placement_split(self):
"""
Makes sure that lists of regions works for both positive and negative strands
"""
tool = pybedtools.create_interval_from_list("chr1 50 60 ENSMUSG1_1_83;ENSMUSG1_6_83 0 + 125 125".split())
location_dict = {"ENSMUSG1" : {"strand" : "+", "regions" : [(0, 50),
(100, 150),
]
}
}
self.assertEqual(RNA_position(tool, location_dict), (.50, .75) )
tool = pybedtools.create_interval_from_list("chr1 50 60 ENSMUSG1_1_83;ENSMUSG1_6_83 0 - 25 25".split())
location_dict = {"ENSMUSG1" : {"strand" : "-", "regions" : [(100, 150),
(0, 50),
]
}
}
self.assertEqual(RNA_position(tool, location_dict), (.50, .75))
示例8: test_minus_feature_is_reversed_profile
def test_minus_feature_is_reversed_profile(self):
feature1 = pybedtools.create_interval_from_list(['chr2L', '0', '20', '.', '.', '+'])
feature2 = pybedtools.create_interval_from_list(['chr2L', '0', '20', '.', '.', '-'])
x, y = self.m.local_coverage(feature1, fragment_size=5)
xm, ym = self.m.local_coverage(feature2, fragment_size=5)
pp(list(enumerate(zip(ym, y))))
assert list(ym) == list(y[::-1])
assert list(xm) == list(x)
示例9: test_all_hits
def test_all_hits():
a = pybedtools.example_bedtool('a.bed')
assert [a[2], a[3]] == a.all_hits(pybedtools.create_interval_from_list(
['chr1', '450', '905', '.', '.', '-']))
assert [a[2]] == a.all_hits(pybedtools.create_interval_from_list(
['chr1', '450', '905', '.', '.', '-']), same_strand=True)
示例10: test_count_hits
def test_count_hits():
a = pybedtools.example_bedtool('a.bed')
assert len(a.all_hits(pybedtools.create_interval_from_list(
['chr1', '450', '905', '.', '.', '-']))) == 2
assert len(a.all_hits(pybedtools.create_interval_from_list(
['chr1', '450', '905', '.', '.', '-']), same_strand=True)) == 1
示例11: test_any_hits
def test_any_hits():
a = pybedtools.example_bedtool('a.bed')
assert 1 == a.any_hits(pybedtools.create_interval_from_list(
['chr1', '900', '905', '.', '.', '-']))
assert 0 == a.any_hits(pybedtools.create_interval_from_list(
['chr1', '900', '905', '.', '.', '-']), same_strand=True)
assert 0 == a.any_hits(pybedtools.create_interval_from_list(
['chr1', '8000', '9000', '.', '.', '-']))
示例12: test_gtf_gff_attrs
def test_gtf_gff_attrs():
# smoke test.
#
# this has always worked:
gff = ["chr1","fake","mRNA","51", "300",".", "+",".","ID=mRNA1;Parent=gene1;"]
gff = pybedtools.create_interval_from_list(gff)
gff.attrs
# this previously failed because of the "=" in the attr string.
gff = ['scaffold_52', 'Cufflinks', 'exon', '5478', '5568', '.', '+', '.', 'gene_id "XLOC_017766"; transcript_id "TCONS_00033979"; exon_number "6"; gene_name "g18412"; oId "PAC:26897502"; nearest_ref "PAC:26897502"; class_code "="; tss_id "TSS21210"; p_id "P18851";']
gff = pybedtools.create_interval_from_list(gff)
gff.attrs
示例13: _create_window
def _create_window(self):
istart = self.start # interval start
istop = self.start + self.size # interval stop
while istop < self.stop and istart < self.stop:
window = map(str, [self.chrom, istart, istop])
window = pybedtools.create_interval_from_list(window)
yield window
istart += self.slide
istop += self.slide
window = map(str, [self.chrom, istart, self.stop])
window = pybedtools.create_interval_from_list(window)
yield window
示例14: test_interval_index
def test_interval_index():
"""
supplement to the more general test in test_cbedtools.IntervalTest.testGetItemNegative
"""
iv = pybedtools.create_interval_from_list('chr21 9719768 9721892 ALR/Alpha 1004 +'.split())
assert iv[-1] == '+'
assert iv[2:-1] == ['9721892', 'ALR/Alpha', '1004']
iv = pybedtools.create_interval_from_list(
['chr1', 'ucb', 'gene', '465', '805', '.', '+', '.',
'ID=thaliana_1_465_805;match=scaffold_801404.1;rname=thaliana_1_465_805'])
print iv[4:-3]
assert iv[4:-3] == ['805', '.']
示例15: get_bedtool_iter
def get_bedtool_iter():
for gene_num, gene_entry in table.iterrows():
chrom = gene_entry["chrom"]
start = int(gene_entry["txStart"]) + 1
end = int(gene_entry["txEnd"])
strand = gene_entry["strand"]
# Annotation fields
name2 = gene_entry["name2"]
if pandas.isnull(name2):
name2 = "NA"
refseq_id = gene_entry["refseq"]
if pandas.isnull(refseq_id):
refseq_id = "NA"
gene_symbol = gene_entry[gene_symbol_col]
if pandas.isnull(gene_symbol):
gene_symbol = "NA"
attributes = \
"ID=%s;ensg_id=%s;refseq_id=%s;gsymbol=%s;" \
%(name2,
name2,
refseq_id,
gene_symbol)
# Convert table to BedTool
gff_entry = [chrom,
"genes_table",
"gene",
str(start),
str(end),
".",
strand,
".",
attributes]
gff_interval = \
pybedtools.create_interval_from_list(gff_entry)
yield gff_interval