Samtools view -f "OR" operator possible?
3
1
Entering edit mode
4.8 years ago

Quick question:

Is it possible to do a samtools view -f XXX using a OR operator?

Say if I wanted to get all reads that were unmapped (4) or supplementary alignments (2048).

Is this possible? Because doing a 2052 is an "AND" (reads are unmapped and supplementary alignments which is impossible)

samtools • 1.3k views
ADD COMMENT
2
Entering edit mode
4.8 years ago

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

 java -jar dist/samjdk.jar -e 'return record.getSupplementaryAlignmentFlag() || record.getReadUnmappedFlag();' in.bam
ADD COMMENT
2
Entering edit mode
4.8 years ago
h.mon 35k

BamTools can do what you want, read the filter section of the tutorial. When you set multiple properties in one filter, these properties are AND-ed, and when you set multiple properties in different filters, these properties are OR-ed.

ADD COMMENT
2
Entering edit mode
4.8 years ago

The closest I can think of is, using samtools (not tested):

samtools merge - \
    <(samtools view -u -f 4 in.bam) \
    <(samtools view -u -f 2048 in.bam)

This will output BAM to stdout, replace - with an actual output filename.

ADD COMMENT
1
Entering edit mode

Maybe worth noting that this will output duplicate alignments if a record matches more than one OR conditions (e.g. for 2052 which is not really possible in this case but you never know...)

ADD REPLY

Login before adding your answer.

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