This is a test version of Biostars. For the public version, visit https://www.biostars.org.
BWA | SAMtools | GATK debugging help

Hello! I am working on a script for a VCF pipeline.

I currently receive the following error in my bwa step....

line 22: 3354610 Killed bwa mem bwaParts my_lovely_file_trimmed.fq > $bwa_sam

...This is a memory issue that I need to speak to my supervisor about, nonetheless because of this, the SAMtools and GATK commands downstream don't work.

Even though I am dealing with this error early in the pipeline I still want to know if the samtools and GATK syntax is correct, and will work once the memory issue is resolved.

Here is the code

samtools sort $bwa_sam -o $sam_sam
gatk AddOrReplaceReadGroups -I sorted_sam -O GATK_bam -RGLB lib1 --RGPL illumina --RGPU unit1 --RGSM file

If you're well seasoned- like a steak at Gordan Ramsey's restaurants- at these commands, please take a peak for my sanity.

All the best, Gilgy

P.S bwaParts are the amb,ann,bwt,pac,sa files from the bwa index command.

alignment mapping vcf

2 answers

you should never use AddOrReplaceReadGroups when using bwa, and you avoid to use SAM but BAM. An invocation of bwa could be:

bwa mem  -t <cpus> -R '@RG\tID:<sample>\tSM:<sample>\tPL:ILLUMINA' reference.fa f1.fq.gz f2.fq.gz |\
samtools sort  -m '10G' --threads <cpus2> -o out.bam -O BAM -T tmp -

Hey Pierre,

How come using AddOrReplaceReadGroups with BWA is discouraged? Also, thank you for the recommendation on using BAM, I will try with .bam files.

edit: Seem to be getting an error that makes no sense.

bwa mem bwaRef my_lovely_file_trimmed.fq > $bwa_bam

returns a 'killed' or 'segmentation fault - core dumped', even at 32 threads & 128G

Meanwhile

bwa mem bwaRef.fa my_lovely_file_trimmed.fq > $bwa_bam 

returns an indexing error.

How come using AddOrReplaceReadGroups with BWA is discouraged?

because read groups should be already set at the beginning with the option '-R' of bwa mem. Using AddOrReplaceReadGroups is an extra time-consumming step.

Hey, if anyones wallowing in a similar error, here are some things that helped.

For the bwa mem command itself, use Pierre's lovely slice of code removes the error but simply hides the BWA software crash inside your file.

Our solution was simply to delete the reference and re-index it.

Please accept the answer so the question is marked solved on the website. To do that, click on the green check mark on the left side of the answer.

Turns out Pierre that piping removes the error but results in an unusable file! There is no answer for this BWA bug yet, although I can supply my code if you would like to replicate.

Log in to answer this question.