Skip to content

Commit

Permalink
Deployed 37bd08e with MkDocs version: 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
davetang committed Mar 25, 2024
1 parent febf0a6 commit 41d8aa5
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 40 deletions.
107 changes: 68 additions & 39 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,12 @@ <h2 id="converting-a-sam-file-to-a-bam-file">Converting a SAM file to a BAM file
<p>Size of SAM file.</p>
<pre><code class="language-bash">ls -lh eg/ERR188273_chrX.sam
</code></pre>
<pre><code>## -rw-r--r-- 1 root root 321M Mar 25 06:10 eg/ERR188273_chrX.sam
<pre><code>## -rw-r--r-- 1 root root 321M Mar 25 07:18 eg/ERR188273_chrX.sam
</code></pre>
<p>Size of BAM file.</p>
<pre><code class="language-bash">ls -lh eg/ERR188273_chrX.bam
</code></pre>
<pre><code>## -rw-r--r-- 1 root root 67M Mar 25 06:08 eg/ERR188273_chrX.bam
<pre><code>## -rw-r--r-- 1 root root 67M Mar 25 07:16 eg/ERR188273_chrX.bam
</code></pre>
<p>We can use <code>head</code> to view a SAM file.</p>
<pre><code class="language-bash">head eg/ERR188273_chrX.sam
Expand Down Expand Up @@ -312,9 +312,9 @@ <h2 id="converting-a-bam-file-to-a-cram-file">Converting a BAM file to a CRAM fi

