-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq2pipe_step7_taxa_filtering.sh
executable file
·173 lines (146 loc) · 6.29 KB
/
q2pipe_step7_taxa_filtering.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
################################
# #
# Qiime 2 Pipeline #
# By: Patrick Gagne (NRCan) #
# Step 8 - Taxa Filtering #
# October 5, 2021 #
# #
################################
exit_on_error(){
echo "Qiime2 command error detected"
echo "Exiting program"
exit 1
}
optionfile=$1
if [ ! $optionfile ] || [ ! -e $optionfile ] || [ ! -r $optionfile ]
then
echo "ERROR: you must specify a valid, accessible qiime2 optionfile"
exit 1
fi
source $optionfile
if [ $TEMPORARY_DIRECTORY ]
then
echo "Overriding default temporary directory to $TEMPORARY_DIRECTORY"
if [ ! -d $TEMPORARY_DIRECTORY ] || [ ! -w $TEMPORARY_DIRECTORY ]
then
echo "ERROR: $TEMPORARY_DIRECTORY does not exist or is read only"
exit 2
fi
export TMPDIR=$TEMPORARY_DIRECTORY
fi
if [ ! $TMPDIR ]
then
export TMPDIR=/tmp
fi
if [ "$APPTAINER_COMMAND" != "" ]
then
echo "DEBUG: Checking temporary folder"
temp_check=$( $APPTAINER_COMMAND mktemp -t Q2PIPE_TEMPFOLDER_CHECK.XXXXXX.temp )
bname=$( basename $temp_check )
if [ ! -e $TMPDIR/$bname ]
then
echo "ERROR: Disparity between Apptainer temporary folder and system temporary folder"
echo "Please make sure both are pointing to the same folder"
exit 5
else
echo "DEBUG: Temporary file check status: OK"
rm $TMPDIR/Q2PIPE_TEMPFOLDER_CHECK.??????.temp
fi
fi
metatag="metafiltered_"
if [ "$p_where" == "" ]
then
echo "No metadata filtering parameter detected... skipping"
metatag=""
else
echo "Applying metadata filtering..."
echo "Metadata filtering parameter: $p_where"
$APPTAINER_COMMAND qiime feature-table filter-samples \
--i-table $ANALYSIS_NAME.table-dada2_dn"$p_perc_identity".qza \
--m-metadata-file $METADATA_FILE_PATH \
--p-where "$p_where" \
--o-filtered-table $ANALYSIS_NAME."$metatag"table-dada2_dn"$p_perc_identity".qza || exit_on_error
$APPTAINER_COMMAND qiime feature-table summarize \
--i-table $ANALYSIS_NAME."$metatag"table-dada2_dn"$p_perc_identity".qza \
--o-visualization $ANALYSIS_NAME."$metatag"table-dada2_dn"$p_perc_identity".qzv \
--m-sample-metadata-file $METADATA_FILE_PATH || exit_on_error
$APPTAINER_COMMAND qiime feature-table filter-seqs \
--i-data $ANALYSIS_NAME.rep-seqs-dada2_dn"$p_perc_identity".qza \
--i-table $ANALYSIS_NAME."$metatag"table-dada2_dn"$p_perc_identity".qza \
--o-filtered-data $ANALYSIS_NAME."$metatag"rep-seqs-dada2_dn"$p_perc_identity".qza || exit_on_error
$APPTAINER_COMMAND qiime taxa barplot \
--i-table $ANALYSIS_NAME."$metatag"table-dada2_dn"$p_perc_identity".qza \
--i-taxonomy $ANALYSIS_NAME.taxo_dn"$p_perc_identity".qza \
--m-metadata-file $METADATA_FILE_PATH \
--o-visualization $ANALYSIS_NAME."$metatag"barplots_taxo_dn"$p_perc_identity".qzv || exit_on_error
fi
#if [ "$SKIP_FILTERING" == "true" ]
#then
# echo "Skip filtering option detected, you must skip this step"
# #cp -v $ANALYSIS_NAME.table-dada2_dn"$p_perc_identity".qza $ANALYSIS_NAME.filtered_table_dn"$p_perc_identity".qza
# #cp -v $ANALYSIS_NAME.rep-seqs-dada2_dn"$p_perc_identity".qza $ANALYSIS_NAME.filtered_rep-seqs-dada2_dn"$p_perc_identity".qza
# exit 0
#fi
taxa_filt=1
if [ ! $p_exclude ] && [ ! $p_include ]
then
echo "Both p_include and p_exclude are undefined, Taxa filtering will be skipped"
echo "table-dada2 and rep-seqs will copied as filtered_table for filename coherency"
cp -v $ANALYSIS_NAME."$metatag"table-dada2_dn"$p_perc_identity".qza $ANALYSIS_NAME.filtered_table_dn"$p_perc_identity".qza
cp -v $ANALYSIS_NAME."$metatag"rep-seqs-dada2_dn"$p_perc_identity".qza $ANALYSIS_NAME.filtered_rep-seqs-dada2_dn"$p_perc_identity".qza
taxa_filt=0
fi
if [ $taxa_filt -eq 1 ]
then
if [ $p_exclude ]
then
excl_param="--p-exclude $p_exclude"
fi
if [ $p_include ]
then
excl_param="--p-include $p_include"
fi
if [ $p_exclude ] && [ $p_include ]
then
excl_param="--p-include $p_include --p-exclude $p_exclude"
fi
echo "Applying Taxa filtering..."
echo "Taxa filtering inclusion parameter: $p_include"
echo "Taxa filtering exclusion parameter: $p_exclude"
$APPTAINER_COMMAND qiime taxa filter-table \
--i-table $ANALYSIS_NAME."$metatag"table-dada2_dn"$p_perc_identity".qza \
--i-taxonomy $ANALYSIS_NAME.taxo_dn"$p_perc_identity".qza \
$excl_param \
--p-mode $p_mode \
--o-filtered-table $ANALYSIS_NAME.filtered_table_dn"$p_perc_identity".qza --verbose || exit_on_error
$APPTAINER_COMMAND qiime feature-table summarize \
--i-table $ANALYSIS_NAME.filtered_table_dn"$p_perc_identity".qza \
--o-visualization $ANALYSIS_NAME.filtered_table_dn"$p_perc_identity".qzv --verbose \
--m-sample-metadata-file $METADATA_FILE_PATH
$APPTAINER_COMMAND qiime taxa filter-seqs \
--i-sequences $ANALYSIS_NAME."$metatag"rep-seqs-dada2_dn"$p_perc_identity".qza \
--i-taxonomy $ANALYSIS_NAME.taxo_dn"$p_perc_identity".qza \
$excl_param \
--p-mode $p_mode \
--o-filtered-sequences $ANALYSIS_NAME.filtered_rep-seqs-dada2_dn"$p_perc_identity".qza --verbose || exit_on_error
$APPTAINER_COMMAND qiime feature-table tabulate-seqs \
--i-data $ANALYSIS_NAME.filtered_rep-seqs-dada2_dn"$p_perc_identity".qza \
--o-visualization $ANALYSIS_NAME.filtered_rep-seqs-dada2_dn"$p_perc_identity".qzv --verbose
$APPTAINER_COMMAND qiime taxa barplot \
--i-table $ANALYSIS_NAME.filtered_table_dn"$p_perc_identity".qza \
--i-taxonomy $ANALYSIS_NAME.taxo_dn"$p_perc_identity".qza \
--m-metadata-file $METADATA_FILE_PATH \
--o-visualization $ANALYSIS_NAME.filtered_barplots_taxo_dn"$p_perc_identity".qzv --verbose || exit_on_error
fi
if [ "$GENERATE_PHYLOGENY" == "true" ]
then
echo "Generating phylogenetic trees"
$APPTAINER_COMMAND qiime phylogeny align-to-tree-mafft-fasttree \
--p-n-threads $NB_THREADS \
--i-sequences $ANALYSIS_NAME.filtered_rep-seqs-dada2_dn"$p_perc_identity".qza \
--o-alignment $ANALYSIS_NAME.filtered_aligned_rep-seqs-dada2_dn"$p_perc_identity".qza \
--o-masked-alignment $ANALYSIS_NAME.filtered_masked_aligned_rep-seqs-dada2_dn"$p_perc_identity".qza \
--o-tree $ANALYSIS_NAME.unrooted_tree.qza \
--o-rooted-tree $ANALYSIS_NAME.rooted_tree.qza
fi