def exchanges_per_taxon(output_dir: str, results: MicomResultsDirectory, direction: str = "import") -> None: """Plot the exchange fluxes.""" template = env.get_template("umap.html") data_loc = path.join(output_dir, "umap.csv") exchanges = results.exchange_fluxes.view(pd.DataFrame) exchanges = exchanges[(exchanges.taxon != "medium") & (exchanges.direction == direction) & (exchanges.flux.abs() > 1e-6)] exchanges.flux = exchanges.flux.abs() mat = exchanges.pivot_table(values="flux", index=["sample_id", "taxon"], columns="reaction", fill_value=0) umapped = UMAP().fit_transform(mat.values) umapped = pd.DataFrame(umapped, index=mat.index, columns=["UMAP 1", "UMAP 2"]).reset_index() umapped.to_csv(data_loc) template.stream(data=umapped.to_json(orient="records"), width=800, height=600).dump(path.join(output_dir, "index.html"))