Let's talk about science with Rhttps://rjbioinformatics.com
Learning R programming to explore and analyze biological datasets.
Tue, 05 Feb 2019 04:40:59 +0000 en
hourly
1 http://wordpress.com/https://secure.gravatar.com/blavatar/93419e9bac907bdcc90d1cc5a562cbcf?s=96&d=https%3A%2F%2Fs0.wp.com%2Fi%2Fbuttonw-com.pngLet's talk about science with Rhttps://rjbioinformatics.com
Fundamentals of R Programming and Statistical Analysis Video Coursehttps://rjbioinformatics.com/2017/02/01/fundamentals-of-r-programming-and-statistical-analysis-video-course/
Wed, 01 Feb 2017 22:45:38 +0000http://rjbioinformatics.com/?p=729Here is the link to my new course at PACKT publishing. I apologize in advance for some of their video editing choices but you will definitely learn a lot and be able to work through a variety of practical examples to meet your bioinformatic needs. I will upload the R code on GitHub and post the links to the files for all the videos in the course section of my website https://rjbioinformatics.com/video-course/. So be sure to stay tuned!

Video Description

The R language is widely used among statisticians and data miners to develop statistical software and data analysis.

In this course, we’ll start by diving into the different types of R data structures and you’ll learn how the R programming language handles data. Then we’ll look in-depth at manipulating different datasets in R. After that, we’ll dive into data visualization with R, using basic plots, heat maps, and networks. We’ll explore the different flow control loops of the R programming language, and you’ll learn how to debug your code.

In the second half of the course, you’ll get hands-on working with the various statistical methods in R programming. You’ll find out how to work with different probability distributions, various types of hypothesis testing, and statistical analysis with the R programming language.

By the end of this video course, you will be well-versed in the basics of R programming and the various concepts of statistical data analysis with R.

Style and Approach

This fast-paced, practical guide is filled with real-world examples that will take you on a journey through the various concepts and phases of statistical analysis using the R programming language.

]]>v05853_mockupcover-jpgRaaDeeyahJSimulating genes and counts for DESeq2 analysishttps://rjbioinformatics.com/2017/01/31/simulating-genes-and-counts-for-deseq2-analysis/
https://rjbioinformatics.com/2017/01/31/simulating-genes-and-counts-for-deseq2-analysis/#respondTue, 31 Jan 2017 20:17:46 +0000http://rjbioinformatics.com/?p=671Sometimes it is helpful to simulate gene expression data to test code or to see how your results look with simulated values from a particular probability distribution. Here I am going to show you how to simulate RNAseq expression data counts from a uniform distribution with a mininum = 0 and maximum = 1200.

Now it’s your turn! What other probability distributions could we simulate data from to perform a mock RNA seq experiment to determine how many genes could be different by chance? You can even use a bootstrap approach to calculate the p-value after running 1000 permutations of the code. Of course, to circumvent these problems we use adjusted p values but it is always nice to go back to basics and stress the importance of applying statistical methods when looking at differentially expressed genes. I encourage you all to leave your answers in the comment section below to inspire others.

Happy R programming!

]]>https://rjbioinformatics.com/2017/01/31/simulating-genes-and-counts-for-deseq2-analysis/feed/0RaaDeeyahJConverting mouse to human gene names with biomaRt packagehttps://rjbioinformatics.com/2016/10/14/converting-mouse-to-human-gene-names-with-biomart-package/
https://rjbioinformatics.com/2016/10/14/converting-mouse-to-human-gene-names-with-biomart-package/#commentsFri, 14 Oct 2016 23:52:00 +0000http://rjbioinformatics.com/?p=622Converting mouse gene names to the human equivalent and vice versa is not always as straightforward as it seems, so I wrote a function to simplify the task. The function takes advantage of the getLDS() function from the biomaRt to get the hgnc symbol equivalent from the mgi symbol. For example, let’s convert the following mouse gene symbols, Hmmr, Tlx3, and Cpeb4, to their human equivalent.

