text: user285: My tutorial link
  library(GenomicAlignments)
  
  atacReads <- readGAlignmentPairs("MACS2_peak_call/ALL_ATAC_data/HSC1.bam", param = ScanBamParam(mapqFilter = 1, 
              flag = scanBamFlag(isPaired = TRUE, isProperPair = TRUE), what = c("qname", 
          "mapq", "isize"), which = GRanges("chr20", IRanges(1, 63025520))))
  # length(atacReads)
  atacReads
  
  
  atacReads_read1 <- GenomicAlignments::first(atacReads)
  insertSizes <- abs(elementMetadata(atacReads_read1)$isize)
  head(insertSizes)
  
  
  library(magrittr)
  library(dplyr)
  library(ggplot2)
  fragLenPlot <- table(insertSizes) %>% data.frame %>% dplyr::rename(InsertSize = insertSizes, 
      Count = Freq) %>% mutate(InsertSize = as.numeric(as.vector(InsertSize)), 
   Count = as.numeric(as.vector(Count))) %>% ggplot(aes(x = InsertSize, y = Count)) + 
    geom_line()
  
  fragLenPlot + theme_bw()
  
  fragLenPlot + scale_y_continuous(trans = "log2") + theme_bw()
  
  How to i specify the Grange to span the total chromosome. Now I use only "chr20" as shown in the example.
  
  user77: You can exclude the which statement and get the entirety of all of the chromosomes. Note however that R is a very bad platform to use for this, since you end up reading everything into memory (I hope the BAM file isn't huge).
  Note that you're seriously reinventing the wheel. There are a number of packages that will directly produce the plot you want, such as bamPEFragmentSize from deepTools.
  
original_text: 285: <p>My tutorial <a href="https://rockefelleruniversity.github.io/RU_ATAC_Workshop.html" rel="nofollow noreferrer">link</a></p>
  <pre><code>library(GenomicAlignments)
  
  atacReads &lt;- readGAlignmentPairs(&quot;MACS2_peak_call/ALL_ATAC_data/HSC1.bam&quot;, param = ScanBamParam(mapqFilter = 1, 
              flag = scanBamFlag(isPaired = TRUE, isProperPair = TRUE), what = c(&quot;qname&quot;, 
          &quot;mapq&quot;, &quot;isize&quot;), which = GRanges(&quot;chr20&quot;, IRanges(1, 63025520))))
  # length(atacReads)
  atacReads
  
  
  atacReads_read1 &lt;- GenomicAlignments::first(atacReads)
  insertSizes &lt;- abs(elementMetadata(atacReads_read1)$isize)
  head(insertSizes)
  
  
  library(magrittr)
  library(dplyr)
  library(ggplot2)
  fragLenPlot &lt;- table(insertSizes) %&gt;% data.frame %&gt;% dplyr::rename(InsertSize = insertSizes, 
      Count = Freq) %&gt;% mutate(InsertSize = as.numeric(as.vector(InsertSize)), 
   Count = as.numeric(as.vector(Count))) %&gt;% ggplot(aes(x = InsertSize, y = Count)) + 
    geom_line()
  
  fragLenPlot + theme_bw()
  
  fragLenPlot + scale_y_continuous(trans = &quot;log2&quot;) + theme_bw()
  </code></pre>
  <p>How to i specify the Grange to span the total chromosome. Now I use only &quot;chr20&quot; as shown in the example.</p>
   77: <p>You can exclude the <code>which</code> statement and get the entirety of all of the chromosomes. Note however that R is a very bad platform to use for this, since you end up reading everything into memory (I hope the BAM file isn't huge).</p>
  <p>Note that you're seriously reinventing the wheel. There are a number of packages that will directly produce the plot you want, such as <code>bamPEFragmentSize</code> from deepTools.</p>
  