This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Extract Reads From All Chromosomes Except One.

I created a sam file by aligning reads, using bwa. I want to create a new sam file that contains all reads except ones that are on a particular chromosome or have an alternative alignment on that chromosome.

How can I do it?

sam

1 answer

cat yoursam.sam | awk '{ if($3 != YourExcludedChrom) print $0 }'

That should do it.

EDIT: However, the alternate alignments to the excluded chromosome will still be in there. Sorry.

I ended up writing my own python script that filters lines in the SAM based on what chromosome they map to. So, your answer is best.

Log in to answer this question.