<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Posts | Cornelius Hennch</title><link>https://www.hennch.co/post/</link><atom:link href="https://www.hennch.co/post/index.xml" rel="self" type="application/rss+xml"/><description>Posts</description><generator>Wowchemy (https://wowchemy.com)</generator><language>en-us</language><copyright>© 2025 Cornelius Hennch</copyright><image><url>https://www.hennch.co/media/icon_hu2d62a3d9f0c90f7fe3f206812180bdcd_66767_512x512_fill_lanczos_center_2.png</url><title>Posts</title><link>https://www.hennch.co/post/</link></image><item><title>Free R Learning resources</title><link>https://www.hennch.co/post/free-r-learning-resources/</link><pubDate>Wed, 26 Jan 2022 00:00:00 +0000</pubDate><guid>https://www.hennch.co/post/free-r-learning-resources/</guid><description>&lt;h2 id="basics">Basics&lt;/h2>
&lt;h3 id="1-r-for-data-science-r4dshttpsr4dshadconz-br">1. &lt;a href="https://r4ds.had.co.nz" target="_blank" rel="noopener">R for Data Science (R4DS)&lt;/a> &lt;br>&lt;/h3>
&lt;p>The absolute bible and best introduction to the &amp;ldquo;Tidyverse&amp;rdquo;, a very special way of handling data and programming that is very powerful due to its simplicity and clarity. I actually don&amp;rsquo;t write a single script without using the core packages of the Tidyverse. The book is written in a clear and very readable way and contains a lot of examples and exercises to play around with.&lt;/p>
&lt;h3 id="2-an-introduction-to-rhttpsintro2rcomindexhtml-br">2. &lt;a href="https://intro2r.com/index.html" target="_blank" rel="noopener">An Introduction to R&lt;/a> &lt;br>&lt;/h3>
&lt;p>Also quite a good start to get going with R, somewhat differently oriented than R4DS.&lt;/p>
&lt;h3 id="3-r-for-health-data-sciencehttpsargoshareisedacukhealthyr_book-br">3. &lt;a href="https://argoshare.is.ed.ac.uk/healthyr_book/" target="_blank" rel="noopener">R for Health Data Science&lt;/a> &lt;br>&lt;/h3>
&lt;p>Very good uptodate e-book specific to questions from Health Data Science. Perfect supplement or sequel to R4DS. The authors have developed their own package &lt;a href="https://finalfit.org" target="_blank" rel="noopener">finalfit&lt;/a> that takes the philosophy of the Tidyverse and applies it to statistical methods for health data analysis. The functions from the package are super convenient for clinical analyses.&lt;/p>
&lt;h3 id="4-the-tidyverse-style-guidehttpsstyletidyverseorg-br">4. &lt;a href="https://style.tidyverse.org" target="_blank" rel="noopener">The tidyverse style guide&lt;/a> &lt;br>&lt;/h3>
&lt;p>The right style is everything. I can only recommend that you adopt a consistent style right from the start, and &lt;a href="https://hadley.nz" target="_blank" rel="noopener">Hadley Wickham&lt;/a> has already said everything about this in this very short e-book.&lt;/p>
&lt;h2 id="advancedmore-specific-topics">Advanced/more specific topics&lt;/h2>
&lt;h3 id="1-ggplot2-elegant-graphics-for-data-analysishttpsggplot2-bookorgindexhtml-br">1. &lt;a href="https://ggplot2-book.org/index.html" target="_blank" rel="noopener">ggplot2: Elegant Graphics for Data Analysis&lt;/a> &lt;br>&lt;/h3>
&lt;p>Everything to about visualization in R with the almighty &lt;code>ggplot2&lt;/code>. The R package ggplot2 is a game changer when it comes to creating beautiful and informative data visualizations. It is an incredibly powerful tool that allows you to easily create complex graphics and customize them to your heart&amp;rsquo;s content. The package makes it simple to create stunning visualizations of your data, from simple bar plots to more complex graphics like heatmaps and scatterplots. And with ggplot2, you can be confident that your visualizations will be clear, accurate, and highly effective at communicating your message. Plus, it&amp;rsquo;s so easy to use that even a novice can create amazing graphics in just a few minutes. So why wait? Start using ggplot2 today and watch your data come to life like never before!&lt;/p>
&lt;h3 id="2-happy-git-with-rhttpshappygitwithrcom-br">2. &lt;a href="https://happygitwithr.com" target="_blank" rel="noopener">Happy Git with R&lt;/a> &lt;br>&lt;/h3>
&lt;p>Using git and GitHub when writing reproducible data analyses with R is incredibly helpful because it allows you to easily track and manage changes to your code and data. This means that you can go back to previous versions of your analysis if needed, and you can also share your work with others in a simple and organized way. Additionally, git and GitHub make it easy to collaborate with others on data analysis projects, which can be incredibly useful when working on large and complex datasets. Overall, git and GitHub are essential tools for anyone who wants to write reproducible and collaborative data analyses with R.&lt;/p>
&lt;h3 id="3-rmarkdown-the-definitive-guidehttpsbookdownorgyihuirmarkdown-br">3. &lt;a href="https://bookdown.org/yihui/rmarkdown/" target="_blank" rel="noopener">Rmarkdown The Definitive Guide&lt;/a> &lt;br>&lt;/h3>
&lt;p>Everything about Rmarkdown, a very handy output format for analysis/reports etc. Written by the main developers of Rmarkdown. Might be superseded by quarto now.&lt;/p>
&lt;h3 id="4-what-they-forgot-to-teach-you-about-rhttpsrstatswtfindexhtml-br">4. &lt;a href="https://rstats.wtf/index.html" target="_blank" rel="noopener">What They Forgot to Teach You About R&lt;/a> &lt;br>&lt;/h3>
&lt;p>Quite funny book on advanced topics, is mostly about better workflows and more robust programming.&lt;/p>
&lt;h3 id="5-efficient-r-programminghttpscsgillespiegithubioefficientr-br">5. &lt;a href="https://csgillespie.github.io/efficientR/" target="_blank" rel="noopener">Efficient R Programming&lt;/a> &lt;br>&lt;/h3>
&lt;p>This is really advanced, it&amp;rsquo;s about writing more efficient code overall. I find it very exciting right now and at some point you get to the point where this becomes important, especially when you work with large data sets.&lt;/p></description></item><item><title>Plot genes with karyoploteR</title><link>https://www.hennch.co/post/genes-karyploter/</link><pubDate>Thu, 20 May 2021 00:00:00 +0000</pubDate><guid>https://www.hennch.co/post/genes-karyploter/</guid><description>&lt;h2 id="how-to-visualize-a-set-of-genes-across-the-genome">How to visualize a set of genes across the genome&lt;/h2>
&lt;p>When analysing sequencing data, you might come across the situation in which you want to know the location of a set of genes across the whole genome. In this case, the &lt;code>karyoploteR&lt;/code> package comes in handy. Here are three simple steps with which you can visualize a set of genes stored in a character vector.&lt;/p>
&lt;h3 id="1-define-the-character-vector-with-the-genes-of-interest">1. Define the character vector with the genes of interest&lt;/h3>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-r" data-lang="r">&lt;span style="color:#75715e"># required packages&lt;/span>
&lt;span style="color:#a6e22e">library&lt;/span>(karyoploteR)
&lt;span style="color:#75715e"># genes you want to visualize&lt;/span>
genes &lt;span style="color:#f92672">&amp;lt;-&lt;/span> &lt;span style="color:#a6e22e">c&lt;/span>(&lt;span style="color:#e6db74">&amp;#39;CD79A&amp;#39;&lt;/span>, &lt;span style="color:#e6db74">&amp;#39;CIITA&amp;#39;&lt;/span>, &lt;span style="color:#e6db74">&amp;#39;CSF2RB&amp;#39;&lt;/span>, &lt;span style="color:#e6db74">&amp;#39;DUSP2&amp;#39;&lt;/span>, &lt;span style="color:#e6db74">&amp;#39;HIST1H1E&amp;#39;&lt;/span>, &lt;span style="color:#e6db74">&amp;#39;IRF8&amp;#39;&lt;/span>, &lt;span style="color:#e6db74">&amp;#39;KLHL6&amp;#39;&lt;/span>, &lt;span style="color:#e6db74">&amp;#39;NFKB2&amp;#39;&lt;/span>, &lt;span style="color:#e6db74">&amp;#39;NFKBIE&amp;#39;&lt;/span>, &lt;span style="color:#e6db74">&amp;#39;NFKBIZ&amp;#39;&lt;/span>, &lt;span style="color:#e6db74">&amp;#39;PIM1&amp;#39;&lt;/span>, &lt;span style="color:#e6db74">&amp;#39;SOCS1&amp;#39;&lt;/span>, &lt;span style="color:#e6db74">&amp;#39;TNFAIP3&amp;#39;&lt;/span>, &lt;span style="color:#e6db74">&amp;#39;XBP1&amp;#39;&lt;/span>, &lt;span style="color:#e6db74">&amp;#39;IGLL5&amp;#39;&lt;/span>, &lt;span style="color:#e6db74">&amp;#39;NFATC2&amp;#39;&lt;/span>)
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="2-get-gene-coordinates-from-biomart">2. Get gene coordinates from Biomart&lt;/h3>
&lt;p>Choose the correct genome version, as coordinates can differ between the versions.&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-r" data-lang="r">&lt;span style="color:#75715e"># 2. Biomart query (for hg19 = grch37) -----------------------------------------&lt;/span>
ensembl &lt;span style="color:#f92672">&amp;lt;-&lt;/span> biomaRt&lt;span style="color:#f92672">::&lt;/span>&lt;span style="color:#a6e22e">useMart&lt;/span>(biomart &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#34;ENSEMBL_MART_ENSEMBL&amp;#34;&lt;/span>,
host &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#34;grch37.ensembl.org&amp;#34;&lt;/span>,
path &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#34;/biomart/martservice&amp;#34;&lt;/span>,
dataset &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#34;hsapiens_gene_ensembl&amp;#34;&lt;/span>)
&lt;span style="color:#75715e"># get coordinates of the genes to visualize (corr_cn)&lt;/span>
genes_coord &lt;span style="color:#f92672">&amp;lt;-&lt;/span>
biomaRt&lt;span style="color:#f92672">::&lt;/span>&lt;span style="color:#a6e22e">getBM&lt;/span>(attributes &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#a6e22e">c&lt;/span>(&lt;span style="color:#e6db74">&amp;#39;chromosome_name&amp;#39;&lt;/span>, &lt;span style="color:#e6db74">&amp;#39;start_position&amp;#39;&lt;/span>,
&lt;span style="color:#e6db74">&amp;#39;end_position&amp;#39;&lt;/span>, &lt;span style="color:#e6db74">&amp;#39;hgnc_symbol&amp;#39;&lt;/span>, &lt;span style="color:#e6db74">&amp;#34;band&amp;#34;&lt;/span>),
filters &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#39;hgnc_symbol&amp;#39;&lt;/span>,
values &lt;span style="color:#f92672">=&lt;/span> genes,
mart &lt;span style="color:#f92672">=&lt;/span> ensembl)
&lt;span style="color:#75715e"># constructs a GenomicRanges object from the bioMart query&lt;/span>
genes_coord &lt;span style="color:#f92672">&amp;lt;-&lt;/span> regioneR&lt;span style="color:#f92672">::&lt;/span>&lt;span style="color:#a6e22e">toGRanges&lt;/span>(genes_coord)
&lt;span style="color:#75715e"># adds &amp;#34;chr&amp;#34; before chromosomes&lt;/span>
&lt;span style="color:#a6e22e">seqlevelsStyle&lt;/span>(genes_coord) &lt;span style="color:#f92672">&amp;lt;-&lt;/span> &lt;span style="color:#e6db74">&amp;#34;UCSC&amp;#34;&lt;/span>
&lt;span style="color:#75715e"># check GRanges object&lt;/span>
&lt;span style="color:#a6e22e">head&lt;/span>(genes_coord)
&lt;span style="color:#75715e"># excludes duplicated CD79A entry&lt;/span>
genes_coord &lt;span style="color:#f92672">&amp;lt;-&lt;/span> genes_coord[&lt;span style="color:#ae81ff">-2&lt;/span>]
&lt;/code>&lt;/pre>&lt;/div>&lt;pre>&lt;code>## GRanges object with 6 ranges and 2 metadata columns:
## seqnames ranges strand | hgnc_symbol band
## &amp;lt;Rle&amp;gt; &amp;lt;IRanges&amp;gt; &amp;lt;Rle&amp;gt; | &amp;lt;character&amp;gt; &amp;lt;character&amp;gt;
## 1 chr19 42381190-42385439 * | CD79A q13.2
## 2 HG1350_HG959_PATCH 42383025-42387277 * | CD79A q13.2
## 3 chr16 10971055-11026079 * | CIITA p13.13
## 4 chr22 37309670-37336491 * | CSF2RB q12.3
## 5 chr2 96808905-96811179 * | DUSP2 q11.2
## 6 chr6 26156559-26157343 * | HIST1H1E p22.2
## -------
## seqinfo: 9 sequences from an unspecified genome; no seqlengths
&lt;/code>&lt;/pre>&lt;h3 id="3-plot-with-plotkaryotype--kpplotmarkers">3. Plot with plotKaryotype + kpPlotMarkers&lt;/h3>
&lt;p>\&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-r" data-lang="r">&lt;span style="color:#75715e"># just the chromosome ideograms&lt;/span>
kp &lt;span style="color:#f92672">&amp;lt;-&lt;/span> &lt;span style="color:#a6e22e">plotKaryotype&lt;/span>(genome &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#34;hg19&amp;#34;&lt;/span>, chromosomes &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#34;autosomal&amp;#34;&lt;/span>)
&lt;span style="color:#75715e"># add markers&lt;/span>
&lt;span style="color:#a6e22e">kpPlotMarkers&lt;/span>(kp, data &lt;span style="color:#f92672">=&lt;/span> genes_coord,
labels &lt;span style="color:#f92672">=&lt;/span> genes_coord&lt;span style="color:#f92672">$&lt;/span>hgnc_symbol,
text.orientation &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#34;horizontal&amp;#34;&lt;/span>,
r1 &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">0.5&lt;/span>, cex &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">0.9&lt;/span>)
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;img src="https://www.hennch.co/post/genes-karyploter/index_files/figure-html/plotKaryotype-1.png" width="672" />&lt;/p>
&lt;p>Just open and close the PDF device around the plot function calls in order to save it.&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-r" data-lang="r">&lt;span style="color:#a6e22e">pdf&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;karyoplot.pdf&amp;#34;&lt;/span>)
kp &lt;span style="color:#f92672">&amp;lt;-&lt;/span> &lt;span style="color:#a6e22e">plotKaryotype&lt;/span>(genome &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#34;hg19&amp;#34;&lt;/span>, chromosomes &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#34;autosomal&amp;#34;&lt;/span>)
&lt;span style="color:#a6e22e">kpPlotMarkers&lt;/span>(kp, data &lt;span style="color:#f92672">=&lt;/span> genes_coord,
labels &lt;span style="color:#f92672">=&lt;/span> genes_coord&lt;span style="color:#f92672">$&lt;/span>hgnc_symbol,
text.orientation &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#34;horizontal&amp;#34;&lt;/span>,
r1 &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">0.5&lt;/span>, cex &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">0.9&lt;/span>)
&lt;span style="color:#a6e22e">dev.off&lt;/span>()
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Voilà!&lt;/p>
&lt;p>The whole documentation of the &lt;code>karyoploteR&lt;/code> package can be found &lt;a href="https://bernatgel.github.io/karyoploter_tutorial//Examples/PlotGenes/PlotGenes.html" title="karyoploteR package documenation" target="_blank" rel="noopener">here&lt;/a>.&lt;/p>
&lt;p>Rmarkdown file with the whole source code can be found on &lt;a href="https://github.com/corneliushennch/hennch.co/blob/b5924773670310c1fdbacd8c2a7357a32c686c14/content/post/2021-05-20-genes-karyploteR/index.Rmarkdown" title="Source Rmarkdown" target="_blank" rel="noopener">Github&lt;/a>.&lt;/p></description></item></channel></rss>