<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/how-to-build-a-shiny-app-for-disease-trait-associated-locations-of-the-human-genome/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://shiring.github.io/genome/2016/12/18/gwas_catalog_post"> Shirin's playgRound</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>This app is based on the <a target="_blank" rel="nofollow" href="http://bioconductor.org/packages/release/bioc/html/gwascat.html">gwascat</a> R package and its <em>ebicat38</em> database and shows trait-associated SNP locations of the human genome. You can visualize and compare the genomic locations of up to 8 traits simultaneously.</p>
<p>The <a target="_blank" rel="nofollow" href="http://www.ebi.ac.uk/gwas/">National Human Genome Research Institute (NHGRI) catalog of Genome-Wide Association Studies (GWAS)</a> is a curated resource of single-nucleotide polymorphism (SNP)-trait associations. The database contains more than 100,000 SNPs and all SNP-trait associations with a p-value &lt;1 × 10^−5.</p>
<p></p>
<p>You can access the app at</p>
<blockquote>
<p><a target="_blank" rel="nofollow" href="https://shiring.shinyapps.io/gwas_shiny_app/">https://shiring.shinyapps.io/gwas_shiny_app/</a></p>
</blockquote>
<p>Loading the data might take a few seconds. Patience you must have, my young padawan… <img alt="😉" class="wp-smiley" src="https://s.w.org/images/core/emoji/2/72x72/1f609.png"></p>
<p></p>
<p>Alternatively, if you are using R, you can load the app via Github with <strong>shiny</strong>:</p>
<div>
<pre><code><span>library</span><span>(</span><span>shiny</span><span>)</span><span>
</span><span>runGitHub</span><span>(</span><span>&quot;ShirinG/GWAS_Shiny_App&quot;</span><span>)</span><span> </span></code></pre>
</div>
<hr>
<p></p>
<p>If you want to know how I built this app, contine reading.</p>
<p></p>
<h1>Data preparation</h1>
<p>Initially, I wanted to load all data directly from R packages. And while this worked in principal, it made the app load super slowly.</p>
<p>So, I decided to prepare the data beforehand and save the datatables as tab-delimited text files and load them in the app.</p>
<p></p>
<h2>Genome information</h2>
<p>First, I’m preparing the genome information: for each chromosome I want to know its length:</p>
<div>
<pre><code><span>library</span><span>(</span><span>AnnotationDbi</span><span>)</span><span>
</span><span>library</span><span>(</span><span>org.Hs.eg.db</span><span>)</span><span>
</span><span>library</span><span>(</span><span>EnsDb.Hsapiens.v79</span><span>)</span><span>
</span></code></pre>
</div>
<div>
<pre><code><span>edb</span><span> </span><span>&lt;-</span><span> </span><span>EnsDb.Hsapiens.v79</span><span>
</span><span>keys</span><span> </span><span>&lt;-</span><span> </span><span>keys</span><span>(</span><span>edb</span><span>,</span><span> </span><span>keytype</span><span>=</span><span>&quot;SEQNAME&quot;</span><span>)</span><span>
</span><span>chromosome_length</span><span> </span><span>&lt;-</span><span> </span><span>select</span><span>(</span><span>edb</span><span>,</span><span> </span><span>keys</span><span> </span><span>=</span><span> </span><span>keys</span><span>,</span><span> </span><span>columns</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>&quot;SEQLENGTH&quot;</span><span>,</span><span> </span><span>&quot;SEQNAME&quot;</span><span>),</span><span> </span><span>keytype</span><span> </span><span>=</span><span> </span><span>&quot;SEQNAME&quot;</span><span>)</span><span>
</span><span>chromosome_length</span><span> </span><span>&lt;-</span><span> </span><span>chromosome_length</span><span>[</span><span>grep</span><span>(</span><span>&quot;^[0-9]+$|^X$|^Y$|^MT$&quot;</span><span>,</span><span> </span><span>chromosome_length</span><span>$</span><span>SEQNAME</span><span>),</span><span> </span><span>]</span><span>
</span><span>write.table</span><span>(</span><span>chromosome_length</span><span>,</span><span> </span><span>&quot;chromosome_length.txt&quot;</span><span>,</span><span> </span><span>row.names</span><span> </span><span>=</span><span> </span><span>FALSE</span><span>,</span><span> </span><span>col.names</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>,</span><span> </span><span>sep</span><span> </span><span>=</span><span> </span><span>&quot;\t&quot;</span><span>)</span><span>
</span></code></pre>
</div>
<p></p>
<h2>GWAS SNP data</h2>
<p>I am saving the GWAS data as a text file as well; this datatable will be used for plotting the SNP locations.</p>
<p>I am also saving a table with the alphabetically sorted traits as input for the drop-down menu.</p>
<div>
<pre><code><span>library</span><span>(</span><span>gwascat</span><span>)</span><span>
</span></code></pre>
</div>
<div>
<pre><code><span>data</span><span>(</span><span>ebicat38</span><span>)</span><span>
</span><span>gwas38</span><span> </span><span>&lt;-</span><span> </span><span>as.data.frame</span><span>(</span><span>ebicat38</span><span>)</span><span>
</span><span>gwas38</span><span>$</span><span>DISEASE.TRAIT</span><span> </span><span>&lt;-</span><span> </span><span>gsub</span><span>(</span><span>&quot;&amp;beta;&quot;</span><span>,</span><span> </span><span>&quot;beta&quot;</span><span>,</span><span> </span><span>gwas38</span><span>$</span><span>DISEASE.TRAIT</span><span>)</span><span>
</span><span># PVALUE_MLOG: -log(p-value)
</span><span>gwas38</span><span>[</span><span>is.infinite</span><span>(</span><span>gwas38</span><span>$</span><span>PVALUE_MLOG</span><span>),</span><span> </span><span>&quot;PVALUE_MLOG&quot;</span><span>]</span><span> </span><span>&lt;-</span><span> </span><span>max</span><span>(</span><span>gwas38</span><span>[</span><span>is.finite</span><span>(</span><span>gwas38</span><span>$</span><span>PVALUE_MLOG</span><span>),</span><span> </span><span>&quot;PVALUE_MLOG&quot;</span><span>])</span><span> </span><span>+</span><span> </span><span>10</span><span>
</span><span>summary</span><span>(</span><span>gwas38</span><span>[</span><span>is.finite</span><span>(</span><span>gwas38</span><span>$</span><span>PVALUE_MLOG</span><span>),</span><span> </span><span>&quot;PVALUE_MLOG&quot;</span><span>])</span><span>
</span><span>summary</span><span>(</span><span>gwas38</span><span>$</span><span>PVALUE_MLOG</span><span>)</span><span>
</span><span># OR or BETA*: Reported odds ratio or beta-coefficient associated with strongest SNP risk allele. Note that if an OR &lt;1 is reported this is inverted, along with the reported allele, so that all ORs included in the Catalog are >1. Appropriate unit and increase/decrease are included for beta coefficients.
</span><span>summary</span><span>(</span><span>gwas38</span><span>$</span><span>OR.or.BETA</span><span>)</span><span>
</span><span>write.table</span><span>(</span><span>gwas38</span><span>,</span><span> </span><span>&quot;gwas38.txt&quot;</span><span>,</span><span> </span><span>row.names</span><span> </span><span>=</span><span> </span><span>FALSE</span><span>,</span><span> </span><span>col.names</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>,</span><span> </span><span>sep</span><span> </span><span>=</span><span> </span><span>&quot;\t&quot;</span><span>)</span><span>
</span><span>gwas38_traits</span><span> </span><span>&lt;-</span><span> </span><span>as.data.frame</span><span>(</span><span>table</span><span>(</span><span>gwas38</span><span>$</span><span>DISEASE.TRAIT</span><span>))</span><span>
</span><span>colnames</span><span>(</span><span>gwas38_traits</span><span>)</span><span> </span><span>&lt;-</span><span> </span><span>c</span><span>(</span><span>&quot;Trait&quot;</span><span>,</span><span> </span><span>&quot;Frequency&quot;</span><span>)</span><span>
</span><span>write.table</span><span>(</span><span>gwas38_traits</span><span>,</span><span> </span><span>&quot;gwas38_traits.txt&quot;</span><span>,</span><span> </span><span>row.names</span><span> </span><span>=</span><span> </span><span>FALSE</span><span>,</span><span> </span><span>col.names</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>,</span><span> </span><span>sep</span><span> </span><span>=</span><span> </span><span>&quot;\t&quot;</span><span>)</span><span>
</span></code></pre>
</div>
<p></p>
<h1>The Shiny App</h1>
<p>I built my Shiny app with the traditional two-file system. This means that I have a “ui.R” file containing the layout and a “server.R” file, which contains the R code.</p>
<p></p>
<h2>ui.R</h2>
<p>From top to bottom I chose the following settings:</p>
<ul>
<li>loading the table with all traits</li>
<li>adding a “choose below” option before the traits to have no trait chosen by default</li>
<li>“united” theme for layout</li>
<li>two slider bars, one for the p-value threshold and one for the odds ratio/ beta coefficient threshold</li>
<li>drop-down menus for all traits, maximal eight can be chosen to be plotted simultaneously</li>
<li>main panel with explanatory text, main plot and output tables</li>
</ul>
<div>
<pre><code><span>library</span><span>(</span><span>shiny</span><span>)</span><span>
</span><span>library</span><span>(</span><span>shinythemes</span><span>)</span><span>
</span><span>gwas38_traits</span><span> </span><span>&lt;-</span><span> </span><span>read.table</span><span>(</span><span>&quot;gwas38_traits.txt&quot;</span><span>,</span><span> </span><span>header</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>,</span><span> </span><span>sep</span><span> </span><span>=</span><span> </span><span>&quot;\t&quot;</span><span>)</span><span>
</span><span>diseases</span><span> </span><span>&lt;-</span><span> </span><span>c</span><span>(</span><span>&quot;choose below&quot;</span><span>,</span><span> </span><span>as.character</span><span>(</span><span>gwas38_traits</span><span>$</span><span>Trait</span><span>))</span><span>
</span><span>shinyUI</span><span>(</span><span>fluidPage</span><span>(</span><span>theme</span><span> </span><span>=</span><span> </span><span>shinytheme</span><span>(</span><span>&quot;united&quot;</span><span>),</span><span>
</span><span>titlePanel</span><span>(</span><span>&quot;GWAS disease- &amp; trait-associated SNP locations of the human genome&quot;</span><span>),</span><span>
</span><span>sidebarLayout</span><span>(</span><span>
</span><span>sidebarPanel</span><span>(</span><span>
</span><span>sliderInput</span><span>(</span><span>&quot;pvalmlog&quot;</span><span>,</span><span>
</span><span>&quot;-log(p-value):&quot;</span><span>,</span><span>
</span><span>min</span><span> </span><span>=</span><span> </span><span>-13</span><span>,</span><span>
</span><span>max</span><span> </span><span>=</span><span> </span><span>332</span><span>,</span><span>
</span><span>value</span><span> </span><span>=</span><span> </span><span>-13</span><span>),</span><span>
</span><span>sliderInput</span><span>(</span><span>&quot;orbeta&quot;</span><span>,</span><span>
</span><span>&quot;odds ratio/ beta-coefficient :&quot;</span><span>,</span><span>
</span><span>min</span><span> </span><span>=</span><span> </span><span>0</span><span>,</span><span>
</span><span>max</span><span> </span><span>=</span><span> </span><span>4426</span><span>,</span><span>
</span><span>value</span><span> </span><span>=</span><span> </span><span>0</span><span>),</span><span>
</span><span>selectInput</span><span>(</span><span>&quot;variable1&quot;</span><span>,</span><span> </span><span>&quot;First trait:&quot;</span><span>,</span><span>
</span><span>choices</span><span> </span><span>=</span><span> </span><span>diseases</span><span>[</span><span>-1</span><span>]),</span><span>
</span><span>selectInput</span><span>(</span><span>&quot;variable2&quot;</span><span>,</span><span> </span><span>&quot;Second trait:&quot;</span><span>,</span><span>
</span><span>choices</span><span> </span><span>=</span><span> </span><span>diseases</span><span>),</span><span>
</span><span>selectInput</span><span>(</span><span>&quot;variable3&quot;</span><span>,</span><span> </span><span>&quot;Third trait:&quot;</span><span>,</span><span>
</span><span>choices</span><span> </span><span>=</span><span> </span><span>diseases</span><span>),</span><span>
</span><span>selectInput</span><span>(</span><span>&quot;variable4&quot;</span><span>,</span><span> </span><span>&quot;Fourth trait:&quot;</span><span>,</span><span>
</span><span>choices</span><span> </span><span>=</span><span> </span><span>diseases</span><span>),</span><span>
</span><span>selectInput</span><span>(</span><span>&quot;variable5&quot;</span><span>,</span><span> </span><span>&quot;Fifth trait:&quot;</span><span>,</span><span>
</span><span>choices</span><span> </span><span>=</span><span> </span><span>diseases</span><span>),</span><span>
</span><span>selectInput</span><span>(</span><span>&quot;variable6&quot;</span><span>,</span><span> </span><span>&quot;Sixth trait:&quot;</span><span>,</span><span>
</span><span>choices</span><span> </span><span>=</span><span> </span><span>diseases</span><span>),</span><span>
</span><span>selectInput</span><span>(</span><span>&quot;variable7&quot;</span><span>,</span><span> </span><span>&quot;Seventh trait:&quot;</span><span>,</span><span>
</span><span>choices</span><span> </span><span>=</span><span> </span><span>diseases</span><span>),</span><span>
</span><span>selectInput</span><span>(</span><span>&quot;variable8&quot;</span><span>,</span><span> </span><span>&quot;Eighth trait:&quot;</span><span>,</span><span>
</span><span>choices</span><span> </span><span>=</span><span> </span><span>diseases</span><span>)</span><span>
</span><span>),</span><span>
</span><span>mainPanel</span><span>(</span><span>
</span><span>br</span><span>(),</span><span>
</span><span>p</span><span>(</span><span>&quot;The National Human Genome Research Institute (NHGRI) catalog of Genome-Wide Association Studies (GWAS) is a curated resource of single-nucleotide polymorphisms (SNP)-trait associations. The database contains more than 100,000 SNPs and all SNP-trait associations with a p-value &lt;1 × 10^−5.&quot;</span><span>),</span><span>
</span><span>p</span><span>(</span><span>&quot;This app is based on the 'gwascat' R package and its 'ebicat38' database and shows trait-associated SNP locations of the human genome.&quot;</span><span>),</span><span>
</span><span>p</span><span>(</span><span>&quot;For more info on how I built this app check out&quot;</span><span>,</span><span> </span><span>a</span><span>(</span><span>&quot;my blog.&quot;</span><span>,</span><span> </span><span>href</span><span> </span><span>=</span><span> </span><span>&quot;https://shiring.github.io/&quot;</span><span>)),</span><span>
</span><span>br</span><span>(),</span><span>
</span><span>h</span><span>4</span><span>(</span><span>&quot;How to use this app:&quot;</span><span>),</span><span>
</span><span>div</span><span>(</span><span>&quot;Out of 1320 available traits or diseases you can choose up to 8 on the left-side panel und see their chromosomal locations below. The traits are sorted alphabetically. You can also start typing in the drop-down panel and traits matching your query will be suggested.&quot;</span><span>,</span><span> </span><span>style</span><span> </span><span>=</span><span> </span><span>&quot;color:blue&quot;</span><span>),</span><span>
</span><span>br</span><span>(),</span><span>
</span><span>div</span><span>(</span><span>&quot;With the two sliders on the left-side panel you can select SNPs above a p-value threshold (-log of association p-value) and/or above an odds ratio/ beta-coefficient threshold. The higher the -log of the p-value the more significant the association of the SNP with the trait. Beware that some SNPs have no odds ratio value and will be shown regardless of the threshold.&quot;</span><span>,</span><span> </span><span>style</span><span> </span><span>=</span><span> </span><span>&quot;color:blue&quot;</span><span>),</span><span>
</span><span>br</span><span>(),</span><span>
</span><span>div</span><span>(</span><span>&quot;The table directly below the plot shows the number of SNPs for each selected trait (without subsetting when p-value or odds ratio are changed). The second table below the first shows detailed information for each SNP of the chosen traits. This table shows only SNPs which are plotted (it subsets according to p-value and odds ratio thresholds).&quot;</span><span>,</span><span> </span><span>style</span><span> </span><span>=</span><span> </span><span>&quot;color:blue&quot;</span><span>),</span><span>
</span><span>br</span><span>(),</span><span>
</span><span>div</span><span>(</span><span>&quot;Loading might take a few seconds...&quot;</span><span>,</span><span> </span><span>style</span><span> </span><span>=</span><span> </span><span>&quot;color:red&quot;</span><span>),</span><span>
</span><span>br</span><span>(),</span><span>
</span><span>plotOutput</span><span>(</span><span>&quot;plot&quot;</span><span>),</span><span>
</span><span>tableOutput</span><span>(</span><span>'table'</span><span>),</span><span>
</span><span>tableOutput</span><span>(</span><span>'table2'</span><span>),</span><span>
</span><span>br</span><span>(),</span><span>
</span><span>p</span><span>(</span><span>&quot;GWAS catalog:&quot;</span><span>,</span><span> </span><span>a</span><span>(</span><span>&quot;http://www.ebi.ac.uk/gwas/&quot;</span><span>,</span><span> </span><span>href</span><span> </span><span>=</span><span> </span><span>&quot;http://www.ebi.ac.uk/gwas/&quot;</span><span>)),</span><span>
</span><span>p</span><span>(</span><span>a</span><span>(</span><span>&quot;Welter, Danielle et al. “The NHGRI GWAS Catalog, a Curated Resource of SNP-Trait Associations.” Nucleic Acids Research 42.Database issue (2014): D1001–D1006. PMC. Web. 17 Dec. 2016.&quot;</span><span>,</span><span> </span><span>href</span><span> </span><span>=</span><span> </span><span>&quot;https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3965119/&quot;</span><span>))</span><span>
</span><span>)</span><span>
</span><span>)</span><span>
</span><span>))</span><span>
</span></code></pre>
</div>
<p></p>
<h2>server.R</h2>
<p>This file contains the R code to produce the plot and output tables.</p>
<ul>
<li>The chromosome data is loaded for the chromosome length barplot. In order to have the correct order, I am setting the chromosome factor order manually</li>
<li>renderPlot() contains the code for the plot</li>
<li>from the eight possible input traits, all unique traits are plotted (removing “choose below” first), unique traits were set here, so as not to plot the same trait on top of themselves if the same trait is chosen in two drop-down menus</li>
<li>the first output table shows the number of SNPs for the chosen traits</li>
<li>the second output table shows SNP information for all SNPs of the chosen trait(s) within the chosen thresholds</li>
</ul>
<div>
<pre><code><span>library</span><span>(</span><span>shiny</span><span>)</span><span>
</span><span>chr_data</span><span> </span><span>&lt;-</span><span> </span><span>read.table</span><span>(</span><span>&quot;chromosome_length.txt&quot;</span><span>,</span><span> </span><span>header</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>,</span><span> </span><span>sep</span><span> </span><span>=</span><span> </span><span>&quot;\t&quot;</span><span>)</span><span>
</span><span>chr_data</span><span>$</span><span>SEQNAME</span><span> </span><span>&lt;-</span><span> </span><span>as.factor</span><span>(</span><span>chr_data</span><span>$</span><span>SEQNAME</span><span>)</span><span>
</span><span>f</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>&quot;1&quot;</span><span>,</span><span> </span><span>&quot;2&quot;</span><span>,</span><span> </span><span>&quot;3&quot;</span><span>,</span><span> </span><span>&quot;4&quot;</span><span>,</span><span> </span><span>&quot;5&quot;</span><span>,</span><span> </span><span>&quot;6&quot;</span><span>,</span><span> </span><span>&quot;7&quot;</span><span>,</span><span> </span><span>&quot;8&quot;</span><span>,</span><span> </span><span>&quot;9&quot;</span><span>,</span><span> </span><span>&quot;10&quot;</span><span>,</span><span> </span><span>&quot;11&quot;</span><span>,</span><span> </span><span>&quot;12&quot;</span><span>,</span><span> </span><span>&quot;13&quot;</span><span>,</span><span> </span><span>&quot;14&quot;</span><span>,</span><span> </span><span>&quot;15&quot;</span><span>,</span><span> </span><span>&quot;16&quot;</span><span>,</span><span> </span><span>&quot;17&quot;</span><span>,</span><span> </span><span>&quot;18&quot;</span><span>,</span><span> </span><span>&quot;19&quot;</span><span>,</span><span> </span><span>&quot;20&quot;</span><span>,</span><span> </span><span>&quot;21&quot;</span><span>,</span><span> </span><span>&quot;22&quot;</span><span>,</span><span> </span><span>&quot;X&quot;</span><span>,</span><span> </span><span>&quot;Y&quot;</span><span>,</span><span> </span><span>&quot;MT&quot;</span><span>)</span><span>
</span><span>chr_data</span><span> </span><span>&lt;-</span><span> </span><span>within</span><span>(</span><span>chr_data</span><span>,</span><span> </span><span>SEQNAME</span><span> </span><span>&lt;-</span><span> </span><span>factor</span><span>(</span><span>SEQNAME</span><span>,</span><span> </span><span>levels</span><span> </span><span>=</span><span> </span><span>f</span><span>))</span><span>
</span><span>library</span><span>(</span><span>ggplot2</span><span>)</span><span>
</span><span>gwas38</span><span> </span><span>&lt;-</span><span> </span><span>read.table</span><span>(</span><span>&quot;gwas38.txt&quot;</span><span>,</span><span> </span><span>header</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>,</span><span> </span><span>sep</span><span> </span><span>=</span><span> </span><span>&quot;\t&quot;</span><span>)</span><span>
</span><span>gwas38_traits</span><span> </span><span>&lt;-</span><span> </span><span>read.table</span><span>(</span><span>&quot;gwas38_traits.txt&quot;</span><span>,</span><span> </span><span>header</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>,</span><span> </span><span>sep</span><span> </span><span>=</span><span> </span><span>&quot;\t&quot;</span><span>)</span><span>
</span><span># Define server logic required to plot variables
</span><span>shinyServer</span><span>(</span><span>function</span><span>(</span><span>input</span><span>,</span><span> </span><span>output</span><span>)</span><span> </span><span>{</span><span>
</span><span># Generate a plot of the requested variables
</span><span> </span><span>output</span><span>$</span><span>plot</span><span> </span><span>&lt;-</span><span> </span><span>renderPlot</span><span>({</span><span>
</span><span>plot_snps</span><span> </span><span>&lt;-</span><span> </span><span>function</span><span>(</span><span>trait</span><span>){</span><span>
</span><span>if</span><span> </span><span>(</span><span>any</span><span>(</span><span>trait</span><span> </span><span>==</span><span> </span><span>&quot;choose below&quot;</span><span>)){</span><span>
</span><span>trait</span><span> </span><span>&lt;-</span><span> </span><span>trait</span><span>[</span><span>-</span><span>which</span><span>(</span><span>trait</span><span> </span><span>==</span><span> </span><span>&quot;choose below&quot;</span><span>)]</span><span>
</span><span>}</span><span> </span><span>else</span><span> </span><span>{</span><span>
</span><span>trait</span><span> </span><span>&lt;-</span><span> </span><span>unique</span><span>(</span><span>trait</span><span>)</span><span>
</span><span>}</span><span>
</span><span>for</span><span> </span><span>(</span><span>i</span><span> </span><span>in</span><span> </span><span>1</span><span>:</span><span>length</span><span>(</span><span>unique</span><span>(</span><span>trait</span><span>))){</span><span>
</span><span>trait_pre</span><span> </span><span>&lt;-</span><span> </span><span>unique</span><span>(</span><span>trait</span><span>)[</span><span>i</span><span>]</span><span>
</span><span>snps_data_pre</span><span> </span><span>&lt;-</span><span> </span><span>gwas38</span><span>[</span><span>which</span><span>(</span><span>gwas38</span><span>$</span><span>DISEASE.TRAIT</span><span> </span><span>==</span><span> </span><span>paste</span><span>(</span><span>trait_pre</span><span>)),</span><span> </span><span>]</span><span>
</span><span>snps_data_pre</span><span> </span><span>&lt;-</span><span> </span><span>data.frame</span><span>(</span><span>Chr</span><span> </span><span>=</span><span> </span><span>snps_data_pre</span><span>$</span><span>seqnames</span><span>,</span><span>
</span><span>Start</span><span> </span><span>=</span><span> </span><span>snps_data_pre</span><span>$</span><span>CHR_POS</span><span>,</span><span>
</span><span>SNPid</span><span> </span><span>=</span><span> </span><span>snps_data_pre</span><span>$</span><span>SNPS</span><span>,</span><span>
</span><span>Trait</span><span> </span><span>=</span><span> </span><span>rep</span><span>(</span><span>paste</span><span>(</span><span>trait_pre</span><span>),</span><span> </span><span>nrow</span><span>(</span><span>snps_data_pre</span><span>)),</span><span>
</span><span>PVALUE_MLOG</span><span> </span><span>=</span><span> </span><span>snps_data_pre</span><span>$</span><span>PVALUE_MLOG</span><span>,</span><span>
</span><span>OR.or.BETA</span><span> </span><span>=</span><span> </span><span>snps_data_pre</span><span>$</span><span>OR.or.BETA</span><span>)</span><span>
</span><span>snps_data_pre</span><span> </span><span>&lt;-</span><span> </span><span>subset</span><span>(</span><span>snps_data_pre</span><span>,</span><span> </span><span>PVALUE_MLOG</span><span> </span><span>></span><span> </span><span>input</span><span>$</span><span>pvalmlog</span><span>)</span><span>
</span><span>snps_data_pre</span><span> </span><span>&lt;-</span><span> </span><span>subset</span><span>(</span><span>snps_data_pre</span><span>,</span><span> </span><span>OR.or.BETA</span><span> </span><span>></span><span> </span><span>input</span><span>$</span><span>orbeta</span><span> </span><span>|</span><span> </span><span>is.na</span><span>(</span><span>OR.or.BETA</span><span>))</span><span>
</span><span>if</span><span> </span><span>(</span><span>i</span><span> </span><span>==</span><span> </span><span>1</span><span>){</span><span>
</span><span>snps_data</span><span> </span><span>&lt;-</span><span> </span><span>snps_data_pre</span><span>
</span><span>}</span><span> </span><span>else</span><span> </span><span>{</span><span>
</span><span>snps_data</span><span> </span><span>&lt;-</span><span> </span><span>rbind</span><span>(</span><span>snps_data</span><span>,</span><span> </span><span>snps_data_pre</span><span>)</span><span>
</span><span>}</span><span>
</span><span>}</span><span>
</span><span>snps_data</span><span> </span><span>&lt;-</span><span> </span><span>within</span><span>(</span><span>snps_data</span><span>,</span><span> </span><span>Chr</span><span> </span><span>&lt;-</span><span> </span><span>factor</span><span>(</span><span>Chr</span><span>,</span><span> </span><span>levels</span><span> </span><span>=</span><span> </span><span>f</span><span>))</span><span>
</span><span>p</span><span> </span><span>&lt;-</span><span> </span><span>ggplot</span><span>(</span><span>data</span><span> </span><span>=</span><span> </span><span>snps_data</span><span>,</span><span> </span><span>aes</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>Chr</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>as.numeric</span><span>(</span><span>Start</span><span>)))</span><span> </span><span>+</span><span>
</span><span>geom_bar</span><span>(</span><span>data</span><span> </span><span>=</span><span> </span><span>chr_data</span><span>,</span><span> </span><span>aes</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>SEQNAME</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>as.numeric</span><span>(</span><span>SEQLENGTH</span><span>)),</span><span> </span><span>stat</span><span> </span><span>=</span><span> </span><span>&quot;identity&quot;</span><span>,</span><span> </span><span>fill</span><span> </span><span>=</span><span> </span><span>&quot;grey90&quot;</span><span>,</span><span> </span><span>color</span><span> </span><span>=</span><span> </span><span>&quot;black&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>theme</span><span>(</span><span>
</span><span>axis.text</span><span> </span><span>=</span><span> </span><span>element_text</span><span>(</span><span>size</span><span> </span><span>=</span><span> </span><span>14</span><span>),</span><span>
</span><span>axis.title</span><span> </span><span>=</span><span> </span><span>element_text</span><span>(</span><span>size</span><span> </span><span>=</span><span> </span><span>14</span><span>),</span><span>
</span><span>panel.grid.major</span><span> </span><span>=</span><span> </span><span>element_blank</span><span>(),</span><span>
</span><span>panel.grid.minor</span><span> </span><span>=</span><span> </span><span>element_blank</span><span>(),</span><span>
</span><span>panel.background</span><span> </span><span>=</span><span> </span><span>element_rect</span><span>(</span><span>fill</span><span> </span><span>=</span><span> </span><span>&quot;white&quot;</span><span>),</span><span>
</span><span>legend.position</span><span> </span><span>=</span><span> </span><span>&quot;bottom&quot;</span><span>
</span><span>)</span><span> </span><span>+</span><span>
</span><span>labs</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>&quot;Chromosome&quot;</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>&quot;Position&quot;</span><span>)</span><span>
</span><span>p</span><span> </span><span>+</span><span> </span><span>geom_segment</span><span>(</span><span>data</span><span> </span><span>=</span><span> </span><span>snps_data</span><span>,</span><span> </span><span>aes</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>as.numeric</span><span>(</span><span>as.character</span><span>(</span><span>Chr</span><span>))</span><span> </span><span>-</span><span> </span><span>0.45</span><span>,</span><span> </span><span>xend</span><span> </span><span>=</span><span> </span><span>as.numeric</span><span>(</span><span>as.character</span><span>(</span><span>Chr</span><span>))</span><span> </span><span>+</span><span> </span><span>0.45</span><span>,</span><span>
</span><span>y</span><span> </span><span>=</span><span> </span><span>Start</span><span>,</span><span> </span><span>yend</span><span> </span><span>=</span><span> </span><span>Start</span><span>,</span><span> </span><span>colour</span><span> </span><span>=</span><span> </span><span>Trait</span><span>),</span><span> </span><span>size</span><span> </span><span>=</span><span> </span><span>2</span><span>,</span><span> </span><span>alpha</span><span> </span><span>=</span><span> </span><span>0.5</span><span>)</span><span> </span><span>+</span><span>
</span><span>scale_colour_brewer</span><span>(</span><span>palette</span><span> </span><span>=</span><span> </span><span>&quot;Set1&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>guides</span><span>(</span><span>colour</span><span> </span><span>=</span><span> </span><span>guide_legend</span><span>(</span><span>ncol</span><span> </span><span>=</span><span> </span><span>3</span><span>,</span><span> </span><span>byrow</span><span> </span><span>=</span><span> </span><span>FALSE</span><span>))</span><span>
</span><span>}</span><span>
</span><span>plot_snps</span><span>(</span><span>trait</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>input</span><span>$</span><span>variable1</span><span>,</span><span> </span><span>input</span><span>$</span><span>variable2</span><span>,</span><span> </span><span>input</span><span>$</span><span>variable3</span><span>,</span><span> </span><span>input</span><span>$</span><span>variable4</span><span>,</span><span> </span><span>input</span><span>$</span><span>variable5</span><span>,</span><span> </span><span>input</span><span>$</span><span>variable6</span><span>,</span><span> </span><span>input</span><span>$</span><span>variable7</span><span>,</span><span> </span><span>input</span><span>$</span><span>variable8</span><span>,</span><span> </span><span>input</span><span>$</span><span>variable9</span><span>))</span><span>
</span><span>})</span><span>
</span><span>output</span><span>$</span><span>table</span><span> </span><span>&lt;-</span><span> </span><span>renderTable</span><span>({</span><span>
</span><span>table</span><span> </span><span>&lt;-</span><span> </span><span>gwas38_traits</span><span>[</span><span>which</span><span>(</span><span>gwas38_traits</span><span>$</span><span>Trait</span><span> </span><span>%in%</span><span> </span><span>c</span><span>(</span><span>input</span><span>$</span><span>variable1</span><span>,</span><span> </span><span>input</span><span>$</span><span>variable2</span><span>,</span><span> </span><span>input</span><span>$</span><span>variable3</span><span>,</span><span> </span><span>input</span><span>$</span><span>variable4</span><span>,</span><span> </span><span>input</span><span>$</span><span>variable5</span><span>,</span><span> </span><span>input</span><span>$</span><span>variable6</span><span>,</span><span> </span><span>input</span><span>$</span><span>variable7</span><span>,</span><span> </span><span>input</span><span>$</span><span>variable8</span><span>)),</span><span> </span><span>]</span><span>
</span><span>})</span><span>
</span><span>output</span><span>$</span><span>table2</span><span> </span><span>&lt;-</span><span> </span><span>renderTable</span><span>({</span><span>
</span><span>table</span><span> </span><span>&lt;-</span><span> </span><span>gwas38</span><span>[</span><span>which</span><span>(</span><span>gwas38</span><span>$</span><span>DISEASE.TRAIT</span><span> </span><span>%in%</span><span> </span><span>c</span><span>(</span><span>input</span><span>$</span><span>variable1</span><span>,</span><span> </span><span>input</span><span>$</span><span>variable2</span><span>,</span><span> </span><span>input</span><span>$</span><span>variable3</span><span>,</span><span> </span><span>input</span><span>$</span><span>variable4</span><span>,</span><span> </span><span>input</span><span>$</span><span>variable5</span><span>,</span><span> </span><span>input</span><span>$</span><span>variable6</span><span>,</span><span> </span><span>input</span><span>$</span><span>variable7</span><span>,</span><span> </span><span>input</span><span>$</span><span>variable8</span><span>)),</span><span> </span><span>c</span><span>(</span><span>1</span><span>:</span><span>5</span><span>,</span><span> </span><span>8</span><span>,</span><span> </span><span>10</span><span>,</span><span> </span><span>11</span><span>,</span><span> </span><span>13</span><span>,</span><span> </span><span>14</span><span>,</span><span> </span><span>20</span><span>,</span><span> </span><span>27</span><span>,</span><span> </span><span>32</span><span>,</span><span> </span><span>33</span><span>,</span><span> </span><span>34</span><span>,</span><span> </span><span>36</span><span>)]</span><span>
</span><span>table</span><span> </span><span>&lt;-</span><span> </span><span>subset</span><span>(</span><span>table</span><span>,</span><span> </span><span>PVALUE_MLOG</span><span> </span><span>></span><span> </span><span>input</span><span>$</span><span>pvalmlog</span><span>)</span><span>
</span><span>table</span><span> </span><span>&lt;-</span><span> </span><span>subset</span><span>(</span><span>table</span><span>,</span><span> </span><span>OR.or.BETA</span><span> </span><span>></span><span> </span><span>input</span><span>$</span><span>orbeta</span><span> </span><span>|</span><span> </span><span>is.na</span><span>(</span><span>OR.or.BETA</span><span>))</span><span>
</span><span>table</span><span>[</span><span>order</span><span>(</span><span>table</span><span>$</span><span>seqnames</span><span>),</span><span> </span><span>]</span><span>
</span><span>})</span><span>
</span><span>})</span><span>
</span></code></pre>
</div>
<p></p>
<h2>Deploying to shinyapps.io</h2>
<p>Finally, I am deploying my finished app to shinyapps.io with the <em>rsconnect</em> package. You will need to register with shinyapps.io before you can host your Shiny app there and register rsconnect with the token you received.</p>
<div>
<pre><code><span>library</span><span>(</span><span>rsconnect</span><span>)</span><span>
</span></code></pre>
</div>
<div>
<pre><code><span>rsconnect</span><span>::</span><span>deployApp</span><span>(</span><span>'~/Documents/Github/blog_posts_prep/gwas/shiny/GWAS_Shiny_App'</span><span>)</span><span>
</span></code></pre>
</div>
<p>This will open your deployed app right aways. You can now share the link to your app with the world! <img alt="🙂" class="wp-smiley" src="https://s.w.org/images/core/emoji/2/72x72/1f642.png"></p>
<hr>
<p></p>
<h4>If you are interested in human genomics…</h4>
<p>… you might also like these posts:</p>
<ul>
<li><a target="_blank" rel="nofollow" href="https://shiring.github.io/genome/2016/10/23/AnnotationDbi">https://shiring.github.io/genome/2016/10/23/AnnotationDbi</a></li>
<li><a target="_blank" rel="nofollow" href="https://shiring.github.io/genome/2016/11/01/AnnotationDbi_part2">https://shiring.github.io/genome/2016/11/01/AnnotationDbi_part2</a></li>
<li><a target="_blank" rel="nofollow" href="https://shiring.github.io/genome/2016/12/11/homologous_genes_post">https://shiring.github.io/genome/2016/12/11/homologous_genes_post</a></li>
<li><a target="_blank" rel="nofollow" href="https://shiring.github.io/genome/2016/12/14/homologous_genes_part2_post">https://shiring.github.io/genome/2016/12/14/homologous_genes_part2_post</a></li>
</ul>
<hr>
<p></p>
<div>
<pre><code>## R version 3.3.2 (2016-10-31)
## Platform: x86_64-apple-darwin13.4.0 (64-bit)
## Running under: macOS Sierra 10.12.1
## 
## locale:
## [1] de_DE.UTF-8/de_DE.UTF-8/de_DE.UTF-8/C/de_DE.UTF-8/de_DE.UTF-8
## 
## attached base packages:
## [1] parallel  stats4    stats     graphics  grDevices utils     datasets 
## [8] methods   base     
## 
## other attached packages:
##  [1] rsconnect_0.6                          
##  [2] gwascat_2.6.0                          
##  [3] Homo.sapiens_1.3.1                     
##  [4] TxDb.Hsapiens.UCSC.hg19.knownGene_3.2.2
##  [5] GO.db_3.4.0                            
##  [6] OrganismDbi_1.16.0                     
##  [7] EnsDb.Hsapiens.v79_2.1.0               
##  [8] ensembldb_1.6.2                        
##  [9] GenomicFeatures_1.26.0                 
## [10] GenomicRanges_1.26.1                   
## [11] GenomeInfoDb_1.10.1                    
## [12] org.Hs.eg.db_3.4.0                     
## [13] AnnotationDbi_1.36.0                   
## [14] IRanges_2.8.1                          
## [15] S4Vectors_0.12.1                       
## [16] Biobase_2.34.0                         
## [17] BiocGenerics_0.20.0                    
## 
## loaded via a namespace (and not attached):
##   [1] colorspace_1.3-1              rprojroot_1.1                
##   [3] biovizBase_1.22.0             htmlTable_1.7                
##   [5] XVector_0.14.0                base64enc_0.1-3              
##   [7] dichromat_2.0-0               base64_2.0                   
##   [9] interactiveDisplayBase_1.12.0 codetools_0.2-15             
##  [11] splines_3.3.2                 snpStats_1.24.0              
##  [13] ggbio_1.22.0                  fail_1.3                     
##  [15] doParallel_1.0.10             knitr_1.15.1                 
##  [17] Formula_1.2-1                 gQTLBase_1.6.0               
##  [19] Rsamtools_1.26.1              cluster_2.0.5                
##  [21] graph_1.52.0                  shiny_0.14.2                 
##  [23] httr_1.2.1                    backports_1.0.4              
##  [25] assertthat_0.1                Matrix_1.2-7.1               
##  [27] lazyeval_0.2.0                limma_3.30.6                 
##  [29] acepack_1.4.1                 htmltools_0.3.5              
##  [31] tools_3.3.2                   gtable_0.2.0                 
##  [33] reshape2_1.4.2                dplyr_0.5.0                  
##  [35] fastmatch_1.0-4               Rcpp_0.12.8                  
##  [37] Biostrings_2.42.1             nlme_3.1-128                 
##  [39] rtracklayer_1.34.1            iterators_1.0.8              
##  [41] ffbase_0.12.3                 stringr_1.1.0                
##  [43] mime_0.5                      XML_3.98-1.5                 
##  [45] AnnotationHub_2.6.4           zlibbioc_1.20.0              
##  [47] scales_0.4.1                  BSgenome_1.42.0              
##  [49] VariantAnnotation_1.20.2      BiocInstaller_1.24.0         
##  [51] SummarizedExperiment_1.4.0    RBGL_1.50.0                  
##  [53] RColorBrewer_1.1-2            BBmisc_1.10                  
##  [55] yaml_2.1.14                   memoise_1.0.0                
##  [57] gridExtra_2.2.1               ggplot2_2.2.0                
##  [59] biomaRt_2.30.0                rpart_4.1-10                 
##  [61] reshape_0.8.6                 latticeExtra_0.6-28          
##  [63] stringi_1.1.2                 RSQLite_1.1-1                
##  [65] foreach_1.4.3                 checkmate_1.8.2              
##  [67] BiocParallel_1.8.1            BatchJobs_1.6                
##  [69] GenomicFiles_1.10.3           bitops_1.0-6                 
##  [71] matrixStats_0.51.0            evaluate_0.10                
##  [73] lattice_0.20-34               GenomicAlignments_1.10.0     
##  [75] bit_1.1-12                    GGally_1.3.0                 
##  [77] plyr_1.8.4                    magrittr_1.5                 
##  [79] sendmailR_1.2-1               R6_2.2.0                     
##  [81] Hmisc_4.0-1                   DBI_0.5-1                    
##  [83] foreign_0.8-67                mgcv_1.8-16                  
##  [85] survival_2.40-1               RCurl_1.95-4.8               
##  [87] nnet_7.3-12                   tibble_1.2                   
##  [89] rmarkdown_1.2                 grid_3.3.2                   
##  [91] data.table_1.10.0             gQTLstats_1.6.0              
##  [93] digest_0.6.10                 xtable_1.8-2                 
##  [95] ff_2.2-13                     httpuv_1.3.3                 
##  [97] brew_1.0-6                    openssl_0.9.5                
##  [99] munsell_0.4.3                 beeswarm_0.2.3               
## [101] Gviz_1.18.1
</code></pre>
</div>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://shiring.github.io/genome/2016/12/18/gwas_catalog_post"> Shirin's playgRound</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/B15WnfPvicQ"></a></div>