I have a bam file that I want to run through GATK's SplitNCigarReads tool. Because of the way the bam file was generated, the program will often fail, with an error message stating:
##### ERROR MESSAGE: Bad input: Cannot split this read (might be an empty section between Ns, for example 1N1D1N): ABCDEFG
My question is: how do I write a bash script to:
Start GATK on the input bam file.
When (and if) the error message arises, take the bad read (e.g., ABCDEFG) and use samtools to remove it,
samtools view -h input.bam | grep -v ABCDEFG | samtools view -bS -o intermediate1.bam
Index the new bam file
Run the same GATK command as #1, but with the newly generated bam file
Keep performing steps 1-4 until the GATK tool runs to completion
I realize this may be quite complicated and/or involved, so I don't expect someone to write the entire script for me. Are there any online resources dedicated to writing a script like this?
P.S. This is my first StackExchange question, please let me know if I did anything incorrectly or inefficiently.