-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add separate sh script that parallelizes svtyper by in chunks of 1000…
… lines.
- Loading branch information
Showing
2 changed files
with
80 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
set -euo pipefail | ||
|
||
export vcf=$1 | ||
export bams=$2 | ||
|
||
export LINES=250 | ||
|
||
svtpar() { | ||
set -euo pipefail | ||
subvcf=$1 | ||
lib=$TMPDIR/tmp.$mypid.$(echo $bams | md5sum | awk '{ print $1 }').lib | ||
svtyper -B $bams -i $subvcf -l $lib | ||
# vcf is a temporary file so clean it up. | ||
# but for the first time, it's and fd from the header so the rm will fail. | ||
set +e | ||
tail -1 $subvcf 2>/dev/null | awk '{ print "svtyped through:" $1":"$2 }' > /dev/stderr | ||
# NOTE: TODO put this back | ||
rm -f $subvcf >/dev/null 2>&1 | ||
} | ||
export -f svtpar | ||
|
||
genvcfs() { | ||
set -euo pipefail | ||
bams=$1 | ||
nth=0 | ||
tmpvcf=$TMPDIR/tmp.$$.$nth.vcf | ||
echo -e "$header" > $tmpvcf | ||
k=0 | ||
# run this once to force the calculation of the bam stats. | ||
# this avoids a race condition. | ||
svtpar <(echo -e "$header") | ||
while read -r line || [[ -n "$line" ]]; do | ||
k=$((k + 1)) | ||
echo -e "$line" >> $tmpvcf | ||
if [[ "$k" -eq "$LINES" ]]; then | ||
# echo the bam and the vcf so they can be sent to svtyper. | ||
echo "$tmpvcf" | ||
nth=$((nth + 1)) | ||
tmpvcf=$TMPDIR/tmp.$$.$nth.vcf | ||
echo -e "$header" > $tmpvcf | ||
k=0; | ||
fi | ||
done < "$vcf" | ||
echo $tmpvcf | ||
} | ||
|
||
vcfsort() { | ||
awk 'BEGIN{x=0;} $0 ~/^#/{ if(x==0) {print;} if($1 == "#CHROM"){x=1}; next;} {x=1; print $0 | "LC_ALL=C sort --buffer-size 2G -k1,1 -k2,2n" }' | ||
} | ||
|
||
|
||
export -f genvcfs | ||
|
||
if [[ -z ${TMPDIR+x} ]]; then | ||
export TMPDIR=/tmp/ | ||
fi | ||
export mypid=$$ | ||
|
||
cleanup() { | ||
#rm -f $TMPDIR/tmp.$mypid.*.vcf | ||
rm -f $TMPDIR/tmp.$mypid.*.lib | ||
} | ||
|
||
trap cleanup EXIT | ||
|
||
|
||
psvtyper() { | ||
set -euo pipefail | ||
export header=$(head -2000 $vcf | grep ^#) | ||
genvcfs $bams | gargs -p $THREADS "svtpar {}" | vcfsort | ||
} | ||
export -f psvtyper | ||
psvtyper |