Filtering BAM files for mapped or unmapped reads
samtools view -f 4 file.bam > unmapped.sam, the output will be in sam
To get only the mapped reads use the parameter 'F', which works like -v of grep and skips the alignments for a specific flag.
samtools view -b -F 4 file.bam > mapped.bam
Source: https://www.biostars.org/p/56246/ Sukhdeep Singh
reformat.sh in=reads.sam out=mapped.fq mappedonly
Also, BBMap has a lot of options designed for filtering, so it can output in fastq format and separate mapped from unmapped reads, preventing the creation of intermediate sam files. This approach also keeps pairs together, which is not very easy using samtools for filtering.
bbmap.sh ref=reference.fa in=reads.fq outm=mapped.fq outu=unmapped.fq
Source: https://www.biostars.org/p/127992/ Brian Bushnell
No comments:
Post a Comment