Commit 6d568a03 authored by Erwan DELAGE's avatar Erwan DELAGE
Browse files

Export rarefied table in BIOM and TSV format

parent 0e00228a
......@@ -8,6 +8,7 @@ import pandas as pd
import os
import sys
import shutil
import subprocess
# The input directory is the output of the Qiime2 diversity analysis
INDIR = sys.argv[1]
......@@ -46,7 +47,8 @@ for alpha_diversity_metric in alpha_diversity_metrics:
# Combine all dataframes in a single one
list_df = list()
for sub_dir in os.listdir(INDIR + "/temp_alpha_diversity/"):
list_df.append(pd.read_csv(INDIR + "/temp_alpha_diversity/" + sub_dir + "/alpha-diversity.tsv", sep="\t", index_col=0))
list_df.append(pd.read_csv(INDIR + "/temp_alpha_diversity/" +
sub_dir + "/alpha-diversity.tsv", sep="\t", index_col=0))
alpha_diversity_df = reduce(lambda left, right: pd.merge(left, right, left_index=True, right_index=True), list_df)
......@@ -56,3 +58,17 @@ alpha_diversity_df.to_csv(OUTDIR + "alpha_diversity.tsv", sep="\t")
# Remove temporary directory
shutil.rmtree(INDIR + "/temp_alpha_diversity/", ignore_errors=True)
########################
# EXPORT RAREFIED TABLE#
########################
# Load rarefied table and export it in BIOM format
artifact = Artifact.load(INDIR + "qiime_artifacts/rarefied_table.qza")
artifact.export_data(OUTDIR)
os.rename(OUTDIR + "feature-table.biom", OUTDIR + "rarefied_table.biom")
# Convert BIOM to TSV
process = subprocess.Popen(['biom', 'convert', '-i', OUTDIR + "rarefied_table.biom", '-o', OUTDIR + "rarefied_table.tsv", "--to-tsv"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment