I guess this does not work because the sequence dictionary is not changed. I think GATK should adopt the faidx strategy.
Hey everyone,
ATM I am working with GATK for the first time and a get an error, wich everybody knows:
##### ERROR MESSAGE: Input files reads and reference have incompatible contigs: Order of contigs differences, which is unsafe.
##### ERROR reads contigs = [chr1, chr2, ..., chrUn_gl000226, chr18_gl000207_random]
##### ERROR reference contigs = [chr1, chr2, ..., chrY, chrM]
Is there a way to remove the chr18_gl000207_random on the BAM level, I don't wanna go back to SAM level and kick them out. Because if already done some postprocessing now.
With best,
Mario
2 answers
You could list all the valid chromosomes as a query like so:
samtools view -b old.bam chr1 chr2 chr3 > newbam
(old.bam file needs to be sorted and indexed)
I don't quite follow why you don't want to go back to SAM level. Surely making a temporary SAM, grepping that, and converting to BAM is the easiest way to do this, isn't it?
The alternative, is to use picard's ReorderSam tool, which, given that the offending contigs are absent from your reference, will drop any reads that are mapped to those contigs
Log in to answer this question.
What if you change the reference sequence instead of the alignment?
This would work to, but I am looking for nice and fast why, Istvan Albert posted below.