Ejemplo n.º 1
0
def output_raw_calls(infile, outfile, limit=None, start=1):
    n_out = limit / 20 if limit > 0 else 100
    n = 0
    l = 0
    result = list()
    with open(infile) as source, open(outfile, "w") as destination:
        while (True):
            line = source.readline()
            if (not line):
                break
            l += 1
            if (l < start):
                continue
            v = Variant(line)
            n += 1
            if (n % n_out == 0):
                print n

            alleles = v.alt_list()
            for allele in alleles:
                variant = dict()
                variant["chromosome"] = v.chr_num()
                variant["position"] = v.start()
                variant["reference"] = v.ref()
                variant["alternative"] = allele
                result.append(variant)
        json.dump(result, destination)
    print "Variants processed: {}".format(n)
Ejemplo n.º 2
0
def compare_db_to_file(file):
    stat = Stat()
    gnomAD = GnomAD()
    with open(file) as input:
        while (True):
            line = input.readline()
            if (not line):
                break
            v = Variant(line, gnomAD_connection=gnomAD)
            alt_list = v.alt_list()
            x1 = 0
            af2 = v.get_gnomad_af()
            for alt in alt_list:
                af1 = gnomAD.get_af(v.chr_num(), v.lowest_coord(), v.ref(),
                                    alt)
                if (af1):
                    x1 += 1

                if (af1 == None and af2 == None):
                    stat.f()
                elif (af1 == af2):
                    stat.t()
                elif (af1):
                    if (af2 == None):
                        stat.one()
                    else:
                        stat.diff()
                else:
                    stat.two()
            if (af2 and (x1 == 0)):
                stat.two0()

    return stat