code: def save_refs(sam, fastas, genomes, s2b):
      
      if s2b is False:
          s2b = {}
      for fasta in fastas:
          # if no reference sequence supplied, get length from sam file
          if fasta is False:
              for line in sam:
                  if line.startswith('@PG'):
                      break
                  if line.startswith('@SQ') is False:
                      continue
                  line = line.strip().split()
                  contig, length = line[1].split(':', 1)[1], int(line[2].split(':', 1)[1])
                  if contig not in s2b:
                      genome = 'n/a'
                      s2b[contig] = genome
                  else:
                      genome = s2b[contig]
                  if genome not in genomes:
                      genomes[genome] = {}
                  if contig not in genomes[genome]:
                      genomes[genome][contig] = {}
                  bp_stats = []
                  for i in range(0, length):
                      bp_stats.append({'A':0, 'T':0, 'G':0, 'C':0, 'N':0, \
                                          'In':[], 'Del':[], 'ref':'N'})
                  genomes[genome][contig][sam.name] = {'bp_stats':bp_stats}
                  return genomes, s2b
          # save reference sequences, if available
          genome = fasta.rsplit('.', 1)[0]
          if genome not in genomes:
              genomes[genome] = {}
          bp_stats = []
          for seq in parse_fasta(fasta):
              contig = seq[0].split('>')[1].split()[0]
              s2b[contig] = genome
              if contig not in genomes[genome]:
                  genomes[genome][contig] = {}
              bp_stats = []
              for base in seq[1]:
                  bp_stats.append({'A':0, 'T':0, 'G':0, 'C':0, 'N':0, \
                                      'In':[], 'Del':[], 'ref':base.upper()})
              genomes[genome][contig][sam.name] = {'bp_stats':bp_stats}
          return genomes, s2b
docs: genomes = {} # genomes[genome][contig][sample] = {'bp_stats':[]}