ls -lh eg/ERR188273_chrX.[sbcr]*am
</code></pre>
<pre><code>## -rw-r--r-- 1 root root 67M Mar 25 06:08 eg/ERR188273_chrX.bam
## -rw-r--r-- 1 root root 40M Mar 25 06:10 eg/ERR188273_chrX.cram
## -rw-r--r-- 1 root root 321M Mar 25 06:10 eg/ERR188273_chrX.sam
<pre><code>## -rw-r--r-- 1 root root 67M Mar 25 07:16 eg/ERR188273_chrX.bam
## -rw-r--r-- 1 root root 40M Mar 25 07:18 eg/ERR188273_chrX.cram
## -rw-r--r-- 1 root root 321M Mar 25 07:18 eg/ERR188273_chrX.sam
</code></pre>
<p>You can use <code>samtools view</code> to view a CRAM file just as you would for a
BAM file.</p>
Expand Down Expand Up @@ -343,27 +343,27 @@ <h2 id="sorting-a-sambam-file">Sorting a SAM/BAM file</h2>
ls -l eg/ERR188273_chrX.bam
ls -l eg/sorted.bam
</code></pre>
<pre><code>## -rw-r--r-- 1 root root 69983526 Mar 25 06:08 eg/ERR188273_chrX.bam
## -rw-r--r-- 1 root root 69983599 Mar 25 06:10 eg/sorted.bam
<pre><code>## -rw-r--r-- 1 root root 69983526 Mar 25 07:16 eg/ERR188273_chrX.bam
## -rw-r--r-- 1 root root 69983599 Mar 25 07:18 eg/sorted.bam
</code></pre>
<p>You should use use additional threads (if they are available) to speed
up sorting; to use four threads, use <code>-@ 4</code>.</p>
<p>Time taken using one thread (default).</p>
<pre><code class="language-bash">time samtools sort eg/ERR188273_chrX.sam -o eg/sorted.bam
</code></pre>
<pre><code>##
## real 0m8.762s
## user 0m8.436s
## sys 0m0.268s
## real 0m8.755s
## user 0m8.460s
## sys 0m0.248s
</code></pre>
<p>Time taken using four threads.</p>
<pre><code class="language-bash">time samtools sort -@ 4 eg/ERR188273_chrX.sam -o eg/sorted.bam
</code></pre>
<pre><code>## [bam_sort_core] merging from 0 files and 4 in-memory blocks...
##
## real 0m2.897s
## user 0m10.521s
## sys 0m0.483s
## real 0m2.905s
## user 0m10.518s
## sys 0m0.505s
</code></pre>
<p>Many of the SAMtools subtools can use additional threads, so make use of
them if you have the resources!</p>
Expand Down Expand Up @@ -736,26 +736,26 @@ <h2 id="comparing-bam-files">Comparing BAM files</h2>
<pre><code class="language-bash">samtools mpileup -s -f test_ref.fa aln_bwa.bam aln_mm.bam | head -20
</code></pre>
<pre><code>## [mpileup] 2 samples in 2 input files
## 1 1694 C 1 ^]. D ] 1 ^]. D ]
## 1 1695 G 1 . I ] 1 . I ]
## 1 1696 T 1 . J ] 1 . J ]
## 1 1697 T 1 . J ] 1 . J ]
## 1 1698 A 1 . J ] 1 . J ]
## 1 1699 A 1 . J ] 1 . J ]
## 1 1700 T 1 . J ] 1 . J ]
## 1 1701 C 1 . J ] 1 . J ]
## 1 1702 A 1 . J ] 1 . J ]
## 1 1703 A 1 . J ] 1 . J ]
## 1 1704 T 1 . J ] 1 . J ]
## 1 1705 C 1 . J ] 1 . J ]
## 1 1706 C 1 . J ] 1 . J ]
## 1 1707 C 1 . J ] 1 . J ]
## 1 1708 C 1 . J ] 1 . J ]
## 1 1709 C 1 . J ] 1 . J ]
## 1 1710 A 1 . J ] 1 . J ]
## 1 1711 A 1 . J ] 1 . J ]
## 1 1712 C 1 . J ] 1 . J ]
## 1 1713 A 1 . J ] 1 . J ]
## 1 4020 C 1 ^]. E ] 1 ^]. E ]
## 1 4021 T 1 . J ] 1 . J ]
## 1 4022 C 1 . J ] 1 . J ]
## 1 4023 T 1 . J ] 1 . J ]
## 1 4024 G 1 . J ] 1 . J ]
## 1 4025 T 1 . J ] 1 . J ]
## 1 4026 T 1 . J ] 1 . J ]
## 1 4027 A 1 . J ] 1 . J ]
## 1 4028 T 1 . J ] 1 . J ]
## 1 4029 A 1 . J ] 1 . J ]
## 1 4030 G 1 . J ] 1 . J ]
## 1 4031 C 1 . J ] 1 . J ]
## 1 4032 G 1 . J ] 1 . J ]
## 1 4033 G 1 . J ] 1 . J ]
## 1 4034 G 1 . J ] 1 . J ]
## 1 4035 A 1 . J ] 1 . J ]
## 1 4036 T 1 . J ] 1 . J ]
## 1 4037 T 1 . J ] 1 . J ]
## 1 4038 A 1 . J ] 1 . J ]
## 1 4039 C 1 . J ] 1 . J ]
</code></pre>
<p>Another approach is to use
<a href="https://deeptools.readthedocs.io/en/develop/">deepTools</a> and the
Expand Down Expand Up @@ -809,7 +809,8 @@ <h2 id="coverage">Coverage</h2>
of bases covered per chromosome/reference sequence.</p>
<p><code>samtools depth</code> will return three columns: reference, position, and
coverage.</p>
<pre><code class="language-bash">samtools depth eg/ERR188273_chrX.bam | head
<pre><code class="language-bash">samtools depth -@ 4 eg/ERR188273_chrX.bam &gt; ERR188273_depth.tsv
head ERR188273_depth.tsv
</code></pre>
<pre><code>## chrX 21649 1
## chrX 21650 1
Expand All @@ -823,8 +824,10 @@ <h2 id="coverage">Coverage</h2>
## chrX 21658 1
</code></pre>
<p>The average depth can be calculated by summing the third column and
dividing by the total number of bases (be sure to use <code>-a</code>).</p>
<pre><code class="language-bash">samtools depth -@ 2 -a eg/ERR188273_chrX.bam | perl -ane '$t += $F[2]; END {$cov = $t / $.; printf &quot;Bases covered:\t%.3f\nCoverage:\t%.3f\n&quot;, $., $cov}'
dividing by the total number of bases (be sure to use <code>-a</code> with
<code>samtools depth</code> as that will output all positions including zero
depth).</p>
<pre><code class="language-bash">samtools depth -@ 4 -a eg/ERR188273_chrX.bam | perl -ane '$t += $F[2]; END {$cov = $t / $.; printf &quot;Bases covered:\t%.3f\nCoverage:\t%.3f\n&quot;, $., $cov}'
</code></pre>
<pre><code>## Bases covered: 156040895.000
## Coverage: 0.532
Expand All @@ -843,7 +846,8 @@ <h2 id="coverage">Coverage</h2>
</ol>
<!-- end list -->

