Skip to content

Commit 93b1087

Browse files
committed
⬇️ removed dependency on GNU awk 4.1.0 (inplace ext)
1 parent d925774 commit 93b1087

File tree

2 files changed

+83
-41
lines changed

2 files changed

+83
-41
lines changed

SRFAligner

+42-21
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,30 @@ if [[ "$argp" = true ]] ; then
118118
-a $alignmentsout
119119

120120
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."
122125

123-
grep -A 1 --no-group-separator \
124-
-f <(grep -v \
126+
unalignedreads=$({ grep -v \
125127
-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
136145
fi
137146
else
138147
# pipeline of above commands
@@ -143,7 +152,7 @@ else
143152
mkfifo -m 600 $fastapipe
144153
trap '{ rm -f -- "$fastapipe"; }' EXIT
145154

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
147156
$graphaligner -x "vg" \
148157
-t $threads \
149158
-g $graph \
@@ -168,16 +177,28 @@ else
168177
-a $alignmentsout
169178

170179
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."
172184

173-
grep -A 1 --no-group-separator \
174-
-f <(grep -v \
185+
unalignedreads=$({ grep -v \
175186
-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
179201

180-
wait $(jobs -p)
181202
cat "$workingfolder/unaligned_reads_$$.gaf" >> $alignmentsout
182203
rm "$workingfolder/unaligned_reads_$$.gaf"
183204
fi

SRFChainer

+41-20
Original file line numberDiff line numberDiff line change
@@ -158,21 +158,30 @@ if [[ "$argp" = true ]] ; then
158158
-a $alignmentsout
159159

160160
if [[ "$argc" = true ]] ; then
161-
awk -i inplace "{if ($discardoption) {print}}" "$alignmentsout"
161+
echo -n "Filtering alignments with identity <= 90% or read coverage < 50%..."
162+
awk "{if ($discardoption) {print}}" "$alignmentsout" > "$workingfolder/filtered_alignments_$$.gaf"
163+
mv "$workingfolder/filtered_alignments_$$.gaf" "$alignmentsout"
164+
echo " done."
162165

163-
grep -A 1 --no-group-separator \
164-
-f <(grep -v \
166+
unalignedreads=$({ grep -v \
165167
-f <(cut -f1 $alignmentsout | uniq) \
166-
<(awk 'NR % 4 == 1' $reads | cut -d' ' -f1 | tr -d "@")) \
167-
<(awk 'NR % 4 == 1 || NR % 4 == 2' $reads | sed 's/^@/>/g' | cut -d' ' -f1) \
168-
> "$workingfolder/$(basename reads)_unaligned_reads.fasta"
169-
170-
$graphaligner -x "vg" \
171-
-t $threads \
172-
-g $graph \
173-
-f "$workingfolder/$(basename reads)_unaligned_reads.fasta" \
174-
-a "$workingfolder/$(basename reads)_unaligned_reads.gaf"
175-
cat "$workingfolder/$(basename reads)_unaligned_reads.gaf" >> $alignmentsout
168+
<(awk 'NR % 4 == 1' $reads | cut -d' ' -f1 | tr -d "@") || true; })
169+
unalignedreadscount=$(echo -n "$unalignedreads" | wc -l)
170+
if [[ "$unalignedreadscount" -gt "0" ]] ; then
171+
grep -A 1 --no-group-separator \
172+
-f <(echo "$unalignedreads") \
173+
<(awk 'NR % 4 == 1 || NR % 4 == 2' $reads | sed 's/^@/>/g' | cut -d' ' -f1) \
174+
> "$workingfolder/$(basename $reads)_unaligned_reads.fasta"
175+
176+
$graphaligner -x "vg" \
177+
-t $threads \
178+
-g $graph \
179+
-f "$workingfolder/$(basename $reads)_unaligned_reads.fasta" \
180+
-a "$workingfolder/$(basename $reads)_unaligned_reads.gaf"
181+
cat "$workingfolder/$(basename $reads)_unaligned_reads.gaf" >> $alignmentsout
182+
else
183+
echo "There are no unaligned reads to realign"
184+
fi
176185
fi
177186
else
178187
# pipeline of above commands
@@ -216,16 +225,28 @@ else
216225
-a $alignmentsout
217226

218227
if [[ "$argc" = true ]] ; then
219-
awk -i inplace "{if ($discardoption) {print}}" "$alignmentsout"
228+
echo -n "Filtering alignments with identity <= 90% or read coverage < 50%..."
229+
awk "{if ($discardoption) {print}}" "$alignmentsout" > "$workingfolder/filtered_alignments_$$.gaf"
230+
mv "$workingfolder/filtered_alignments_$$.gaf" "$alignmentsout"
231+
echo " done."
220232

221-
grep -A 1 --no-group-separator \
222-
-f <(grep -v \
233+
unalignedreads=$({ grep -v \
223234
-f <(cut -f1 $alignmentsout | uniq) \
224-
<(awk 'NR % 4 == 1' $reads | cut -d' ' -f1 | tr -d "@")) \
225-
<(awk 'NR % 4 == 1 || NR % 4 == 2' $reads | sed 's/^@/>/g' | cut -d' ' -f1) \
226-
> $fastapipe
235+
<(awk 'NR % 4 == 1' $reads | cut -d' ' -f1 | tr -d "@") || true; })
236+
unalignedreadscount=$(echo -n "$unalignedreads" | wc -l)
237+
if [[ "$unalignedreadscount" -gt "0" ]] ; then
238+
echo "There are the following unaligned reads:"
239+
echo "$unalignedreads"
240+
grep -A 1 --no-group-separator \
241+
-f <(echo "$unalignedreads") \
242+
<(awk 'NR % 4 == 1 || NR % 4 == 2' $reads | sed 's/^@/>/g' | cut -d' ' -f1) \
243+
> $fastapipe
244+
wait $(jobs -p)
245+
else
246+
echo "There are no unaligned reads to realign"
247+
set +eo pipefail ; { kill $(jobs -p) & } ; set -eo pipefail
248+
fi
227249

228-
wait $(jobs -p)
229250
cat "$workingfolder/unaligned_reads_$$.gaf" >> $alignmentsout
230251
rm "$workingfolder/unaligned_reads_$$.gaf"
231252
fi

0 commit comments

Comments
 (0)