<p>I have a fastq file with over 2 million reads.  I am trying to use FastqSampler to select 2 million reads at random.  But strangely, I don't get 2 million, I get something less -- 1929951 in the following example.  Why?</p>

<p>Might it have something to do with the way FastqSampler chunks the input file?  (author is describing this here: <a href='/p/6544/#6578'>A: Selecting random pairs from fastq?</a> )</p>

<p>It works fine if I set n to 1 million reads.</p>

<pre><code>&gt; library(ShortRead)
&gt; fq=readFastq("file.fq")
&gt; fq
class: ShortReadQ
length: 2198402 reads; width: 100 cycles
&gt; 
&gt; fqs=FastqSampler("file.fq", n=2e6)
&gt; yield(fqs)
class: ShortReadQ
length: 1929951 reads; width: 100 cycles
&gt; 
&gt; sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-redhat-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=C                 LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ShortRead_1.14.4     Rsamtools_1.8.6      lattice_0.20-13      Biostrings_2.24.1    GenomicRanges_1.8.13 IRanges_1.14.4      

loaded via a namespace (and not attached):
[1] Biobase_2.16.0 grid_2.15.2    hwriter_1.3    tools_2.15.2
</code></pre>

<p>Sorry for the delayed reply. I'm not able to reproduce this with the current version of ShortRead (1.16.3); there were bug fixes related to FastqSampler between the version you are using and the current version. </p>

<pre><code>&gt; set.seed(123)
&gt; fl &lt;- "~/b/working/tmp.fastq"
&gt; readFastq(fl)
class: ShortReadQ
length: 2198402 reads; width: 37 cycles
&gt; fqs=FastqSampler(fl, n=2e6)
&gt; yield(fqs)
class: ShortReadQ
length: 2000000 reads; width: 37 cycles
&gt; sessionInfo()
R version 2.15.2 Patched (2012-12-23 r61401)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=C                 LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] ShortRead_1.16.4     latticeExtra_0.6-24  RColorBrewer_1.0-5  
 [4] Rsamtools_1.10.2     lattice_0.20-13      Biostrings_2.26.3   
 [7] GenomicRanges_1.10.7 IRanges_1.16.6       BiocGenerics_0.4.0  
[10] BiocInstaller_1.8.3 

loaded via a namespace (and not attached):
[1] Biobase_2.18.0  bitops_1.0-5    grid_2.15.2     hwriter_1.3    
[5] parallel_2.15.2 stats4_2.15.2   zlibbioc_1.4.0
</code></pre>

<p>Try</p>

<pre><code>source("http://bioconductor.org/biocLite.R")
biocLite(character())
</code></pre>

<p>to update packages. Please ask follow-up questions on the <a href="http://bioconductor.org/help/mailing-list/mailform/">Bioconductor mailing list</a> (no subscription required).</p>
