@@ -118,21 +118,30 @@ if [[ "$argp" = true ]] ; then
118
118
-a $alignmentsout
119
119
120
120
if [[ " $argc " = true ]] ; then
121
- awk -i inplace " {if ($discardoption ) {print}}" " $alignmentsout "
121
+ echo -n " Filtering alignments with identity <= 90% or read coverage < 50%..."
122
+ awk " {if ($discardoption ) {print}}" " $alignmentsout " > " $workingfolder /filtered_alignments_$$ .gaf"
123
+ mv " $workingfolder /filtered_alignments_$$ .gaf" " $alignmentsout "
124
+ echo " done."
122
125
123
- grep -A 1 --no-group-separator \
124
- -f <( grep -v \
126
+ unalignedreads=$( { grep -v \
125
127
-f <( cut -f1 $alignmentsout | uniq) \
126
- <( awk ' NR % 4 == 1' $reads | cut -d' ' -f1 | tr -d " @" ) ) \
127
- <( awk ' NR % 4 == 1 || NR % 4 == 2' $reads | sed ' s/^@/>/g' | cut -d' ' -f1) \
128
- > " $workingfolder /$( basename reads) _unaligned_reads.fasta"
129
-
130
- $graphaligner -x " vg" \
131
- -t $threads \
132
- -g $graph \
133
- -f " $workingfolder /$( basename reads) _unaligned_reads.fasta" \
134
- -a " $workingfolder /$( basename reads) _unaligned_reads.gaf"
135
- cat " $workingfolder /$( basename reads) _unaligned_reads.gaf" >> $alignmentsout
128
+ <( awk ' NR % 4 == 1' $reads | cut -d' ' -f1 | tr -d " @" ) || true ; })
129
+ unalignedreadscount=$( echo -n " $unalignedreads " | wc -l)
130
+ if [[ " $unalignedreadscount " -gt " 0" ]] ; then
131
+ grep -A 1 --no-group-separator \
132
+ -f <( echo " $unalignedreads " ) \
133
+ <( awk ' NR % 4 == 1 || NR % 4 == 2' $reads | sed ' s/^@/>/g' | cut -d' ' -f1) \
134
+ > " $workingfolder /$( basename $reads ) _unaligned_reads.fasta"
135
+
136
+ $graphaligner -x " vg" \
137
+ -t $threads \
138
+ -g $graph \
139
+ -f " $workingfolder /$( basename $reads ) _unaligned_reads.fasta" \
140
+ -a " $workingfolder /$( basename $reads ) _unaligned_reads.gaf"
141
+ cat " $workingfolder /$( basename $reads ) _unaligned_reads.gaf" >> $alignmentsout
142
+ else
143
+ echo " There are no unaligned reads to realign"
144
+ fi
136
145
fi
137
146
else
138
147
# pipeline of above commands
143
152
mkfifo -m 600 $fastapipe
144
153
trap ' { rm -f -- "$fastapipe"; }' EXIT
145
154
146
- # TODO find a way to not store on disk the unaligned alignments and directly append them
155
+ # TODO find a way to not store as a separate file the unaligned alignments and directly append them
147
156
$graphaligner -x " vg" \
148
157
-t $threads \
149
158
-g $graph \
@@ -168,16 +177,28 @@ else
168
177
-a $alignmentsout
169
178
170
179
if [[ " $argc " = true ]] ; then
171
- awk -i inplace " {if ($discardoption ) {print}}" " $alignmentsout "
180
+ echo -n " Filtering alignments with identity <= 90% or read coverage < 50%..."
181
+ awk " {if ($discardoption ) {print}}" " $alignmentsout " > " $workingfolder /filtered_alignments_$$ .gaf"
182
+ mv " $workingfolder /filtered_alignments_$$ .gaf" " $alignmentsout "
183
+ echo " done."
172
184
173
- grep -A 1 --no-group-separator \
174
- -f <( grep -v \
185
+ unalignedreads=$( { grep -v \
175
186
-f <( cut -f1 $alignmentsout | uniq) \
176
- <( awk ' NR % 4 == 1' $reads | cut -d' ' -f1 | tr -d " @" ) ) \
177
- <( awk ' NR % 4 == 1 || NR % 4 == 2' $reads | sed ' s/^@/>/g' | cut -d' ' -f1) \
178
- > $fastapipe
187
+ <( awk ' NR % 4 == 1' $reads | cut -d' ' -f1 | tr -d " @" ) || true ; })
188
+ unalignedreadscount=$( echo -n " $unalignedreads " | wc -l)
189
+ if [[ " $unalignedreadscount " -gt " 0" ]] ; then
190
+ echo " There are the following unaligned reads:"
191
+ echo " $unalignedreads "
192
+ grep -A 1 --no-group-separator \
193
+ -f <( echo " $unalignedreads " ) \
194
+ <( awk ' NR % 4 == 1 || NR % 4 == 2' $reads | sed ' s/^@/>/g' | cut -d' ' -f1) \
195
+ > $fastapipe
196
+ wait $( jobs -p)
197
+ else
198
+ echo " There are no unaligned reads to realign"
199
+ set +eo pipefail ; { kill $( jobs -p) & } ; set -eo pipefail
200
+ fi
179
201
180
- wait $( jobs -p)
181
202
cat " $workingfolder /unaligned_reads_$$ .gaf" >> $alignmentsout
182
203
rm " $workingfolder /unaligned_reads_$$ .gaf"
183
204
fi
0 commit comments