Thanks - i played around with awk and regex to get what i wanted.
I have been mapping paired-end reads (SOLiD) and would like to extract mapped pairs that are located on different chromosomes from the SAM/BAM file. `
samtools flagstat actually reports the number of pairs on different chromosomes. Are there any simple methods of extracting them?
Thank you!
3 answers
Here is a simple method:
samtools view -F 14 infile.bam | grep -v " = " > outfile.sam
The -F 14 gives you reads that are
- are mapped
- have a mate that is mapped
- but are not mapped in a proper pair
Note that there are TAB characters left and right of the = sign. Try Ctrl-V [HTML] to enter them at the terminal.
Caveat - this will include INTRA-chromosomal discordant pairs as well.
No, since identical RNAME and RNEXT are excluded. Or am I missing something?
I noticed -F, but if this relates to the second column of the SAM file, then it does not tally with the flags i have, e.g. 97 and 145 for the 50bp and 35bp reads respectively.
-F 14 will not remove reads with flag 97 or 145. Have a look at http://picard.sourceforge.net/explain-flags.html
A version that allows the reversion to bam includes the header:
samtools view -F 14 -h infile.bam | grep -v " = " > outfile.sam
reversion to bam:
samtools view -b outfile.sam > finalout.bam
can be shortened to (including mapQ>5):
samtools view -F 14 -q 5 -h input.sam \
| awk '$7 !~ /=/' \
| samtools view -Sb - \
> map_2_diff_chroms.bam
Log in to answer this question.