INNER CODE UNIT · Python
read_bracken_report
StaPH-B/docker-builds · build-files/cbird-util/2.0/html_report.py:14
def read_bracken_report(taxon_report):
# get bracken report
df = pd.read_csv(taxon_report, sep = '\t')
df = df.sort_values(by=['fraction_total_reads'], ascending=False)
# find top tax id & write
with open("taxid.txt", "w") as f:
taxid = df["taxonomy_id"][0]
f.write(str(taxid))
# Species
df2 = df.loc[:, ["name", "fraction_total_reads" ]].copy()
df2['fraction_total_reads'] = df2['fraction_total_reads'].apply(lambda x: round(x*100, 2))
df2 = df2.rename(columns={"name": "Microorganism", "fraction_total_reads": "Abundance(%)"})
return df2
def read_mlst_report(mlst_report):
df = pd.read_csv(mlst_report, sep="\t", skiprows=1, header=None)