Using Gatk, Removing Read Contigs On Bam Level
2
1
Entering edit mode
13.2 years ago
Mdeng ▴ 530

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

gatk contigs snp • 7.4k views
ADD COMMENT
0
Entering edit mode

What if you change the reference sequence instead of the alignment?

ADD REPLY
0
Entering edit mode

This would work to, but I am looking for nice and fast why, Istvan Albert posted below.

ADD REPLY
3
Entering edit mode
13.2 years ago

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)

ADD COMMENT
0
Entering edit mode

I guess this does not work because the sequence dictionary is not changed. I think GATK should adopt the faidx strategy.

ADD REPLY
0
Entering edit mode

@lh3 Couldn't this be solved by recreating the SAM header using Picards AddOrReplaceReadGroups?

ADD REPLY
0
Entering edit mode

Do you mean ReplaceSamHeader?

ADD REPLY
1
Entering edit mode
13.2 years ago
Russh ★ 1.2k

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

ADD COMMENT

Login before adding your answer.

Traffic: 2497 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6