示例#1
0
def get_freqs(path, contig, pos, ref, alt, tlen_cutoff, fm_cutoff):
    it = pysam.AlignmentFile(path).pileup(contig, pos)
    column = it.next()
    while column.pos < pos:
        column = it.next()
    ref_counts = freq(get_tlens(column, ref, tlen_cutoff, fm_cutoff))
    alt_counts = freq(get_tlens(column, alt, tlen_cutoff, fm_cutoff))
    all_counts = freq(get_tlens(column, "ALL", tlen_cutoff, fm_cutoff))
    return {"ref": ref_counts, "alt": alt_counts, "all": all_counts}
示例#2
0
 def test_freq(self):
     self.assertEqual(freq("ACGTTTAAA"), {
         'A': 4,
         'C': 1,
         'G': 1,
         'T': 3
     })
示例#3
0
 def fill_tables(self):
     self.nucs = set(pr.alignment.seq[pr.query_position] for
                     pr in self.pc.pileups)
     self.tables = {nuc: freq(pr.alignment.opt("FM") for pr in
                              self.pc.pileups if
                              pr.alignment.seq[pr.query_position] == nuc)
                    for nuc in self.nucs}
示例#4
0
 def __init__(self, pileup_column, minFM=2, ref='C', alt='T'):
     all_counts = freq(i.alignment.seq[i.query_position]
                       for i in pileup_column.pileups)
     fm_counts = freq(i.alignment.seq[i.query_position]
                      for i in pileup_column.pileups
                      if i.alignment.opt("FM") >= minFM)
     if alt not in all_counts:
         all_counts[alt] = 0
     if alt not in fm_counts:
         fm_counts[alt] = 0
     self.all = AAFObj(all_counts[alt], sum(all_counts.values()))
     self.fm = AAFObj(fm_counts[alt], sum(fm_counts.values()))
     self.all_discounted = AAFObj(fm_counts[alt], sum(all_counts.values()))
     bc_stacks = get_bc_stack(pileup_column)
     self.all_expected = AAFObj(
         get_expectation_count(bc_stacks, alt, minFM),
         sum(all_counts.values()))
示例#5
0
 def fill_tables(self):
     self.nucs = set(pr.alignment.seq[pr.query_position]
                     for pr in self.pc.pileups)
     self.tables = {
         nuc: freq(
             pr.alignment.opt("FM") for pr in self.pc.pileups
             if pr.alignment.seq[pr.query_position] == nuc)
         for nuc in self.nucs
     }
示例#6
0
def aaf_pos(bam, contig, pos, ref='C', alt='T', minFM=1):
    a = pysam.AlignmentFile(bam)
    b = a.pileup(contig, pos)
    c = b.next()
    while c.pos < pos:
        c = b.next()
    counts = freq(i.alignment.seq[i.query_position] for i in c.pileups
                  if i.alignment.opt("FM") >= minFM)
    try:
        return float(counts[alt]) / counts[ref]
    except KeyError:
        if ref not in counts:
            return -137.
        return 0.
示例#7
0
def aaf_ret(bam, contig, pos, ref='C', alt='T', minFM=1):
    """
    Returns the frequency of ref allele 'C' in pileup in a bam.
    """
    a = pysam.AlignmentFile(bam)
    b = a.pileup(contig, pos)
    c = b.next()
    while c.pos < pos:
        c = b.next()
    counts = freq(i.alignment.seq[i.query_position] for i in c.pileups
                  if i.alignment.opt("FM") >= minFM)
    try:
        return counts[alt] / counts[ref]
    except KeyError:
        if ref not in counts:
            return -137.
        return 0.