<p>Note the flag; that read is mapped in a reverse-complemented manner, so <code>isMinusStrand = FALSE</code> is filtering it out. I tested this by making a BAM file with only that read:</p>

<pre><code>@SQ SN:I    LN:1000000
000000F|arrow   2064    I   336331  7   2926310H260M1774267H    *   00  *   *
</code></pre>

<p>Then in R:</p>

<pre><code>&gt; library(Rsamtools)
&gt; blah = scanBam("foo.bam", param=ScanBamParam(what=scanBamWhat(), flag=scanBamFlag(isMinusStrand = TRUE)))[[1]]
&gt; blah$qname
[1] "000000F|arrow"
&gt; blah = scanBam("foo.bam", param=ScanBamParam(what=scanBamWhat(), flag=scanBamFlag(isMinusStrand = FALSE)))[[1]]
&gt; blah$qname
character(0)
</code></pre>

CC BY-SA 3.0
2017-07-07T15:18:17.480Z
Thanks! I don't know why I was filtering out reverse-complemented alignments! Can I just use `bam <- Rsamtools::scanBam('output/alignment/pacbio/bwa/ref/bristolAssemblySorted.bam')[[1]]` to get all the information in the BAM file?
Biomagician
CC BY-SA 3.0
2017-07-07T15:25:56.300Z
Yup, that should work!
Devon Ryan
CC BY-SA 3.0
2017-07-07T10:35:44.040Z
2017-07-09T20:07:48.103Z
2017-07-09T20:07:48.103Z
Devon Ryan
<p>I have this read in my BAM file. It maps on chromosome 1.</p>

<p>I open this BAM file in IGV, and I can see the alignment on chromosome 1.</p>

<p>But when I open this file in R with Rsamtools:</p>

<pre><code>bamContigsCel &lt;- Rsamtools::scanBam('output/alignment/pacbio/bwa/ref     /bristolAssemblySorted.bam', param = Rsamtools::ScanBamParam(what = Rsamtools::scanBamWhat(), flag = Rsamtools::scanBamFlag(isMinusStrand = FALSE), tag = bamTags))[[1]]
</code></pre>

<p>I then check if the read maps to chromosome 1 in my R object but I cannot find it.</p>

<pre><code>bamContigsCel$rname[bamContigsCel$qname == '000000F|arrow']
[1] II II IV
Levels: I II III IV MtDNA V X
</code></pre>

<p>But if I look at the BAM file, it's there. Why isn't Rsamtools importing my read into R?</p>

<pre><code>$ samtools view bristolAssemblySorted.bam | grep -n '000000F' | head  -c80
000000F|arrow   2064    I   336331  7   2926310H260M1774267H    *   0 0   GAAGCTGTCTAAACTTTGGC
</code></pre>

<p>Cross-posted on <a href="https://www.biostars.org/p/261365/" rel="noreferrer">biostars</a></p>

CC BY-SA 3.0
2017-07-07T12:51:24.350Z
Careful, your code is using an almost certainly wrong path to the BAM file.
Konrad Rudolph
<r><sam><samtools>
scanBam from Rsamtools is not importing one of my reads into R
# scanBam from Rsamtools is not importing one of my reads into R

(Asked by: username_0 on 2017-07-07)

I have this read in my BAM file. It maps on chromosome 1.
I open this BAM file in IGV, and I can see the alignment on chromosome 1.
But when I open this file in R with Rsamtools:
bamContigsCel <- Rsamtools::scanBam('output/alignment/pacbio/bwa/ref     /bristolAssemblySorted.bam', param = Rsamtools::ScanBamParam(what = Rsamtools::scanBamWhat(), flag = Rsamtools::scanBamFlag(isMinusStrand = FALSE), tag = bamTags))[[1]]

I then check if the read maps to chromosome 1 in my R object but I cannot find it.
bamContigsCel$rname[bamContigsCel$qname == '000000F|arrow']
[1] II II IV
Levels: I II III IV MtDNA V X

But if I look at the BAM file, it's there. Why isn't Rsamtools importing my read into R?
$ samtools view bristolAssemblySorted.bam | grep -n '000000F' | head  -c80
000000F|arrow   2064    I   336331  7   2926310H260M1774267H    *   0 0   GAAGCTGTCTAAACTTTGGC

Cross-posted on biostars

**Tags:** r, sam, samtools
> **Comments:**
> **username_1**: Careful, your code is using an almost certainly wrong path to the BAM file.  

---

## 1 answers

### Answer by username_2 on 2017-07-07. Score: 4 | Accepted answer

Note the flag; that read is mapped in a reverse-complemented manner, so isMinusStrand = FALSE is filtering it out. I tested this by making a BAM file with only that read:
@SQ SN:I    LN:1000000
000000F|arrow   2064    I   336331  7   2926310H260M1774267H    *   00  *   *

Then in R:
> library(Rsamtools)
> blah = scanBam("foo.bam", param=ScanBamParam(what=scanBamWhat(), flag=scanBamFlag(isMinusStrand = TRUE)))[[1]]
> blah$qname
[1] "000000F|arrow"
> blah = scanBam("foo.bam", param=ScanBamParam(what=scanBamWhat(), flag=scanBamFlag(isMinusStrand = FALSE)))[[1]]
> blah$qname
character(0)

> **Comments:**
> **username_0**: Thanks! I don't know why I was filtering out reverse-complemented alignments! Can I just use `bam <- Rsamtools::scanBam('output/alignment/pacbio/bwa/ref/bristolAssemblySorted.bam')[[1]]` to get all the information in the BAM file?  
> **username_2**: Yup, that should work!  

---

