code: def get_region_nt_counts(region, bam, stranded=False):
      if type(bam) == str:
          bam = pysam.AlignmentFile(bam, 'rb')
      if type(region) is str:
          r = parse_region(region)
          if len(r) == 3:
              chrom, start, end = r
          elif len(r) == 4:
              chrom, start, end, strand = r
          start = int(start)
          end = int(end)
          ind = ['{}:{}'.format(chrom, x) for 
                 x in range(start, end + 1)]
          pp = bam.pileup(region=region, truncate=True)
      elif type(region) is (list or tuple):
          chrom, start, end = region
          ind = ['{}:{}'.format(chrom, x) for 
                 x in range(int(start) + 1, int(end) + 1)]
          pp = bam.pileup(chrom, start, end, truncate=True)
      cols = ['A', 'T', 'C', 'G', 'N']
      if stranded:
          cols = ['{}+'.format(x) for x in cols] + ['{}-'.format(x) for x in cols]
      counts = pd.DataFrame(0, index=ind, columns=cols)
      for pc in pp: 
          pos = pc.reference_pos + 1
          r1_qnames = []
          r1_nts = []
          r2_qnames = []
          r2_nts = []
          for pr in pc.pileups:
              qnames = [r1_qnames, r2_qnames][pr.alignment.is_read2]
              nts = [r1_nts, r2_nts][pr.alignment.is_read2]
              nt = _pos_nt(pr, pc.reference_pos, stranded)
              if nt:
                  qnames.append(pr.alignment.qname)
                  nts.append(nt)
          r1 = pd.Series(r1_nts, index=r1_qnames)
          r2 = pd.Series(r2_nts, index=r2_qnames)
          df = pd.DataFrame([r1, r2], index=['R1', 'R2']).T
          singles = df[df.isnull().sum(axis=1) == 1]
          doubles = df.dropna()
          vcs = []
          vcs.append(singles['R1'].value_counts())
          vcs.append(singles['R2'].value_counts())
          doubles = doubles[doubles.R1 == doubles.R2]
          vcs.append(doubles.R1.value_counts())
          for vc in vcs:
              counts.ix['{}:{}'.format(chrom, pos), vc.index] += vc
      return counts