Friday, September 6, 2013

creating Manhattan plot (p-value, -log10(pvalue) or R-square etc) using plantbreeding package


Install recent version of R (R version 3.0.1)

Install plantbreeding. Update to recent release if you have old one.

Default plot expect pvalue as input and produce output in terms of -log10 (pvalue).

# Example data

data12 <- data.frame (snp = 1: 2000*20 , chr = c(rep(1:20, each = 2000)), 
pos= rep(1:2000, 20), pval= rnorm(2000*20, 0.001, 0.005))


manhatton.plot(dataframe = data12, SNPname = "snp", chromosome = "chr", position = "pos",pconv= "-log10",  pvcol = "pval",ymax = "maximum", ymin = 0, gapbp = 500, color=c("hotpink3","dodgerblue4"), line1 = 3, line2 = 5, pch = c(1,20) )


Plotting p-value without log conversion or R-square

plotting simple p-value or R-square 
 data13 <- data.frame (snp = 1: 2000*20 , chr = c(rep(1:20, each = 2000)), 
pos= rep(1:2000, 20), pval= rnorm(2000*20, 0.15, 0.05))

manhatton.plot(dataframe = data13, pconv= "NULL", ylabel = "R-square", SNPname = "snp", chromosome = "chr", position = "pos", pvcol = "pval",ymax = 0.5, ymin = 0, gapbp = 0, color=c("hotpink3","dodgerblue4", "green1"), line1 = 0.05, line2 = 0.1, pch = c(1,18, 21) )


 