If you have any other suggestions on how to convert mouse to human gene names in R, I would love to hear them just email me at info@rjbioinformatics.com.

]]>https://rjbioinformatics.com/2016/10/14/converting-mouse-to-human-gene-names-with-biomart-package/feed/3house20mouse20standing20on20rear20feet20mus20musculusRaaDeeyahJCreating Annotated Data Frames from GEO with the GEOquery packagehttps://rjbioinformatics.com/2016/08/05/creating-annotated-data-frames-from-geo-with-the-geoquery-package/
https://rjbioinformatics.com/2016/08/05/creating-annotated-data-frames-from-geo-with-the-geoquery-package/#commentsFri, 05 Aug 2016 19:35:45 +0000http://rjbioinformatics.com/?p=418Mining gene expression data from publicly available databases is a great way to find evidence to support you working hypothesis that gene X is relevant in condition Y. You may also want to mine publicly available data to build on an existing hypothesis or simply to find additional support for your favorite gene in a different animal model or experimental condition. In this post, we will go over how to use the GEOquerypackage to download a data matrix (or eset object) directly into R and append specific probe annotation information to this matrix for it to be exported as a csv file for easy manipulation in Excel or spreadsheet tools. This is especially useful for sharing data with collaborators who are not familiar with R and would rather look up there favorite genes in a spreadsheet format.

First, let’s start by opening an R session and creating a function to return the eset (ExpressionSet) object or the original list object downloaded by the getGEO() function in R.

getGEOdataObjects <- function(x, getGSEobject=FALSE){
# Make sure the GEOquery package is installed
require("GEOquery")
# Use the getGEO() function to download the GEO data for the id stored in x
GSEDATA <- getGEO(x, GSEMatrix=T, AnnotGPL=FALSE)
# Inspect the object by printing a summary of the expression values for the first 2 columns
print(summary(exprs(GSEDATA[[1]])[, 1:2]))
# Get the eset object
eset <- GSEDATA[[1]]
# Save the objects generated for future use in the current working directory
save(GSEDATA, eset, file=paste(x, ".RData", sep=""))
# check whether we want to return the list object we downloaded on GEO or
# just the eset object with the getGSEobject argument
if(getGSEobject) return(GSEDATA) else return(eset)
}

We can test this function on a GEO dataset such as GSE73835 as follows:

# Store the dataset ids in a vector GEO_DATASETS just in case you want to loop through several GEO ids
GEO_DATASETS <- c("GSE73835")
# Use the function we created to return the eset object
eset <- getGEOdataObjects(GEO_DATASETS[1])
# Inspect the eset object to get the annotation GPL id
eset

Let’s take a look at the first 6 lines of the data frame we just created with the head()function.

As you can see once we export this data frame as a csv file, it is much easier for others to open this file as a spreadsheet and get useful information such as the gene symbol or entrez id with the expression values across the samples.

Hope this helps and happy collaborations!

]]>https://rjbioinformatics.com/2016/08/05/creating-annotated-data-frames-from-geo-with-the-geoquery-package/feed/3RaaDeeyahJexample1Creating color palettes in Rhttps://rjbioinformatics.com/2016/07/10/creating-color-palettes-in-r/
https://rjbioinformatics.com/2016/07/10/creating-color-palettes-in-r/#respondSun, 10 Jul 2016 13:23:25 +0000http://rjbioinformatics.com/?p=254There are several color palettes available in R such as rainbow(), heat.colors(), terrain.colors(), and topo.colors(). We can visualize these as 3D pie charts using the plotrix R package.

Other popular color palettes include the RColorBrewer package that has a variety of sequential, divergent and qualitative palettes and the wesandersonpackage that has color palettes derived from his films.

# To get an idea of the colors available
head(colors())
length(colors()) # 657
# To see all 657 colors as a color chart you can source the R script to generate a pdf version in your working directory

