-
Notifications
You must be signed in to change notification settings - Fork 0
/
q2b_unoise3.batch
executable file
·231 lines (188 loc) · 6.17 KB
/
q2b_unoise3.batch
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/bin/bash
#This batch aims to generate the feature-table and representative sequences through unoise3 algorithm in usearch software.
set -euxo pipefail
cd $(dirname `readlink -f $0`)
work_dir=$PWD
prefix=`cat configuration.txt | grep "^prefix" | cut -d "=" -f 2`
usearch_command=`cat configuration.txt | grep "^usearch_command" | cut -d "=" -f 2`
unoise3_minsize=`cat configuration.txt | grep "^unoise3_minsize" | cut -d "=" -f 2`
fastq_maxee=`cat configuration.txt | grep "^fastq_maxee" | cut -d "=" -f 2`
manifest=${prefix}_manifest
Usearch_dir=${work_dir}/${prefix}_USEARCH
input_file=${work_dir}/${prefix}_merged
output_file=${Usearch_dir}/${prefix}_filtered
filtered_output_info=${Usearch_dir}/${prefix}_filtered_fastx_info
echo "#============ This script is going to output these files ..."
echo
echo ${prefix}_un3_tab.qza
echo ${prefix}_un3_rep.qza
echo ${prefix}_un3_tab.qzv
echo ${prefix}_un3_rep.qzv
echo
echo "#============ running batch ..."
#################################################################filter
cd ${work_dir}
if [ ! -d ${output_file} ]
then
mkdir ${output_file}
else
rm -r ${output_file}
mkdir ${output_file}
fi
for seq in `ls ${input_file}`
do
name=`echo ${seq} | cut -f1 -d"." `
${usearch_command} -fastq_filter ${input_file}/${seq} -fastq_maxee ${fastq_maxee} -fastaout ${output_file}/${name}_filtered.fasta
done
cd ${work_dir}
if [ ! -d ${filtered_output_info} ]
then
mkdir ${filtered_output_info}
else
rm -r ${filtered_output_info}
mkdir ${filtered_output_info}
fi
for seq in `ls ${output_file}`
do
name=`echo ${seq} | cut -f1 -d"." `
${usearch_command} -fastx_info ${output_file}/${seq} -output ${filtered_output_info}/${name}_info.log
done
################################################################pooling
input_file=${Usearch_dir}/${prefix}_filtered
output_file=${Usearch_dir}/${prefix}_pooling_data
cd ${work_dir}
if [ ! -d ${output_file} ]
then
mkdir ${output_file}
else
rm -r ${output_file}
mkdir ${output_file}
fi
cat ${input_file}/* > ${output_file}/pooling.fasta
${usearch_command} -fastx_info ${output_file}/pooling.fasta -output ${output_file}/pooling_info.log
#################################################################unique
input_file=${Usearch_dir}/${prefix}_pooling_data
output_file=${Usearch_dir}/${prefix}_unique
cd ${work_dir}
if [ ! -d ${output_file} ]
then
mkdir ${output_file}
else
rm -r ${output_file}
mkdir ${output_file}
fi
nohup ${usearch_command} -fastx_uniques ${input_file}/pooling.fasta \
-fastaout ${output_file}/unique.fasta \
-sizeout -relabel Uniq > ${output_file}/unique.log
################################################################unoise3
input_file=${Usearch_dir}/${prefix}_unique
output_file=${Usearch_dir}/${prefix}_unoise3
cd ${work_dir}
if [ ! -d ${output_file} ]
then
mkdir ${output_file}
else
rm -r ${output_file}
mkdir ${output_file}
fi
nohup ${usearch_command} -unoise3 ${input_file}/unique.fasta \
-zotus ${output_file}/zotus.fasta -tabbedout ${output_file}/zotus.txt \
-minsize ${unoise3_minsize} > ${output_file}/unoise3.log
################################################################relabel
input_file=${Usearch_dir}/${prefix}_filtered
output_file=${Usearch_dir}/${prefix}_filter_relabel
cd ${work_dir}
if [ ! -d ${output_file} ]
then
mkdir ${output_file}
else
rm -r ${output_file}
mkdir ${output_file}
fi
for seq in `ls ${work_dir}/${prefix}_merged`
do
name=`echo ${seq} | cut -f1 -d"."`
sed "s/>.*/>${name}/g" ${input_file}/${name}* > ${output_file}/${name}_filtered_relabel.fasta
done
############################################################generateTab
input_file1=${Usearch_dir}/${prefix}_filter_relabel
input_file3=${Usearch_dir}/${prefix}_unoise3
output_file2=${Usearch_dir}/${prefix}_otutab_unoise3
cd ${work_dir}
if [ ! -d ${output_file2} ]
then
mkdir ${output_file2}
else
rm -r ${output_file2}
mkdir ${output_file2}
fi
for seq in `ls ${work_dir}/${prefix}_merged`
do
name=`echo ${seq} | cut -f1 -d"."`
nohup ${usearch_command} \
-otutab ${input_file1}/${name}* \
-zotus ${input_file3}/zotus.fasta \
-otutabout ${output_file2}/${name}_ztab.txt \
-mapout ${output_file2}/${name}_zmap.txt \
-notmatched ${output_file2}/${name}_zunmapped.fasta >> \
${output_file2}/otutab_unoise3.log
done
############################################################otutabMerge
work_dir1=${Usearch_dir}/${prefix}_otutab_unoise3
output_file1=${work_dir1}/merge_tab.txt
#Creating a core function to process the merging
function merge_process(){
nohup head merge_tab.txt && rm merge_tab.txt > /dev/null
in=`ls | grep tab.txt | sed ':a;N;$!ba; s/\n/,/g'`
${usearch_command} -otutab_merge ${in} -output merge_tab.txt
}
#Start merging
cd ${work_dir1}
merge_process
#########################################################usearchToQiime
input_file1=${Usearch_dir}/${prefix}_otutab_unoise3
output_file1=${Usearch_dir}/${prefix}_unoise3_to_qiime
cd ${Usearch_dir}
if [ ! -d ${output_file1} ]
then
mkdir ${output_file1}
else
rm -r ${output_file1}
mkdir ${output_file1}
fi
biom convert -i ${input_file1}/merge_tab.txt \
-o ${output_file1}/merge_tab_v100.biom \
--table-type="OTU table" --to-json
qiime tools import \
--input-path ${output_file1}/merge_tab_v100.biom \
--type 'FeatureTable[Frequency]' \
--input-format BIOMV100Format \
--output-path ${output_file1}/${prefix}_un3_tab.qza
qiime tools import \
--input-path ${Usearch_dir}/${prefix}_unoise3/zotus.fasta \
--output-path ${output_file1}/${prefix}_un3_rep.qza \
--type 'FeatureData[Sequence]'
###visualization
cd ${work_dir}
qiime feature-table summarize \
--m-sample-metadata-file ${manifest}.tsv \
--i-table ${output_file1}/${prefix}_un3_tab.qza \
--o-visualization ${output_file1}/${prefix}_un3_tab.qzv
qiime feature-table tabulate-seqs \
--i-data ${output_file1}/${prefix}_un3_rep.qza \
--o-visualization ${output_file1}/${prefix}_un3_rep.qzv
if [ -f ${prefix}_un3_tab.qza -o -f ${prefix}_un3_tab.qzv ]
then
rm -f ./${prefix}_un3_tab.qza
cp ${output_file1}/${prefix}_un3_tab.qz* .
else
cp ${output_file1}/${prefix}_un3_tab.qz* .
fi
if [ -f ${prefix}_un3_rep.qza -o -f ${prefix}_un3_rep.qzv ]
then
rm -f ./${prefix}_un3_rep.qza
cp ${output_file1}/${prefix}_un3_rep.qz* .
else
cp ${output_file1}/${prefix}_un3_rep.qz* .
fi
exit 0