That does what I need, thank you!
• 0 views
•
link
I have paired end data in a SAM file and I want to extract all the reads which correspond to specific contig ids. My contig ids are in a text file with one ID per line.
Output of SAM/BAM is preferred.
Thanks for your help.
ah, I see. Using awk, matching chromosomes RF01 or RF02
/samtools view -h S1.bam | awk -F '\t' 'function fun(C) { return C=="RF01" || C=="RF02";} /^@/ {print;next;} {if(fun($3) || fun($7)) print;}'
or using samjdk: http://lindenb.github.io/jvarkit/SamJdk.html
java -jar dist/samjdk.jar -e 'Predicate<String> f=C->C.equals("RF01") || C.equals("RF02"); return (!record.getReadUnmappedFlag() && f.test(record.getReferenceName())) || (!record.getMateUnmappedFlag() && f.test(record.getMateReferenceName()));' in.bam
That does what I need, thank you!
Log in to answer this question.
many duplicates. e.g: Extract ONLY chromosomes 1-22 from bam file - removing extraneous chr annotations ...
would the solution in that link also work for paired data? Thanks!
@max_19 why wouldn't it work for paired data ?
If one read in a pair matches the contig but the other read in that pair does not. Is there a way to include that pair even if only one read matches?