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


Python Utilities.parse_line方法代码示例

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


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

示例1: CompoundHets

# 需要导入模块: from utilities import Utilities [as 别名]
# 或者: from utilities.Utilities import parse_line [as 别名]
class CompoundHets(object):
    def __init__(self, input, ped, frequency_cutoff=None, consequence=None, output=None, prefix=None, transcript=False, debug=False,
                 gene_lookback=5, force=False):
        self.frequency_cutoff = frequency_cutoff
        self.consequence = consequence
        self.transcript = transcript
        self.output = output
        self.prefix = prefix
        self.force = force
        self.aggregate_file = os.path.join(output, 'compound_hets.aggregate.tsv')
        if self.prefix:
            self.aggregate_file = os.path.join(output, self.prefix + '.compound_hets.aggregate.tsv')
        self.debug = debug
        self.Utils = Utilities(self.frequency_cutoff, self.consequence, self.transcript, self.debug)
        self.families = self.Utils.read_ped_file(ped)
        self.lookback = gene_lookback
        self.setup_output(output, self.families)
        self.process_file(input)


    # Print each compound het pair for each sample to a sample file
    # Input:
    #   samples: dictionary of lists of tuples of Variants
    #   output: output prefix
    def print_samples(self, samples, output):
        if not samples:
            return
        for s in samples:
            filename = "%s.compound_het_pairs.txt" % s
            if self.prefix:
                filename = self.prefix + "." + filename
            if output:
                filename = "%s.%s.compound_het_pairs.txt" % (output, s)
            f = open(filename, 'w')
            f.write("#PAIR\tCHR\tPOS\tGENE\n")
            count = 1
            for pair in samples[s]:
                v1 = pair[0]
                v2 = pair[1]
                f.write(v1.for_sample_file(count) + "\n")
                f.write(v2.for_sample_file(count) + "\n")
                count += 1
            f.close()

    # Print all pairs of compound hets to file
    # Input:
    #   positions: A list of tuples of variants
    #   output: output file prefix
    def print_positions(self, positions, output):
        if not positions:
            return
        filename = "all_compound_het_pairs.txt"
        if output:
            filename = "%s.all_compound_het_pairs.txt" % output
        f = open(filename, 'w')
        f.write("#PAIR\tCHR\tPOS\tGENE\tFROM_MOTHER\tFROM_FATHER\n")
        count = 1
        for p in positions:
            v1 = p[0]
            v2 = p[1]
            f.write(v1.for_variant_file(count) + "\n")
            f.write(v2.for_variant_file(count) + "\n")
            count += 1
        f.close()

    # Parse each line in the input file, convert it to a Variant object, and assign it to a gene within the gene
    #  dictionary
    # Input:
    #   input: input filename
    # Return:
    #   genes: dictionary of lists of Variants
    def process_file(self, input):
        current_genes = defaultdict(list)
        gene_list = []
        checked_genes = []
        with open(input) as f:
            for line in f:
                if line.startswith('#'):
                    continue
                variant = self.Utils.parse_line(line)
                if variant is None:
                    continue
                if variant.gene not in current_genes:
                    if variant.gene in checked_genes:
                        print("%s ALREADY CHECKED! File may be out of order!" % variant.gene)
                    else:
                        checked_genes.append(variant.gene)
                    gene_list.append(variant.gene)
                    # Keep a lookback of 5 genes to account for gene overlaps
                    if len(current_genes) > self.lookback:
                        to_process = gene_list.pop(0)
                        self.process_gene(current_genes[to_process])
                        del current_genes[to_process]
                current_genes[variant.gene].append(variant)
        for gene in current_genes:
            self.process_gene(current_genes[gene])

    # Get any het calls for a gene and print the results
    # Input:
    #   gene: A list of variants (Variant objects) within a gene
#.........这里部分代码省略.........
开发者ID:gregmcinnes,项目名称:compound-het-calculator,代码行数:103,代码来源:compound-hets.py


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