I might word my initial question like another post, but I really have the opposite meaning, i think: Filtering multiple flags with SAMtools
I am trying to remove paired-end reads from a .SAM file where neither segment is mapped
But by "remove" I don't mean collect. I want all the read pairs where the forward read OR the reverse read OR both reads are mapped then I will use bam2fastq to get the reads and assemble.
I think there are pieces missing from my reference. I will use all these reads to try to assemble a better reference. So if one read maps to the reference, but its pair does not, that is a good read for me; the reverse read is possibly part of the sequence that is missing from my reference.
What SAM flags should I set?
This won't do what he wants, since he wants to convert the bam back to fastq (with both end of a read pair present) for use in assembly. This will make a bam with many reads with missing mates.
I don't think so. That is what I had tried first, and again upon your suggestion. The bam2fastq output says: [samopen] SAM header is present: 7 sequences. This looks like paired data from lane 198. Output will be in IMmitoJF4_1.fq and IMmitoJF4_2.fq 15962489 sequences in the BAM file 15962489 sequences exported WARNING: 8855375 reads could not be matched to a mate and were not exported
However, I expect every read in the new.bam file to be paired. Since, all pairs in, then select every pair where at least one read is mapped, means all pairs out.
I did get all pairs out when I followed Filtering multiple flags with SAMtools, but they were the unmapped pairs.