# We can create choose a palette based on the R chart as follow:
mycols <- colors()[c(8, 5, 30, 53, 118, 72)] #
# or you could enter the color names directly
# mycols <- c("aquamarine", "antiquewhite2", "blue4", "chocolate1", "deeppink2", "cyan4")
# You could also get and store all distinct colors in the cl object and use the sample function to select colors at random
cl <- colors(distinct = TRUE)
set.seed(15887) # to set random generator seed
mycols2 <- sample(cl, 7)

You can also create color palettes with hex color codes. A great example of this is to work with popular color palettes available on the http://www.colorcombos.com website. This website has various palettes you can choose from and even derive color palettes from your favorite websites. For example, let’s grab the color palette from the rjbioinformatics.com website at http://www.colorcombos.com/grabcolors.html .

After entering the URL of our website, we will receive the hex codes for the color scheme used on the website.

We can even export the colors as little pencils

You can also choose from hundred of color schemes based on your color of choice. For example, we will also create a color palette based on the color olive – ColorCombo382.

We can also create a color palette with the colorRampPalette() to use for heatmaps and other plots. For this example, we will use the leukemia dataset available in the GSVAdata package, which corresponds to microarray data from 37 human acute leukemias where 20 of these cases are Acute lymphoblastic leukemia (ALL) and the other 17 are ALL’s with Mixed leukemia gene rearrangements. For more information on the study please see Armstrong et al. Nat Genet 30:41-47, 2002.

Now you are all set to work with and create your own awesome color palettes! Happy R programing

]]>https://rjbioinformatics.com/2016/07/10/creating-color-palettes-in-r/feed/0FeaturePieChartsRaaDeeyahJScreen Shot 2016-07-10 at 9.01.30 AMScreen Shot 2016-07-10 at 9.01.45 AMScreen Shot 2016-07-09 at 5.18.32 PMScreen Shot 2016-07-09 at 5.36.02 PMScreen Shot 2016-07-09 at 5.38.34 PMC6D4E1-2F2016-FCFAEA-456789.pngC3D938-772877-7C821E-D8B98B-7A4012Screen Shot 2016-07-10 at 9.01.56 AMHeatmap_ExampleConverting Gene Names in R with AnnotationDbihttps://rjbioinformatics.com/2016/07/04/converting-gene-names-in-r-with-annotationdbi/
https://rjbioinformatics.com/2016/07/04/converting-gene-names-in-r-with-annotationdbi/#respondMon, 04 Jul 2016 18:39:24 +0000http://rjbioinformatics.com/?p=160There are many ways to convert gene accession numbers or ids to gene symbols or other types of ids in R and several R/Bioconductor packages to facilitate this process including the AnnotationDbi, annotate, and biomaRt packages. In this post, we are going to learn how to convert gene ids with the AnnotationDbi and org.Hs.eg.db package. You could potentially modify this code to work with other species such as mice with the org.Mm.eg.db package.

For example, say we have a gene expression matrix stored in M1 created from an eset object you downloaded from GEO. The study I will be using for this example is A Leukemic Stem Cell Expression Signature is Associated with Clinical Outcomes in Acute Myeloid Leukemia deposited on GEO with the accession id GSE24006. To view the script on how to generate the expression set (eset) object see the post – Retrieving Gene Expression Data Objects & Matrices From GEO.

We can generalize this function to go back and forth between gene symbols and entrez ids (or other ids) as follows:

