def save_refs(sam, fastas, genomes, s2b):
if s2b is False:<EOL><INDENT>s2b = {}<EOL><DEDENT>for fasta in fastas:<EOL><INDENT>if fasta is False:<EOL><INDENT>for line in sam:<EOL><INDENT>if line.startswith('<STR_LIT>'):<EOL><INDENT>break<EOL><DEDENT>if line.startswith('<STR_LIT>') is False:<EOL><INDENT>continue<EOL><DEDENT>line = line.strip().split()<EOL>contig, length = line[<NUM_LIT:1>].split('<STR_LIT::>', <NUM_LIT:1>)[<NUM_LIT:1>], int(line[<NUM_LIT:2>].split('<STR_LIT::>', <NUM_LIT:1>)[<NUM_LIT:1>])<EOL>if contig not in s2b:<EOL><INDENT>genome = '<STR_LIT>'<EOL>s2b[contig] = genome<EOL><DEDENT>else:<EOL><INDENT>genome = s2b[contig]<EOL><DEDENT>if genome not in genomes:<EOL><INDENT>genomes[genome] = {}<EOL><DEDENT>if contig not in genomes[genome]:<EOL><INDENT>genomes[genome][contig] = {}<EOL><DEDENT>bp_stats = []<EOL>for i in range(<NUM_LIT:0>, length):<EOL><INDENT>bp_stats.append({'<STR_LIT:A>':<NUM_LIT:0>, '<STR_LIT:T>':<NUM_LIT:0>, '<STR_LIT>':<NUM_LIT:0>, '<STR_LIT:C>':<NUM_LIT:0>, '<STR_LIT:N>':<NUM_LIT:0>,'<STR_LIT>':[], '<STR_LIT>':[], '<STR_LIT>':'<STR_LIT:N>'})<EOL><DEDENT>genomes[genome][contig][sam.name] = {'<STR_LIT>':bp_stats}<EOL>return genomes, s2b<EOL><DEDENT><DEDENT>genome = fasta.rsplit('<STR_LIT:.>', <NUM_LIT:1>)[<NUM_LIT:0>]<EOL>if genome not in genomes:<EOL><INDENT>genomes[genome] = {}<EOL><DEDENT>bp_stats = []<EOL>for seq in parse_fasta(fasta):<EOL><INDENT>contig = seq[<NUM_LIT:0>].split('<STR_LIT:>>')[<NUM_LIT:1>].split()[<NUM_LIT:0>]<EOL>s2b[contig] = genome<EOL>if contig not in genomes[genome]:<EOL><INDENT>genomes[genome][contig] = {}<EOL><DEDENT>bp_stats = []<EOL>for base in seq[<NUM_LIT:1>]:<EOL><INDENT>bp_stats.append({'<STR_LIT:A>':<NUM_LIT:0>, '<STR_LIT:T>':<NUM_LIT:0>, '<STR_LIT>':<NUM_LIT:0>, '<STR_LIT:C>':<NUM_LIT:0>, '<STR_LIT:N>':<NUM_LIT:0>,'<STR_LIT>':[], '<STR_LIT>':[], '<STR_LIT>':base.upper()})<EOL><DEDENT>genomes[genome][contig][sam.name] = {'<STR_LIT>':bp_stats}<EOL><DEDENT>return genomes, s2b<EOL><DEDENT>
genomes = {} # genomes[genome][contig][sample] = {'bp_stats':[]}