Step 3. Tutorials for R language Learning which commands to type is the main challenge, but thankfully excellent tutorials exist online. I found this tutorial to be the best one for someone unfamiliar with R. Following 12 sets of instructions should not take more than an hour. After finishing the above instructions, please try tutorials at Quick R project. The website is created to help people learn R quickly. Many other introductory tutorials for R are linked on the right sidebar, but if you finished the above two, I would suggest you to jump straight to Bioconductor. We will discuss Bioconductor packages for Transcriptome analysis tomorrow. Let me finish this article by giving two examples of using R. The first example is very easy and is p resented to make you feel comfortable with R. In fact, if you finished the above tutorials, you will laugh at me for using the example. The second example is does more complex task by using a library from Bioconductor. You will have to wait till tomorrow to laugh at me for the second example.
Example 1. Simple Calculations #R can be used as a calculator. if you type any simple #calculation, R returns the result. No programming needed.
2+3+sqrt(4) [1] 7
Here we create two vectors x and y, and plot them.
This vector format will be used in R everywhere.
x <-c(1,2,3) y <-c(10,9,8)
After this command, a new window opens plotting x and y using a line.
plot(x,y,”l”) Example 2. Processing fastq files library(ShortRead) seq <- readFastq(“a.fq”) primer <- “GGA” trimmed <- trimLRPatterns(Lpattern=Primer,subject=sread(seq),Lfixed=”subject”) primer In the above program, first line opens a library called ‘ShortRead’. If the library is not already installed in your machine, R will find it online and install for you. The second line loads a fastq file called ‘a.fq’ into an array named ‘seq’. Fastq is a fasta like format typically used for short reads. The third line creates a string called ‘primer’. It contains the sequence ‘GGA’. The fourth line goes through all short reads read from a.fq and trims them, if they have GGA or part of it on the 5′ end. All the above steps are automatically done by R without requiring you to write any complicated python script. Isn’t that cool? Two questions -
- In which directory do I save the file ‘a.fq’ for R to open? Ans. Type ‘getwd()’ in R command window and it will tell you where it picks file from. How do I get out of R? Ans. Type ‘q()’ in the command window. You can also use ‘Exit’ from the graphical menu of R to quit.