-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path900_q2_summary.sh
executable file
·154 lines (117 loc) · 4.71 KB
/
900_q2_summary.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
#!/usr/bin/env bash
# 03.02.2021 - Paul Czechowski - [email protected]
# ========================================================
# set -x
set -eu
set -o pipefail
# Adjust base paths
# -----------------
if [[ "$HOSTNAME" != "Pauls-MacBook-Pro.local" ]] && [[ "$HOSTNAME" != "Mac-mini-3" ]]; then
bold=$(tput bold)
normal=$(tput sgr0)
printf "${bold}$(date):${normal} Execution on remote...\n"
trpth="/workdir/pc683/OU_eDNA"
cores="$(nproc --all)"
elif [[ "$HOSTNAME" == "Pauls-MacBook-Pro.local" ]] || [[ "$HOSTNAME" == "Mac-mini-3" ]]; then
bold=$(tput bold)
normal=$(tput sgr0)
printf "${bold}$(date):${normal} Execution on local...\n"
trpth="/Users/paul/Documents/OU_eDNA"
cores="2"
fi
# define relative input locations - Qiime files
# --------------------------------------------------------
inpth_map='201126_preprocessing/metadata/850_prep_q2_predictor-tab__metadata.tsv'
inpth_tax='201126_preprocessing/qiime/800_12S_single_end_ee3-seq_q2taxtable.qza'
# define relative input locations - sequence files
# -----------------------------------------------------------
# (https://stackoverflow.com/questions/23356779/how-can-i-store-the-find-command-results-as-an-array-in-bash)
# Fill sequence array using find
inpth_seq_unsorted=()
while IFS= read -r -d $'\0'; do
inpth_seq_unsorted+=("$REPLY")
done < <(find "$trpth/201126_preprocessing/qiime" \( -name '600_12S_single_end_ee3-seq.qza' \) -print0)
# for debugging - print unsorted sequences
# printf '%s\n'
# printf '%s\n' "${inpth_seq_unsorted[@]}"
# Sort array
IFS=$'\n' inpth_seq=($(sort <<<"${inpth_seq_unsorted[*]}"))
unset IFS
# for debugging - print sorted sequences - ok!
# printf '%s\n'
# printf '%s\n' "${inpth_seq[@]}"
# define relative input locations - feature tables
# ------------------------------------------------
# Fill table array using find
inpth_tab_unsorted=()
while IFS= read -r -d $'\0'; do
inpth_tab_unsorted+=("$REPLY")
done < <(find "$trpth/201126_preprocessing/qiime" \( -name '600_12S_single_end_ee3-tab.qza' \) -print0)
# for debugging - print unsorted tables
# printf '%s\n'
# printf '%s\n' "${inpth_tab_unsorted[@]}"
# Sort array
IFS=$'\n' inpth_tab=($(sort <<<"${inpth_tab_unsorted[*]}"))
unset IFS
# for debugging - print sorted tables - ok!
# printf '%s\n'
# printf '%s\n' "${inpth_tab[@]}"
# define relative output locations - feature tables
# otpth_tabv='Zenodo/Qiime/080_18S_denoised_tab_vis.qzv'
# otpth_seqv='Zenodo/Qiime/080_18S_denoised_seq_vis.qzv'
# otpth_bplv='Zenodo/Qiime/080_18S_denoised_tax_vis.qzv'
# loop over filtering parameters, and corresponding file name names additions
for i in "${!inpth_seq[@]}"; do
# check if files can be mathced otherwise abort script because it would do more harm then good
seqtest="$(basename "${inpth_seq[$i]//-seq/}")"
tabtest="$(basename "${inpth_tab[$i]//-tab/}")"
# for debugging
# echo "$seqtest"
# echo "$tabtest"
if [ "$seqtest" == "$tabtest" ]; then
echo "Sequence- and table files have been matched, continuing..."
# get input sequence file name - for debugging
# echo "${inpth_seq[$i]}"
# get input table file name - for debugging
# echo "${inpth_tab[$i]}"
directory="$(dirname "$inpth_seq[$i]")"
seq_file_tmp="$(basename "${inpth_seq[$i]%.*}")"
seq_file_name="${seq_file_tmp:4}"
tab_file_tmp="$(basename "${inpth_tab[$i]%.*}")"
tab_file_name="${tab_file_tmp:4}"
plot_file_temp="$(basename "${inpth_seq[$i]//_seq/}")"
plot_file_temp="${plot_file_temp:4}"
plot_file_name="${plot_file_temp%.*}"
extension=".qzv"
# check string construction - for debugging
# echo "$seq_file_name"
# echo "$tab_file_name"
# echo "$plot_file_name"
seq_file_vis_path="$directory/900_$seq_file_name""$extension"
tab_file_vis_path="$directory/900_$tab_file_name""$extension"
plot_file_vis_path="$directory/900_$plot_file_name"_barplot"$extension"
# check string construction - for debugging
# echo "$seq_file_vis_path"
# echo "$tab_file_vis_path"
# echo "$plot_file_vis_path"
# Qiime calls
qiime feature-table tabulate-seqs \
--i-data "${inpth_seq[$i]}" \
--o-visualization "$seq_file_vis_path" \
--verbose
qiime feature-table summarize \
--m-sample-metadata-file "$trpth"/"$inpth_map" \
--i-table "${inpth_tab[$i]}" \
--o-visualization "$tab_file_vis_path" \
--verbose
qiime taxa barplot \
--m-metadata-file "$trpth"/"$inpth_map" \
--i-taxonomy "$trpth"/"$inpth_tax" \
--i-table "${inpth_tab[$i]}" \
--o-visualization "$plot_file_vis_path" \
--verbose
else
echo "Sequence- and table files can't be matched, aborting."
exit
fi
done