# with stripes 
data12 <- data.frame (snp = 1: 2000*20 , chr = c(rep(1:20, each = 2000)), 
pos= rep(1:2000, 20), pval= rnorm(2000*20, 0.001, 0.005))
manhatton.plot(dataframe = data12, SNPname = "snp", chromosome = "chr", 
position = "pos", pvcol = "pval",ymax = "maximum", ymin = 0,  gapbp = 500, 
color=c("hotpink3","dodgerblue4"), line1 = 3, line2 = 5, pch = c(1,20),
stripe= TRUE, stripe.color = c("aliceblue", "cornsilk", "lightgoldenrod") 



Add annotation above or below a threshold 
# with annotation 
manhatton.plot(dataframe = data12, SNPname = "snp", chromosome = "chr", 
position = "pos", pvcol = "pval",ymax = "maximum", ymin = 0,  gapbp = 500, 
color=c("hotpink3","dodgerblue4"), line1 = 3, line2 = 5, pch = c(1,20),
annotate= TRUE, threshold= 6, thresholddir = "upper" )








Wednesday, May 15, 2013

installing plantbreeding in R 3.0.0 gui

plantbreeding 1.1.0 is  available for R 3.0.0 current version. 

You can now install in the same way:

install.packages("plantbreeding", repos="http://R-Forge.R-project.org")

If you are using RGui in windows, you do menu driven installation as well.

First you need to set repositories to R-Forge. Go to package menu then select set repositories menu and set R-Forge as your repositories.



Now we can install packages from go to the packages menu and then install packages and then select plantbreeding and click OK. 

Please note that the package dependencies must be installed. You can do manually or can be done just simply using the following commend, all at once:

install.packages("qtl")
install.packages("ggplot2")
install.packages ("onemap")
install.packages("grid")
install.packages ("agricolae")
install.packages ("reshape")
install.packages ("lme4")
install.packages ("boot")
install.packages ("plyr")
install.packages ("pvclust")








Thursday, April 4, 2013

Getting started with R/plantbreeding



How to install plantbreeding: 

The "plantbreeding" is written in R language and implemented as an add-on package.

Download R: 
R can be downloaded from The Comprehensive R Archive Network:
Both command line and graphical user interface implementation are available.

Download plantbreeding:
The "plantbreeding" is available for in R implementing environments - Microsoft Windows, Linux and Mac OSX operating systems. The software package version “plantbreeding 1.1.0 " is available for free download and use under General Public License from r-forge website (https://r-forge.r-project.org/projects/plantbreeding). The licensing, warranty and distribution policy are same as of R version 2.15.1. 

# install from R-Forge
install.packages("plantbreeding", repos="http://R-Forge.R-project.org")

Once package is installed, implementation is similar to other R software packages. 
Current version of The "plantbreeding" version 1.1.0 compilation consists of altogether 58 functions and datasets. The software will be extended to more functions useful for plant breeding and genetics. The most of functions are complete in themselves returning output in forms different data objects and / or graphs. The objects can piped to other functions available in the R library. As other typical R functions, these functions can be used to build up, user-defined, high level functions. They can be employed in combination with the data analysis routines available in R functions library including base distributions including R/base, R/stats and R/graphics or any other compatible add-in packages.

Detailed manual of each of the function is available on comes with the package and html help can be invoked with:
  help(plantbreeding)
or simply:
?plantbreeding 
Similarly help on any of the functions available can also invoked by: help(name.of.function)
or simply:
? name.of.function
 For example to seek help on carolina1 function, use help(carolina1) or simply ?carolina1.  

Examples of implementation 
# Diallel analysis 
data(fulldial) 
 out <-diallele1(dataframe = fulldial, male = "MALE", female = "FEMALE",  progeny = "TRT", replication = "REP", yvar = "YIELD" )
print(out) 
out$anvout # analysis of variance 
out$anova.mod1 # analysis of variance for GCA and SCA effects 
out$components.model1 # model1 GCA, SCA and reciprocal components 
out$gca.effmat # GCA effects
out$sca.effmat # SCA effect matrix 
out$reciprocal.effmat # reciprocal effect matrix 

# Analysis of Augmented randomized block design 
data(augblock)
out <- aug.rcb(dataframe = augblock, genotypes = "var", block = "blk", yvar = "gw")
out$anova  # analysis of variance 
out$adjusted_values # yield observed and expected value table  





Tuesday, March 19, 2013

Welcome to plantbreeding - R package


plantbreeding - Analysis and visualization of data from plant breeding and genetics experiments


This adds-on package contains functionality for analysis and visualization data from plant breeding experiments. Analysis includes both conventional quantitative genetics as well as molecular breeding tools. The library also consists of example datasets and codes to perform different analysis relevant to plant breeders depending upon other R packages.

Details

Package:plantbreeding
Type:Package
Version:1.0
Date:2012-04-21
License:GPL (>= 2)
The package contains different functiolities relevant to analysis of data from both conventional and molecular plant breeding and genetics experiments. The functionalities include analysis of designs specific to plant breeding needs such as Augmented block designs, Genotype x Environment and stability , variance component and combining ability estimations (eg. Diallel analysis, North Carolina designs, LinexTester), Heritability and Genetic correlation estimation, selection index. Beside classical breeding tools functionalities and examples provide different molecular analysis tools such as genetic map construction, - QTL mapping, association mapping and genomic selection. There are other relevant utilities relevant to handling of moderate to large datasets. Also the package includes functions for visualization of population and genetic gain under selection as well as genome or chromosome wide visualization tools fitted to needs of molecular breeding tools. General R functions are also integrated with to guide new user who have limited experience of using R.

Examples:

# load the package 
library(plantbreeding)
require (plantbreeding)

# seek help about the package 
help(plantbreeding)
library(help = plantbreeding)

# list of dataset in the package 
data(package="plantbreeding") 

# list all objects in the package 
ls("package:plantbreeding")

# load a dataset from the library - for example dataset nassociation  
data (nassociation)

# seek help on particular function, example map.plot  
help (map.plot)
?map.plot 

# example of applying a function 


# Example 1 : Diallele analysis 
require(plantbreeding)
data(fulldial) 
 out <-diallele1(dataframe = fulldial, male = "MALE", female = "FEMALE",  
 progeny = "TRT", replication = "REP", yvar = "YIELD" )
print(out) 
out$anvout # analysis of variance 
out$anova.mod1 # analysis of variance for GCA and SCA effects 
out$components.model1 # model1 GCA, SCA and reciprocal components 
out$gca.effmat # GCA effects
out$sca.effmat # SCA effect matrix
heatmap(out$sca.effmat, labRow = rownames(out$sca.effmat) ,
labCol = colnames(out$sca.effmat)) # heatmap plot of SCA matrix 
out$reciprocal.effmat # reciprocal effect matrix 


# Example 2: Stability, AMMI analysis and heatmap plot   
# stability analysis 
require(plantbreeding)
data(multienv)
out <- stability (dataframe = multienv , yvar = "yield", genotypes = "genotypes", 
environments = "environments", replication =  "replication")
out
# AMMI analysis 
results <- ammi.full(dataframe = multienv , environment = "environments", genotype = "genotypes", 
replication = "replication", yvar = "yield")
results

# heatmap plot 
heatmap (results$means, col = cm.colors (10))



# Example 3 : Analysis of Augumented row column block designs 
data(rowcoldata)
outp <- aug.rowcol(dataframe = rowcoldata, rows = "rows", columns = "columns",
 genotypes = "genotypes", yield = "yield")
outp$ANOVA # analysis of variance 
outp$Adjustment # adjusted values



#### Example 4: Mahattan plots for association mapping results 
set.seed (1234) 
data12 <- data.frame (snp = 1: 2000*20 , chr = c(rep(1:20, each = 2000)), pos= rep(1:2000, 20), 
pval= rnorm(2000*20, 0.001, 0.005))

manhatton.circos(dataframe = data12, SNPname = "snp", chromosome = "chr", position = "pos",
 pvcol = "pval",ymax = "maximum", ymin = 0, gapbp = 500,
 type = "polar", colour = "multicolor", geom = "area")
 
manhatton.circos(dataframe = data12, SNPname = "snp", chromosome = "chr", position = "pos", 
pvcol = "pval",ymax = "maximum", ymin = 0, gapbp = 1000,
 type = "polar", colour = "multicolor" , geom = "point")
 
 manhatton.circos(dataframe = data12, SNPname = "snp", chromosome = "chr", position = "pos",
  pvcol = "pval",ymax = "maximum", ymin = 0, gapbp = 1000,
 type = "regular", colour = "multicolor" , geom = c("line","point"))
 
manhatton.plot(dataframe = data12, SNPname = "snp", chromosome = "chr", position = "pos",
 pvcol = "pval",ymax = "maximum", ymin = 0, gapbp = 500, color=c("hotpink3","dodgerblue4"), 
 line1 = 3, line2 = 5, pch = c(1,20) ) 



### Example 5: plot maps with additional informations 
lab1 <- paste("SNP_", 1:30, sep = "")
mapdat <- data.frame (chr = rep(1:3, each = length (lab1)/3), label= lab1, 
position= c(0, 1, 4, 5, 6, 8, 10,  11, 12,  13,
            0, 4, 5, 9, 12, 18, 20, 21, 22,  33,
            0, 2, 6, 9, 12, 14, 18,  21, 24,  28 ))
# positions must start from zero 
 # data 2 filling avariable data 
set.seed (1234)
fillcol <-rnorm(3*(length(lab1)-1), 0.5, 0.2)
filld <- data.frame(chr1 = rep(1:3, each = length(fillcol)/3), fillcol)
 
   
 mapbar.plot (mapdat = mapdat, chr = "chr" ,position = "position",label = "label",
  colorpalvec = heat.colors, size = 10,  filld = filld, chr1 = "chr1") 
# Brewing own color palette 
 colvec1 <- colorRampPalette(c("red", "yellow", "green")) 
  mapbar.plot (mapdat = mapdat, chr = "chr" ,position = "position",label = "label", 
  colorpalvec = colvec1, size = 10, filld = filld, chr1 = "chr1") 


Suggestions for improvement are welcome !!

R-forge website: https://r-forge.r-project.org/projects/plantbreeding/