-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrimmer.sh
More file actions
executable file
·153 lines (133 loc) · 4.94 KB
/
trimmer.sh
File metadata and controls
executable file
·153 lines (133 loc) · 4.94 KB
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
#!/bin/bash
# ==============================================================================
# The BBDuk wrapper called by trimFASTQ
# ==============================================================================
# --- Source common settings and functions -------------------------------------
# These variables are exported from the trimFASTQ wrapper:
# xpath paired_reads dual_files target_dir r1_suffix r2_suffix se_suffix counter
# bbpath nor remove_originals
#source "${xpath}"/workers/x.funx.sh
# --- Main program -------------------------------------------------------------
if $paired_reads && $dual_files; then
# Loop over FASTQ pairs
i=1 # Just another counter
for r1_infile in "${target_dir}"/*"$r1_suffix"
do
r2_infile="$(echo "$r1_infile" | sed "s/$r1_suffix/$r2_suffix/")"
printf "%b\n" "\n============" \
" Cycle ${i}/${counter}" \
"============" \
"Targeting: ${r1_infile}" \
" ${r2_infile}" \
"\nStart trimming through BBDuk...\n"
prefix="$(basename "$r1_infile" "$r1_suffix")"
# Paths with spaces need to be hard-escaped at this very level to be
# correctly parsed when passed as arguments to BBDuk!
esc_r1_infile="${r1_infile//" "/'\ '}"
esc_r2_infile="${r2_infile//" "/'\ '}"
esc_target_dir="${target_dir//" "/'\ '}"
# Run BBDuk
# NOTE: all BBTools write status information to stderr, not stdout !!!
# also try to add this for Illumina: ftm=5 \
${bbpath}/bbduk.sh \
reads=$nor \
in1=$esc_r1_infile \
in2=$esc_r2_infile \
ref=${bbpath}/resources/adapters.fa \
stats=${esc_target_dir}/Trim_stats/${prefix}_STATS.tsv \
ktrim=r \
k=23 \
mink=11 \
hdist=1 \
tpe \
tbo \
out1=$(echo $esc_r1_infile | sed -E "s/_?$r1_suffix/_TRIM_$r1_suffix/") \
out2=$(echo $esc_r2_infile | sed -E "s/_?$r2_suffix/_TRIM_$r2_suffix/") \
qtrim=rl \
trimq=10 \
minlen=25
printf "\nDONE!\n"
if $remove_originals; then
rm "$r1_infile" "$r2_infile"
fi
((i++))
done
elif ! $paired_reads; then
# Loop over FASTQ files
i=1 # Just another counter
for infile in "${target_dir}"/*"$se_suffix"
do
printf "%b\n" "\n============" \
" Cycle ${i}/${counter}" \
"============" \
"Targeting: ${infile}" \
"\nStart trimming through BBDuk...\n"
prefix="$(basename "$infile" "$se_suffix")"
# Paths with spaces need to be hard-escaped at this very level to be
# correctly parsed when passed as arguments to BBDuk!
esc_infile="${infile//" "/'\ '}"
esc_target_dir="${target_dir//" "/'\ '}"
# Run BBDuk
# NOTE: all BBTools write status information to stderr, not stdout !!!
# also try to add this for Illumina: ftm=5 \
"${bbpath}"/bbduk.sh \
reads=$nor \
in=$esc_infile \
ref=${bbpath}/resources/adapters.fa \
stats=${esc_target_dir}/Trim_stats/${prefix}_STATS.tsv \
ktrim=r \
k=23 \
mink=11 \
hdist=1 \
interleaved=f \
out=$(echo $esc_infile | sed -E "s/_?$se_suffix/_TRIM$se_suffix/") \
qtrim=rl \
trimq=10 \
minlen=25
printf "\nDONE!\n"
if $remove_originals; then
rm "$infile"
fi
((i++))
done
elif ! $dual_files; then
# Loop over FASTQ files
i=1 # Just another counter
for infile in "${target_dir}"/*"$se_suffix"
do
printf "%b\n" "\n============" \
" Cycle ${i}/${counter}" \
"============" \
"Targeting: ${infile}" \
"\nStart trimming through BBDuk...\n"
prefix="$(basename "$infile" "$se_suffix")"
# Paths with spaces need to be hard-escaped at this very level to be
# correctly parsed when passed as arguments to BBDuk!
esc_infile="${infile//" "/'\ '}"
esc_target_dir="${target_dir//" "/'\ '}"
# Run BBDuk
# NOTE: all BBTools write status information to stderr, not stdout !!!
# also try to add this for Illumina: ftm=5 \
${bbpath}/bbduk.sh \
reads=$nor \
in=$esc_infile \
ref=${bbpath}/resources/adapters.fa \
stats=${esc_target_dir}/Trim_stats/${prefix}_STATS.tsv \
ktrim=r \
k=23 \
mink=11 \
hdist=1 \
interleaved=t \
tpe \
tbo \
out=$(echo $esc_infile | sed -E "s/_?$se_suffix/_TRIM$se_suffix/") \
qtrim=rl \
trimq=10 \
minlen=25
printf "\nDONE!\n"
if $remove_originals; then
rm "$infile"
fi
((i++))
done
fi