<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/bioinformatics-tutorial-with-exercises-in-r-part-1/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://r-exercises.com/2017/01/22/bioinformatics-lessons-in-r-1-biostrings-exercises/?utm_source=rss&utm_medium=rss&utm_campaign=bioinformatics-lessons-in-r-1-biostrings-exercises"> R-exercises</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a target="_blank" rel="nofollow" href="http://r-exercises.com/wp-content/uploads/2017/01/dna-1015661__340.jpg?x61433"><img sizes="(max-width: 150px) 100vw, 150px" alt="" class="wp-image-3957" src="https://i1.wp.com/r-exercises.com/wp-content/uploads/2017/01/dna-1015661__340-150x150.jpg?resize=150%2C150" data-recalc-dims="1"></a>Bioinformatics is an interdisciplinary field of study that combines the field of biology with computer science to understand biological data. Bioinformatics is generally used in laboratories as an initial or final step to get the information. This information can subsequently be utilized for the wet lab practices. However, it can also be used as a standalone computational method to get the answers to relevant biological questions. Bioinformatics has greatly accelerated the discovery process and is used in both academics as well as industry to understand genomics &amp; proteomics data, determine the protein structure, RNA structures, analyzing sequence data for molecular biological work, gene identification, to name a few applications. Over the years it has grown into a complex field of discipline requiring specific education and professional training.</p>
<p>We begin with a simple introduction in sequence data. This tutorial assumes that readers have basic knowledge about the central dogma and biological molecules such as protein, DNA and RNA; and also understand that they are biopolymers naturally or synthetically produced for a specific role. Wikipedia is a great resource to get the basic introduction on these. However, I will also write a few sentences in my exercises to refresh the knowledge of the readers. Numerous programming languages have been used for the development of Bioinformatics, ranging from low end languages such as Java, C/C++ to high end scripting languages such as perl, python and the R statistical language. Bioinformatics also involves extensive database management implementation for storage, query and updating the sequence and numerical data. Most of the Bioinformatics software can be implemented either on a Windows, Mac or Linux platform. This tutorial also assumes that the reader has some understanding about R programming, RStudio and installation of packages. We will use numerous packages both common as well as strictly developed for Bioinformatics.</p>
<p>The open source community known as <a target="_blank" rel="nofollow" href="https://www.bioconductor.org/">Bioconductor</a> specifically develops the Bioinformatics tools using R for the analysis and comprehension of high-throughput genomic data. It boasts to have two releases each year, 1296 software packages, and an active user community. It has packages developed for application ranging from basic sequence alignment to recent years’ NextGen sequencing machines. We hope that we will able to discuss more about it in later chapters, when not only readers would be able to appreciate its relevance but also utilize it in their daily examples. Let us begin with some little steps by installing a few packages on our machines. I personally prefer to begin with a fresh installation to make sure their are no conflicts from the preinstalled packages.</p>
<div>
<aside><img src="http://r-exercises.com/2017/01/22/bioinformatics-lessons-in-r-1-biostrings-exercises/?utm_source=rss&utm_medium=rss&utm_campaign=bioinformatics-lessons-in-r-1-biostrings-exercises"></aside>
<div><strong>Learn more</strong> about Bioconductor in the (Free!) online courses <a target="_blank" rel="nofollow" href="http://r-exercises.com/product/introduction-to-bioconductor-annotation-and-analysis-of-genomes-and-genomic-assays/">Introduction to Bioconductor: Annotation and Analysis of Genomes and Genomics Assays</a> and <a target="_blank" rel="nofollow" href="http://r-exercises.com/product/case-studies-in-functional-genomics/">Case Studies in Functional Genomics</a> offered by Harvard University.</div>
</div>
<p>To begin with let us first install a package known as Biostrings by running the following command on your RStudio.<br>
<code><br>
source(&quot;https://bioconductor.org/biocLite.R&quot;)<br>
</code><code>biocLite(&quot;Biostrings&quot;)<br>
</code><br>
This would take up to 5 minutes depending upon your internet connection and computer. Note that typing install.packages(“biostrings”) in RStudio might not result into success because of version issues. As usual use <code> library(Biostrings) </code>command to load the package.</p>
<p>Deoxyribonucleic acid, or DNA, stores biological information which is expressed in form of RNA inside the cells. The two antiparallel DNA strands are termed polynucleotides and they are composed of simpler monomer units called nucleotides. Each nucleotide is composed of one of four nitrogen-containing nucleobases—either cytosine (C), guanine (G), adenine (A), or thymine (T). The randomly arranged nucleotide finally write up the code of life in the form of strict vocabulary.</p>
<p>Answers to the exercises are available <a target="_blank" rel="nofollow" href="http://r-exercises.com/2017/01/22/bioinformatics-lessons-in-r-1-biostrings-solutions/">here</a>.</p>
<p>If you obtained a different (correct) answer than those listed on the solutions page, please feel free to post your answer as a comment on that page.</p>
<p><strong>Exercise 1</strong><br>
Using the following command, create a list of DNA exactly the same as the one given below, then list the outcome by writing the vector myDNA.<br>
<code>myDNA &lt;- c(&quot;ATGTTGCATTCATTAATTAAGAACGACCCAATACA&quot;) </code><br>
<code> myDNA </code></p>
<p><strong>Exercise 2</strong><br>
In recent years there has been exponential advancement in the field of DNA sequencing. High throughput methods have been developed to speed up the sequencing project. Still the basic DNA sequencing is a technology that reads each nucleotide step-by-step by chemical methods to decipher what order of letters A, T, G and C were placed that resulted into the specific DNA sequence. However, for this problem we have given you a short result from sequencing data. In a typical laboratory sequencing results, some of the DNA sequence could look something like this “CTGATTT-GATGGTC-NAT” where apart from ATGC we could see some dashes (skipped) and N (unknown) nucleotide. Copy these into mySequencing and print the result. Use the <code>length()</code> command to find out the length. Which of the following is the length</p>
<p><code>A [1] 1</code><br>
<code>B [2] 19 </code><br>
<code>C [1] 0 </code></p>
<p><strong>Exercise 3</strong><br>
Now use the package specific command called <code> DNAString </code> to copy the seq</p>
<p><code> myDNASeq &lt;- DNAString(&quot;CTGATTT-GATGGTC-NAT&quot;) </code><br>
Now use <code> length </code> command to find the length of the myDNASeq. Compare the difference between <code> mySequencing </code> and <code> myDNASeq </code>.</p>
<p><strong>Exercise 4</strong><br>
Use the <code> class() </code> command to analyze the datatype of the myDNA and myDNASeq. Which of the following represents the result</p>
<p>A<br>
<code> class(myDNASeq)<br>
[1] &quot;DNAString&quot;<br>
attr(,&quot;package&quot;)<br>
[1] &quot;Biostrings&quot;<br>
> class(myDNA)<br>
[1] &quot;integr&quot;</code><br>
B<br>
<code><br>
> class(myDNASeq)<br>
[1] &quot;DNAString&quot;<br>
attr(,&quot;package&quot;)<br>
[1] &quot;Biostrings&quot;<br>
> class(myDNA)<br>
[1] &quot;character&quot;<br>
</code></p>
<p>C None of the above<br>
D Both</p>
<p><strong>Exercise 5</strong><br>
In this problem let us attempt to paste the <code> myDNA </code> and <code> myDNASeq </code> sequences using <code> paste </code> and analyse the results. Try to understand the syntax of <code> paste </code> command using <code> ?paste </code> command. Copy the result into <code> pastedDNA </code> and print it by typing <code> pastedDNA </code> .<br>
Try to analyze the <code> pastedDNA </code> using <code> class </code> command.</p>
<p><strong>Exercise 6</strong><br>
Did you notice that final result was a <code> character </code>class and not the <code> Biostring </code> as expected? This would make <code> pastedDNA </code> not usable for biostring for any purpose. What happens is that <code> Biostrings </code> introduces a new data structure hierarchy which is different than the <code> vector </code> datatype of R. It has few sequence constructors such as <code> DNAString()</code>, <code> RNAString()</code>, <code> AAString() </code> for type of biomolecules (DNA, RNA and Amino Acids). This results into the fact that <code> Biostrings </code> objects cannot be compared with R strings (<code> myDNA == myDNASeq </code> is an invalid command). You will always end up with <code> FALSE </code> upon attempting to compare.<br>
Next we would look at some basic transformations in Biostrings that can be implemented on DNA data. These transformations are <code> reverse() </code>, <code> complement() </code>, <code> reverseComplement() </code> and <code> translate() </code>. Run the <code> myDNASeq &lt;- DNAString(&quot;CTGATTT-GATGGTC-NAT&quot;) </code> again. Run the <code> complement(myDNASeq) </code>. Analyze the data.</p>
<p><strong>Exercise 7</strong><br>
Did you find out what as happened in previous problem? This just created the complement of each nucleotide. The DNA usually exists as a double helix with both strands running antiparallel. Each base of ATGC is paired with some base on complementary strand. A has preference for T (and vise versa), G has preference for C (and vise versa). So the complementary strand is going to have the nucleotide that is pairs preferentially. However, the unknown nucleotide N gets written as N because the sequencer could not tell what it was.<br>
In next problem run <code> reverse(myDNASeq) </code></p>
<p><strong>Exercise 8</strong><br>
Did you notice what has happened? Did nucletide in DNA sequences got read from back to front and not front to back? Or not. Each complementary strand is usually written from back to front because the complementary strands are anti-parallel. This because the sign of each strand is opposite. This is basically because the strand which basically is a polymer of nucleotide either has 5’ or 3’ end (more about it later). So the +ve strand runs from 5’-3’ and -ve strand runs from 3’-5’. In the next problem run <code> reverseComplement(myDNASeq) </code></p>
<p><strong>Exercise 9</strong><br>
Did you notice what happened. The DNA sequences not only got complementary but also reversed. This is how double stranded DNA exists in nature.<br>
Run <code> alphabetFrequency(myDNASeq) </code></p>
<p><strong>Exercise 10</strong><br>
The values in problem 9 gave you the frequency of occurrence of each nucleotide in this DNA. This is an important thing to know when analyzing the DNA.<br>
Finally run translate(myDNASeq) . This would yield the hypothetical protein sequence that myDNASeq would produce. Afterall that is one of the important role of DNA, to code for the protein. What did you get?</p>
<p>In our next exercises we will work little more with Biostrings to analyze the DNA at little more. Happy learning.</p>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://r-exercises.com/2017/01/22/bioinformatics-lessons-in-r-1-biostrings-exercises/?utm_source=rss&utm_medium=rss&utm_campaign=bioinformatics-lessons-in-r-1-biostrings-exercises"> R-exercises</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/o3x6HREJyPo"></a></div>