def parse(self, filename, filtered=True, cleanup=False, stutter=False):
        self.samplekey = op.basename(filename).split(".")[0]
        logging.debug("Parse `{}` (filtered={} stutter={})".\
                        format(filename, filtered, stutter))
        fp = must_open(filename)
        reader = vcf.Reader(fp)
        for record in reader:
            if stutter and record.CHROM != "chrY":
                continue
            if filtered and record.FILTER:
                continue
            info = record.INFO
            ref = float(info["REF"])
            rpa = info.get("RPA", ref)
            motif = info["MOTIF"]
            name = "_".join(str(x) for x in (record.CHROM, record.POS, motif))
            for sample in record.samples:
                if stutter:
                    dp = int(sample["DP"])
                    if dp < 10:
                        break
                    allreads = sample["ALLREADS"]
                    counts = []
                    for r in allreads.split(";"):
                        k, v = r.split("|")
                        counts.append(int(v))
                    mode = max(counts)
                    st = dp - mode
                    if st * 1. / dp > .2:
                        break
                    self.evidence[name] = "{},{}".format(st, dp)
                    break

                gt = sample["GT"]
                if filtered and sample["FT"] != "PASS":
                    continue
                if gt == "0/0":
                    alleles = (ref, ref)
                elif gt in ("0/1", "1/0"):
                    alleles = (ref, rpa[0])
                elif gt == "1/1":
                    alleles = (rpa[0], rpa[0])
                elif gt == "1/2":
                    alleles = rpa
                self[name] = ",".join(str(int(x)) for x in sorted(alleles))

                # Collect supporting read evidence
                motif_length = len(motif)
                adjusted_alleles = [(x - ref) * motif_length for x in alleles]
                support = stutters = 0
                allreads = sample["ALLREADS"]
                for r in allreads.split(";"):
                    k, v = r.split("|")
                    k, v = int(k), int(v)
                    min_dist = min([abs(k - x) for x in adjusted_alleles])
                    if motif_length * .5 < min_dist < motif_length * 1.5:
                        stutters += v
                    support += v
                self.evidence[name] = "{},{}".format(stutters, support)

        if cleanup:
            sh("rm -f {}".format(op.basename(filename)))
dataset/ETHPy150Open tanghaibao/jcvi/variation/str.py/LobSTRvcf.parse/original