Skip to content

Commit

Permalink
Workaround for HTSJDK removing additional ALT headers (#553)
Browse files Browse the repository at this point in the history
* Workaround for HTSJDK removing additional ALT headers

* Only reinsert headers if there are any
  • Loading branch information
bartcharbon authored Jan 18, 2024
1 parent 463c019 commit 41f060b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
20 changes: 20 additions & 0 deletions modules/vcf/templates/classify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,28 @@ index () {
${CMD_BCFTOOLS} index --stats "!{vcfOut}" > "!{vcfOutStats}"
}


#Workaround for https://github.com/samtools/htsjdk/issues/500https://github.com/samtools/htsjdk/issues/500
store_alt(){
#store ALT headers
zcat "!{vcf}" | sed --quiet --expression='/^##ALT/p' > header.tmp
}

insert_alt(){
if [ -s header.tmp ]; then
#remove remaining ALT header (since htsjdk stores in a map, a single ALT remains)
zcat "!{vcfOut}" | sed '/^##ALT/d' > "!{vcfOut}".tmp
#re-insert the ALT headers
f1=$(<header.tmp)
awk -vf1="$f1" '/^#CHROM/{print f1;print;next}1' "!{vcfOut}".tmp | ${CMD_BGZIP} -c > "!{vcfOut}"
#rm header.tmp
fi
}

main () {
store_alt
classify
insert_alt
index
}

Expand Down
20 changes: 20 additions & 0 deletions modules/vcf/templates/classify_samples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,28 @@ index () {
${CMD_BCFTOOLS} index --stats "!{vcfOut}" > "!{vcfOutStats}"
}


#Workaround for https://github.com/samtools/htsjdk/issues/500https://github.com/samtools/htsjdk/issues/500
store_alt(){
#store ALT headers
zcat "!{vcf}" | sed --quiet --expression='/^##ALT/p' > header.tmp
}

insert_alt(){
if [ -s header.tmp ]; then
#remove remaining ALT header (since htsjdk stores in a map, a single ALT remains)
zcat "!{vcfOut}" | sed '/^##ALT/d' > "!{vcfOut}".tmp
#re-insert the ALT headers
f1=$(<header.tmp)
awk -vf1="$f1" '/^#CHROM/{print f1;print;next}1' "!{vcfOut}".tmp | ${CMD_BGZIP} -c > "!{vcfOut}"
#rm header.tmp
fi
}

main() {
store_alt
classify_samples
insert_alt
index
}

Expand Down
19 changes: 19 additions & 0 deletions modules/vcf/templates/inheritance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,28 @@ index () {
${CMD_BCFTOOLS} index --stats "!{vcfOut}" > "!{vcfOutStats}"
}

#Workaround for https://github.com/samtools/htsjdk/issues/500https://github.com/samtools/htsjdk/issues/500
store_alt(){
#store ALT headers
zcat "!{vcf}" | sed --quiet --expression='/^##ALT/p' > header.tmp
}

insert_alt(){
if [ -s header.tmp ]; then
#remove remaining ALT header (since htsjdk stores in a map, a single ALT remains)
zcat "!{vcfOut}" | sed '/^##ALT/d' > "!{vcfOut}".tmp
#re-insert the ALT headers
f1=$(<header.tmp)
awk -vf1="$f1" '/^#CHROM/{print f1;print;next}1' "!{vcfOut}".tmp | ${CMD_BGZIP} -c > "!{vcfOut}"
#rm header.tmp
fi
}

main() {
create_ped
store_alt
inheritance
insert_alt
index
}

Expand Down

0 comments on commit 41f060b

Please sign in to comment.