def relative_abundance(coverage):
relative = {}<EOL>sums = []<EOL>for genome in coverage:<EOL><INDENT>for cov in coverage[genome]:<EOL><INDENT>sums.append(<NUM_LIT:0>)<EOL><DEDENT>break<EOL><DEDENT>for genome in coverage:<EOL><INDENT>index = <NUM_LIT:0><EOL>for cov in coverage[genome]:<EOL><INDENT>sums[index] += cov<EOL>index += <NUM_LIT:1><EOL><DEDENT><DEDENT>for genome in coverage:<EOL><INDENT>index = <NUM_LIT:0><EOL>relative[genome] = []<EOL>for cov in coverage[genome]:<EOL><INDENT>if sums[index] == <NUM_LIT:0>:<EOL><INDENT>relative[genome].append(<NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>relative[genome].append((cov / sums[index]) * float(<NUM_LIT:100>))<EOL><DEDENT>index += <NUM_LIT:1><EOL><DEDENT><DEDENT>return relative<EOL>
cov = number of bases / length of genome
relative abundance = [(cov) / sum(cov for all genomes)] * 100