Filter bam, EXCLUDING specific tagged reads
1
1
Entering edit mode
19 months ago
dayne.filer ▴ 10

I am trying to use samtools view to filter a bam file. I would ideally like to take a sorted bam with the DT flags set by picard markduplicates (e.g. DT:Z:SQ for optical/sequencing and DT:Z:LB for PCR/library) and exclude reads with either DT:SQ only OR DT:SQ & DT:LB. As far as I can tell, samtools only supports filtering by including specific tag:value pairs with the -d parameter. Is there any workaround here? Or is the only option to write another intermediate file?

samtools • 672 views
ADD COMMENT
2
Entering edit mode
19 months ago

using samjdk http://lindenb.github.io/jvarkit/SamJdk.html

(not tested)

 java -jar dist/samjdk.jar -e 'Object att = record.getAttribute("DT"); return att==null || !(att.equals("SQ") || att.equals("LB"));' input.bam
ADD COMMENT
0
Entering edit mode

This is great -- thanks!!!!!! One quick question, where am I going wrong here?

 java -jar samjdk.jar -e 'Object att = record.getAttribute("DT"); return att.equals("SQ");' input.bam

I get the following error:

[SEVERE][SamJdk]null
java.lang.NullPointerException
    at SamJdkCustom1168468679.apply(SamJdkCustom1168468679.java:14)
    at com.github.lindenb.jvarkit.tools.samjs.SamJdk.doWork(SamJdk.java:722)
    at com.github.lindenb.jvarkit.util.jcommander.Launcher.instanceMain(Launcher.java:777)
    at com.github.lindenb.jvarkit.util.jcommander.Launcher.instanceMainWithExit(Launcher.java:940)
    at com.github.lindenb.jvarkit.tools.samjs.SamJdk.main(SamJdk.java:806)
[INFO][Launcher]samjdk Exited with failure (-1)
ADD REPLY
1
Entering edit mode

you have some reads that don't have the attribute DT. record.getAttribute("DT") returns a null value...

ADD REPLY

Login before adding your answer.

Traffic: 3139 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