We can generalize this function to go back and forth between gene symbols and entrez ids (or other ids) as follows:
# This function can take any of the columns(org.Hs.eg.db) as type and keys as long as the row names are in the format of the keys argument
getMatrixWithSelectedIds <- function(df, type, keys){
require("AnnotationDbi")
require("org.Hs.eg.db")
geneSymbols <- mapIds(org.Hs.eg.db, keys=rownames(df), column=type, keytype=keys, multiVals="first")
# get the entrez ids with gene symbols i.e. remove those with NA's for gene symbols
inds <- which(!is.na(geneSymbols))
found_genes <- geneSymbols[inds]
# subset your data frame based on the found_genes
df2 <- df[names(found_genes), ]
rownames(df2) <- found_genes
return(df2)
}
# for example, going from SYMBOL to ENTREZID
M1entrez <- getMatrixWithSelectedIds(M1symb, type="ENTREZID", keys="SYMBOL")

Stay tuned for more posts on Converting Gene Names in R with the annotation and biomaRt package.

]]>https://rjbioinformatics.com/2016/07/04/converting-gene-names-in-r-with-annotationdbi/feed/0GeneConvTable_Post1RaaDeeyahJWorking with Venn Diagramshttps://rjbioinformatics.com/2016/06/21/working-with-venn-diagrams/
https://rjbioinformatics.com/2016/06/21/working-with-venn-diagrams/#commentsTue, 21 Jun 2016 18:48:46 +0000http://rjbioinformatics.com/?p=115In this post, we will learn how to create venn diagrams for gene lists and how to retrieve the genes present in each venn compartment with R.

In this particular example, we will generate random gene lists using the molbiotools gene set generator but you can use your own gene lists if you prefer. Specifically, we will generate a random list of 257 genes to represent those that are upregulated in condition and another list of 1570 genes to represent those that are upregulated in condition B.

Then, we will sort and paste the gene lists in an excel document we will save as randomGeneLists.xlsx.

Now, let’s load the data into R using the gdata package.

library("gdata")
geneLists <- read.xls("randomGeneLists.xlsx", sheet=1, stringsAsFactors=FALSE, header=FALSE)
head(geneLists)
# Notice there are empty strings to complete the data frame in column 1 (V1)
tail(geneLists)
# To convert this data frame to separate gene lists with the empty strings removed we can use lapply() with our home made function(x) x[x != ""]
geneLS <- lapply(as.list(geneLists), function(x) x[x != ""])
# If this is a bit confusing you can also write a function and then use it in lapply()
removeEMPTYstrings <- function(x) {
newVectorWOstrings <- x[x != ""]
return(newVectorWOstrings)
}
geneLS2 <- lapply(as.list(geneLists), removeEMPTYstrings)
# You can print the last 6 entries of each vector stored in your list, as follows:
lapply(geneLS, tail)
lapply(geneLS2, tail) # Both methods return the same results
# We can rename our list vectors
names(geneLS) <- c("ConditionA", "ConditionB")
# Now we can plot a Venn diagram with the VennDiagram R package, as follows:
require("VennDiagram")
VENN.LIST <- geneLS
venn.plot <- venn.diagram(VENN.LIST , NULL, fill=c("darkmagenta", "darkblue"), alpha=c(0.5,0.5), cex = 2, cat.fontface=4, category.names=c("A", "B"), main="Random Gene Lists")
# To plot the venn diagram we will use the grid.draw() function to plot the venn diagram
grid.draw(venn.plot)
# To get the list of gene present in each Venn compartment we can use the gplots package
require("gplots")
a <- venn(VENN.LIST, show.plot=FALSE)
# You can inspect the contents of this object with the str() function
str(a)
# By inspecting the structure of the a object created,
# you notice two attributes: 1) dimnames 2) intersections
# We can store the intersections in a new object named inters
inters <- attr(a,"intersections")
# We can summarize the contents of each venn compartment, as follows:
# in 1) ConditionA only, 2) ConditionB only, 3) ConditionA & ConditionB
lapply(inters, head)

Now you are ready, to review the genes in each section of the venn diagram separately. Alternatively, you can always use Venny web tool that is a great way to start looking at your data and then write a modified version of this R script to make a more exhaustive figure or facilitate downstream analysis in your script.