Hello,
I have sample sets from different locations that I would like to process in the same way, but separately. I usually make a feature table summary and take the highest feature count for alpha rarefaction and the select the sampling depth that allows me to keep 95% of my samples. It all works great, but... what if I wanted to do this for 100 sites?
Is it possible to use bash commands with an qiime2 command? I think it is not, but I have not found confirmation of this.
I would like to be able to do something along the lines of:
for folder in Dir
do
qiime feature-table summarize
--i-table $folder/feature_table.qza
--m-sample-metadata-file sample_metadata.txt
--o-visualization $folder/$folder_table_summary.qzv
done
If this was possible it means that I could run my whole qiime2 script recursively instead of doing it manually folder by folder.
Maybe there are better ways to do this? But how would one go about doing it in cli if absolutely necessary?
UPDATE (10/17/22): I got something to work and I figured I would post it in case anybody is curious or has feedback as to how to improve this or point out any potential or incipient issues. Here is the script:
#Making Data Subsets and Getting Core Metrics Recursively using BASH
#Use metadata columns and their values to stratify samples
#To also make subsets including all the samples for each metadata column,
#"All" and "Samples" are added to each values list, respectively.
for metadata-col-1 in All value_x value_y value_z;
do for metadata-col-2 in Samples value_q value_r value_s;
#Make directories for each data subset
do mkdir Path/$metadata-col-1_$metadata-col-2;
#Make Feature Tables for data subsets. There are three possible cases:
if [ "$metadata-col-1" == "All" ] && [ "$metadata-col-2" == "Samples" ];
then echo "THIS IS ALL SAMPLES";
#Make All Samples Feature Table (You probably already have this table, so this step may be redundant)
qiime feature-table filter-samples
--i-table Input_Files/clean_feature_table.qza
--m-metadata-file Input_Files/sample_metadata.txt
--o-filtered-table Path/$metadata-col-1_$metadata-col-2/$metadata-col-1_$metadata-col-2_feature_table.qza ;
elif [ "$metadata-col-1" == "All" ];
then echo "THIS IS ALL metadata-col-1 $metadata-col-2";
#Make All metadata-col-1 for each metadata-col-2 Feature Tables
qiime feature-table filter-samples
--i-table Input_Files/clean_feature_table.qza
--m-metadata-file Input_Files/sample_metadata.txt
--p-where "metadata-col-2 = '$metadata-col-2'"
--o-filtered-table Path/$metadata-col-1_$metadata-col-2/$metadata-col-1_$metadata-col-2_feature_table.qza ;
elif [ "$metadata-col-2" == "Samples" ];
then echo "THIS IS $metadata-col-1 ALL metadata-col-2";
#Make All metadata-col-2 for each metadata-col-1 Feature Tables
qiime feature-table filter-samples
--i-table Input_Files/clean_feature_table.qza
--m-metadata-file Input_Files/sample_metadata.txt
--p-where "metadata-col-1 = '$metadata-col-1'"
--o-filtered-table Path/$metadata-col-1_$metadata-col-2/$metadata-col-1_$metadata-col-2_feature_table.qza ;
else echo "THIS IS $metadata-col-1 $metadata-col-2";
#Make each metadata-col-1 for each metadata-col-2 Feature Tables
qiime feature-table filter-samples
--i-table Input_Files/clean_feature_table.qza
--m-metadata-file Input_Files/sample_metadata.txt
--p-where "metadata-col-1 = '$metadata-col-1' AND metadata-col-2 = '$metadata-col-2'"
--o-filtered-table Path/$metadata-col-1_$metadata-col-2/$metadata-col-1_$metadata-col-2_feature_table.qza ;
fi;
#Make Feature Table Summaries
qiime feature-table summarize
--i-table Path/$metadata-col-1_$metadata-col-2/$metadata-col-1_$metadata-col-2_feature_table.qza
--m-sample-metadata-file Input_Files/sample_metadata.txt
--o-visualization Path/$metadata-col-1_$metadata-col-2/$metadata-col-1_$metadata-col-2_table_summary.qzv ;
#Core Metrics: Alpha and Beta Diversity
qiime diversity core-metrics-phylometadata-col-1etic
--i-phylogeny Input_Files/rooted_tree.qza
--i-table Path/$metadata-col-1_$metadata-col-2/$metadata-col-1_$metadata-col-2_feature_table.qza
--p-sampling-depth 1000
--m-metadata-file Input_Files/sample_metadata.txt
--output-dir Path/$metadata-col-1_$metadata-col-2/$metadata-col-1_$metadata-col-2_core_metrics_results
done;
done
I hope this makes sense!