当前位置: 首页>>代码示例>>Python>>正文


Python Bed.binIntervals方法代码示例

本文整理汇总了Python中CGAT.Bed.binIntervals方法的典型用法代码示例。如果您正苦于以下问题:Python Bed.binIntervals方法的具体用法?Python Bed.binIntervals怎么用?Python Bed.binIntervals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CGAT.Bed的用法示例。


在下文中一共展示了Bed.binIntervals方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from CGAT import Bed [as 别名]
# 或者: from CGAT.Bed import binIntervals [as 别名]
def main(argv=sys.argv):

    parser = E.OptionParser(version="%prog version: $Id: bed2bed.py 2861 2010-02-23 17:36:32Z andreas $",
                            usage=globals()["__doc__"])

    # IMS: new method: extend intervals by set amount
    parser.add_option("-m", "--method", dest="methods", type="choice", action="append",
                      choices=("merge", "filter-genome", "bins",
                               "block", "sanitize-genome", "shift", "extend"),
                      help="method to apply [default=%default]")

    parser.add_option("--num-bins", dest="num_bins", type="int",
                      help="number of bins into which to merge (used for method `bins) [default=%default]")

    parser.add_option("--bin-edges", dest="bin_edges", type="string",
                      help="bin_edges for binning method [default=%default]")

    parser.add_option("--binning-method", dest="binning_method", type="choice",
                      choices=(
                          "equal-bases", "equal-intervals", "equal-range"),
                      help="method used for binning (used for method `bins` if no bin_edges is given) [default=%default]")

    parser.add_option("--merge-distance", dest="merge_distance", type="int",
                      help="distance in bases over which to merge that are not directly adjacent [default=%default]")

    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,
#.........这里部分代码省略.........
开发者ID:lesheng,项目名称:cgat,代码行数:103,代码来源:bed2bed.py


注:本文中的CGAT.Bed.binIntervals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。