<pre><code class="language-bash">samtools mpileup -f genome/chrX.fa -s eg/ERR188273_chrX.bam | head
<pre><code class="language-bash">samtools mpileup -f genome/chrX.fa -s eg/ERR188273_chrX.bam &gt; ERR188273_mpileup.tsv
head ERR188273_mpileup.tsv
</code></pre>
<pre><code>## [mpileup] 1 samples in 1 input files
## chrX 251271 g 1 ^]. @ ]
Expand All @@ -862,7 +866,8 @@ <h2 id="coverage">Coverage</h2>
some filtering by default. In the case of this example, read pairs that
are not both mapped will be ignored. To count these “orphan” reads, use
the <code>--count-orphans</code> argument.</p>
<pre><code class="language-bash">samtools mpileup -f genome/chrX.fa --count-orphans -s eg/ERR188273_chrX.bam | head
<pre><code class="language-bash">samtools mpileup -f genome/chrX.fa --count-orphans -s eg/ERR188273_chrX.bam &gt; ERR188273_mpileup_orphans.tsv
head ERR188273_mpileup_orphans.tsv
</code></pre>
<pre><code>## [mpileup] 1 samples in 1 input files
## chrX 21649 g 0 * * *
Expand Down Expand Up @@ -911,6 +916,30 @@ <h2 id="coverage">Coverage</h2>
<li>average depth of each covered base = <code>meandepth</code></li>
<li>percentage of bases covered = <code>covbases</code></li>
</ol>
<p>The <a href="https://github.com/brentp/mosdepth">mosdepth</a> tool can also
calculate depth (and much faster than <code>samtools depth</code>) per base or
within a given window. The output is given in a BED file, where the
fourth column indicates the coverage.</p>
<pre><code class="language-bash">mosdepth ERR188275 eg/ERR188273_chrX.bam
gunzip -c ERR188273.per-base.bed.gz | head
</code></pre>
<pre><code>## gzip: ERR188273.per-base.bed.gz: No such file or directory
</code></pre>
<p>Coverage in using a 500 bp window.</p>
<pre><code class="language-bash">mosdepth -n --fast-mode --by 500 ERR188275_500 eg/ERR188273_chrX.bam
gunzip -c ERR188275_500.regions.bed.gz | head
</code></pre>
<pre><code>## chrX 0 500 0.00
## chrX 500 1000 0.00
## chrX 1000 1500 0.00
## chrX 1500 2000 0.00
## chrX 2000 2500 0.00
## chrX 2500 3000 0.00
## chrX 3000 3500 0.00
## chrX 3500 4000 0.00
## chrX 4000 4500 0.00
## chrX 4500 5000 0.00
</code></pre>
<h2 id="stargazers-over-time">Stargazers over time</h2>
<p><a href="https://starchart.cc/davetang/learning_bam_file"><img alt="Stargazers over
time" src="https://starchart.cc/davetang/learning_bam_file.svg" /></a></p>
Expand Down Expand Up @@ -956,5 +985,5 @@ <h2 id="stargazers-over-time">Stargazers over time</h2>

<!--
MkDocs version : 1.3.0
Build Date UTC : 2024-03-25 06:13:19.989786+00:00
Build Date UTC : 2024-03-25 07:22:47.369318+00:00
-->
2 changes: 1 addition & 1 deletion search/search_index.json

Large diffs are not rendered by default.

Binary file modified sitemap.xml.gz
Binary file not shown.

0 comments on commit 41d8aa5

Please sign in to comment.