Separating bam files to forward and reverse strand files.

When mapping RNA-seq reads to a reference genome, sequences from both directions in the reference are used. To separate the reads in a bam file map to either the forward or reverse strand specifically, we can use the following trick.

samtools view -F 0x10  -h input.bam | samtools view -bS - > forward.bam
samtools view -f 0x10  -h input.bam | samtools view -bS - > forward.bam

Here 0x10 is a flag to indicate whether the reads map to the reverse complement or not.

Advertisements

4 thoughts on “Separating bam files to forward and reverse strand files.

    1. biobeat Post author

      No. Notice that one uses “-F” and one uses “-f.” From samtools view help:

      -f INT only include reads with all bits set in INT set in FLAG [0]
      -F INT only include reads with none of the bits set in INT set in FLAG [0]

      Reply
  1. Lucile Pain

    Hello, thanks for your post.
    I want to analyse my .bam files (sorted and indexed), that have been mapped previously
    These are as this:
    – sample.merged.mdup.forward.bam
    – sample.merged.mdup.reverse.bam

    Do you know how to fusion them (for ht-seq counts sub-analysis) ?

    Thanks

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s