本文整理汇总了Python中CGAT.Bed.blocked_iterator方法的典型用法代码示例。如果您正苦于以下问题:Python Bed.blocked_iterator方法的具体用法?Python Bed.blocked_iterator怎么用?Python Bed.blocked_iterator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGAT.Bed
的用法示例。
在下文中一共展示了Bed.blocked_iterator方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from CGAT import Bed [as 别名]
# 或者: from CGAT.Bed import blocked_iterator [as 别名]
#.........这里部分代码省略.........
parser.add_option("--merge-min-intervals", dest="merge_min_intervals", type="int",
help="only output merged intervals that are build from at least x intervals [default=%default]")
parser.add_option("--merge-by-name", dest="merge_by_name", action="store_true",
help="only merge intervals with the same name [default=%default]")
parser.add_option("--remove-inconsistent", dest="remove_inconsistent", action="store_true",
help="when merging, do not output intervals where the names of overlapping intervals "
"do not match [default=%default]")
parser.add_option("--offset", dest="offset", type="int",
help="offset for shifting intervals [default=%default]")
parser.add_option("-g", "--genome-file", dest="genome_file", type="string",
help="filename with genome.")
parser.add_option("-b", "--bam-file", dest="bam_file", type="string",
help="bam-formatted filename with genome.")
parser.set_defaults(methods=[],
merge_distance=0,
binning_method="equal-bases",
merge_by_name=False,
genome_file=None,
bam_file=None,
num_bins=5,
merge_min_intervals=1,
bin_edges=None,
offset=10000,
test=None,
extend_distance=1000,
remove_inconsistent=False)
(options, args) = E.Start(parser, add_pipe_options=True)
contigs = None
# Why provide full indexed genome, when a tsv of contig sizes would do?
if options.genome_file:
genome_fasta = IndexedFasta.IndexedFasta(options.genome_file)
contigs = genome_fasta.getContigSizes()
if options.bam_file:
samfile = pysam.Samfile(options.bam_file)
contigs = dict(zip(samfile.references, samfile.lengths))
processor = Bed.iterator(options.stdin)
for method in options.methods:
if method == "filter-genome":
if not contigs:
raise ValueError("please supply contig sizes")
processor = filterGenome(processor, contigs)
elif method == "sanitize-genome":
if not contigs:
raise ValueError("please supply contig sizes")
processor = sanitizeGenome(processor, contigs)
elif method == "merge":
processor = merge(processor,
options.merge_distance,
by_name=options.merge_by_name,
min_intervals=options.merge_min_intervals,
remove_inconsistent=options.remove_inconsistent)
elif method == "bins":
if options.bin_edges:
bin_edges = map(float, options.bin_edges.split(","))
# IMS: check bin edges are valid
if not(len(bin_edges) == options.num_bins + 1):
raise ValueError(
"Number of bin edge must be one more than number of bins")
else:
bin_edges = None
processor, bin_edges = Bed.binIntervals(processor,
num_bins=options.num_bins,
method=options.binning_method,
bin_edges=bin_edges)
E.info("# split bed: bin_edges=%s" % (str(bin_edges)))
elif method == "block":
processor = Bed.blocked_iterator(processor)
elif method == "shift":
# IMS: test that contig sizes are availible
if not contigs:
raise ValueError("please supply genome file")
processor = shiftIntervals(
processor, contigs, offset=options.offset)
# IMS: new method: extend intervals by set amount
elif method == "extend":
if not contigs:
raise ValueError("please supply genome file")
processor = extendInterval(processor, contigs, options.offset)
noutput = 0
for bed in processor:
options.stdout.write(str(bed) + "\n")
noutput += 1
E.info("noutput=%i" % (noutput))
E.Stop()