Question: Extracting Unmapped Reads from BAM files using Rsamtools
0
gravatar for danekhoffman0319
3 months ago by
danekhoffman03190 wrote:

Hello,

Does anyone have any experience extracting unmapped reads from BAM files and converting them back to fastq format using Rsamtools? If you could provide some generic code to address this problem it would be greatly appreciated.

I am mapping C. elegans RNA library against E. coli genome to remove contamination. I would like to obtain the unmapped reads to then map against C. elegans genome for DGE.

PS. These are unpaired reads

Cheers

ADD COMMENTlink modified 3 months ago by Shalu Jhanwar470 • written 3 months ago by danekhoffman03190

Posting an alternate solution. You can take a look at bbsplit.sh from BBMap suite. You can easily bin reads by aligning to both these genomes at the same time.

ADD REPLYlink written 3 months ago by genomax91k

You can also use GenomicAlignments to pull the unmapped reads out. You really gotta wrangle the metadata and pull all the right values to extract the necessary information to recreate the original fastq lines - but it is do-able.

Example for single end:

readGAlignments(bam.file,params=scanBamFlag(isUnmappedQuery=TRUE)
ADD REPLYlink written 3 months ago by benformatics2.0k
0
gravatar for Shalu Jhanwar
3 months ago by
Shalu Jhanwar470
Switzerland
Shalu Jhanwar470 wrote:

You can use SAM flag value 4 to get reads unmapped from BAM files like below:

samtools view -f 4 in.bam > out.bam

You can provide this flag with Rsamtools as well.

ADD COMMENTlink written 3 months ago by Shalu Jhanwar470
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1017 users visited in the last hour