Skip to content

Commit

Permalink
handle ancombc edge case with two classes + nan, also make filtered t…
Browse files Browse the repository at this point in the history
…ables more manageable
  • Loading branch information
adamcantor22 committed Aug 14, 2024
1 parent 1ee83ec commit e847c91
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mmeds/snakemake/rules/common.smk
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def pairwise_splits(wildcards, tool, vars):
splits += expand("results/{var}/lefse_plot.{feature_table}.{var}.{subclass}.pdf",
feature_table=tables, var=var, subclass=subclasses)
elif tool == "ancombc":
splits += expand("differential_abundance/{var}/ancom-bc_barplot.{feature_table}.{var}.qzv",
splits += expand("differential_abundance/{var}/ancom-bc_barplot.{feature_table}-{var}-clean.{var}.qzv",
feature_table=tables, var=var)
continue

Expand Down
2 changes: 1 addition & 1 deletion mmeds/snakemake/rules/differential_abundance.smk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
rule differential_abundance_ancom_bc:
input:
feature_table = "tables/{table}.qza",
feature_table = "tables/{var}/{table}.qza",
mapping_file = "tables/qiime_mapping_file.tsv"
output:
diffs = "differential_abundance/{var}/ancom-bc_diffs.{table}.{var}.qza",
Expand Down
19 changes: 18 additions & 1 deletion mmeds/snakemake/rules/file_manipulation.smk
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,26 @@ rule extract_feature_table_tsv:
rm -f tables/{wildcards.table}.biom
"""

rule extract_feature_table_tsv_class:
input:
"tables/{class}/{table}.qza"
output:
"tables/{class}/{table}.tsv"
conda:
"qiime2-2020.8.0"
shell:
"""
unzip -jo {input} -d tables/tmp_unzip_{wildcards.table}
mv tables/tmp_unzip_{wildcards.table}/feature-table.biom tables/{wildcards.table}.biom
biom convert --to-tsv -i tables/{wildcards.table}.biom -o {output}
sed -i '1d;2s/^#//' {output}
rm -rf tables/tmp_unzip_{wildcards.table}
rm -f tables/{wildcards.table}.biom
"""

rule format_metadata_qiime_to_lefse:
input:
feature_table = "tables/{table}.tsv",
feature_table = "tables/{class}/{table}.tsv",
mapping_file = "tables/qiime_mapping_file.tsv"
output:
"tables/{class}/lefse_format.{table}.{class}.{subclass}.tsv"
Expand Down
17 changes: 16 additions & 1 deletion mmeds/snakemake/rules/table_filtering.smk
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rule filter_table_to_two_classes:
feature_table = "tables/{table}.qza",
mapping_file = "tables/qiime_mapping_file.tsv"
output:
"tables/{table}.{category}-{class1}-or-{class2}.qza"
"tables/{category}/{table}.{category}-{class1}-or-{class2}.qza"
conda:
"qiime2-2020.8.0"
shell:
Expand All @@ -27,3 +27,18 @@ rule filter_table_to_two_classes:
"--m-metadata-file {input.mapping_file} "
"--p-where \"[{wildcards.category}]==\'{wildcards.class1}\' OR [{wildcards.category}]==\'{wildcards.class2}\'\" "
"--o-filtered-table {output}"

rule filter_nans:
input:
feature_table = "tables/{table}.qza",
mapping_file = "tables/qiime_mapping_file.tsv"
output:
"tables/{category}/{table}-{category}-clean.qza"
conda:
"qiime2-2020.8.0"
shell:
"qiime feature-table filter-samples "
"--i-table {input.feature_table} "
"--m-metadata-file {input.mapping_file} "
"--p-where \"[wildcards.category]!=\'nan\'\" "
"--o-filtered-table {output}"

0 comments on commit e847c91

Please sign in to comment.