显示标签为“R”的博文。显示所有博文
显示标签为“R”的博文。显示所有博文

2013年7月28日星期日

driftsel: an R package for detecting signals of natural selection in quantitative traits

http://onlinelibrary.wiley.com/doi/10.1111/1755-0998.12111/full

Approaches and tools to differentiate between natural selection and genetic drift as causes of population differentiation are of frequent demand in evolutionary biology. Based on the approach of Ovaskainen et al. (2011), we have developed an R package (driftsel) that can be used to differentiate between stabilizing selection, diversifying selection and random genetic drift as causes of population differentiation in quantitative traits when neutral marker and quantitative genetic data are available. Apart from illustrating the use of this method and the interpretation of results using simulated data, we apply the package on data from three-spined sticklebacks (Gasterosteus aculeatus) to highlight its virtues. driftsel can also be used to perform usual quantitative genetic analyses in common-garden study designs.

2013年7月12日星期五

choose colors for your plots

1. The HTML 4.01 specification[9] defines sixteen named colors, as follows (names are defined in this context to be case-insensitive):
http://en.wikipedia.org/wiki/Web_colors
CSS 1–2.0 / HTML 3.2–4 / VGA color names
ColorNameHex (RGB)Red
(RGB)
Green
(RGB)
Blue
(RGB)
Hue
(HSL/HSV)
Satur
(HSL)
Light
(HSL)
Satur
(HSV)
Value
(HSV)
CGA number (name); alias
 White#FFFFFF100%100%100%0%100%0%100%15 (white)
 Silver#C0C0C075%75%75%0%75%0%75%(light gray)
 Gray#80808050%50%50%0%50%0%50%(dark gray)
 Black#0000000%0%0%0%0%0%0%0 (black)
 Red#FF0000100%0%0%100%50%100%100%12 (high red)
 Maroon#80000050%0%0%100%25%100%50%(low red)
 Yellow#FFFF00100%100%0%60°100%50%100%100%14 (yellow)
 Olive#80800050%50%0%60°100%25%100%50%(brown)
 Lime#00FF000%100%0%120°100%50%100%100%10 (high green); green
 Green#0080000%50%0%120°100%25%100%50%(low green)
 Aqua#00FFFF0%100%100%180°100%50%100%100%11 (high cyan); cyan
 Teal#0080800%50%50%180°100%25%100%50%(low cyan)
 Blue#0000FF0%0%100%240°100%50%100%100%(high blue)
 Navy#0000800%0%50%240°100%25%100%50%(low blue)
 Fuchsia#FF00FF100%0%100%300°100%50%100%100%13 (high magenta); magenta
 Purple#80008050%0%50%300°100%25%100%50%(low magenta)
2. using colors in R
http://research.stowers-institute.org/efg/Report/UsingColorInR.pdf


interiorfontHTMLbgcolor=Red<GreenBlueColor
Black[Color 1]#000000#000000000[Black]
White[Color 2]#FFFFFF#FFFFFF255255255[White]
Red[Color 3]#FF0000#FF000025500[Red]
Green[Color 4]#00FF00#00FF0002550[Green]
Blue[Color 5]#0000FF#0000FF00255[Blue]
Yellow[Color 6]#FFFF00#FFFF002552550[Yellow]
Magenta[Color 7]#FF00FF#FF00FF2550255[Magenta]
Cyan[Color 8]#00FFFF#00FFFF0255255[Cyan]
[Color 9][Color 9]#800000#80000012800[Color 9]
[Color 10][Color 10]#008000#00800001280[Color 10]
[Color 11][Color 11]#000080#00008000128[Color 11]
[Color 12][Color 12]#808000#8080001281280[Color 12]
[Color 13][Color 13]#800080#8000801280128[Color 13]
[Color 14][Color 14]#008080#0080800128128[Color 14]
[Color 15][Color 15]#C0C0C0#C0C0C0192192192[Color 15]
[Color 16][Color 16]#808080#808080128128128[Color 16]
[Color 17][Color 17]#9999FF#9999FF153153255[Color 17]
[Color 18][Color 18]#993366#99336615351102[Color 18]
[Color 19][Color 19]#FFFFCC#FFFFCC255255204[Color 19]
[Color 20][Color 20]#CCFFFF#CCFFFF204255255[Color 20]
[Color 21][Color 21]#660066#6600661020102[Color 21]
[Color 22][Color 22]#FF8080#FF8080255128128[Color 22]
[Color 23][Color 23]#0066CC#0066CC0102204[Color 23]
[Color 24][Color 24]#CCCCFF#CCCCFF204204255[Color 24]
[Color 25][Color 25]#000080#00008000128[Color 25]
[Color 26][Color 26]#FF00FF#FF00FF2550255[Color 26]
[Color 27][Color 27]#FFFF00#FFFF002552550[Color 27]
[Color 28][Color 28]#00FFFF#00FFFF0255255[Color 28]
[Color 29][Color 29]#800080#8000801280128[Color 29]
[Color 30][Color 30]#800000#80000012800[Color 30]
[Color 31][Color 31]#008080#0080800128128[Color 31]
[Color 32][Color 32]#0000FF#0000FF00255[Color 32]
[Color 33][Color 33]#00CCFF#00CCFF0204255[Color 33]
[Color 34][Color 34]#CCFFFF#CCFFFF204255255[Color 34]
[Color 35][Color 35]#CCFFCC#CCFFCC204255204[Color 35]
[Color 36][Color 36]#FFFF99#FFFF99255255153[Color 36]
[Color 37][Color 37]#99CCFF#99CCFF153204255[Color 37]
[Color 38][Color 38]#FF99CC#FF99CC255153204[Color 38]
[Color 39][Color 39]#CC99FF#CC99FF204153255[Color 39]
[Color 40][Color 40]#FFCC99#FFCC99255204153[Color 40]
[Color 41][Color 41]#3366FF#3366FF51102255[Color 41]
[Color 42][Color 42]#33CCCC#33CCCC51204204[Color 42]
[Color 43][Color 43]#99CC00#99CC001532040[Color 43]
[Color 44][Color 44]#FFCC00#FFCC002552040[Color 44]
[Color 45][Color 45]#FF9900#FF99002551530[Color 45]
[Color 46][Color 46]#FF6600#FF66002551020[Color 46]
[Color 47][Color 47]#666699#666699102102153[Color 47]
[Color 48][Color 48]#969696#969696150150150[Color 48]
[Color 49][Color 49]#003366#003366051102[Color 49]
[Color 50][Color 50]#339966#33996651153102[Color 50]
[Color 51][Color 51]#003300#0033000510[Color 51]
[Color 52][Color 52]#333300#33330051510[Color 52]
[Color 53][Color 53]#993300#993300153510[Color 53]
[Color 54][Color 54]#993366#99336615351102[Color 54]
[Color 55][Color 55]#333399#3333995151153[Color 55]
[Color 56][Color 56]#333333#333333515151[Color 56]
Excel only recognizes names for Color 1 through 8 (Black, White, Red, Green, Blue, Yellow, Magenta, and Cyan).  The colors 1-16 are widely understood color names from the VGA color palette.  Of the 56 colors only 40 colors appear on the palette.  The 40 colors names indicated on the Excel color palette (see below) are for descriptive purposes only. 

2013年7月2日星期二

parsing arguements in a R script

http://ggorjan.blogspot.ca/2013/07/parse-arguments-of-r-script.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+GregorGorjancsBlog+(Gregor+Gorjanc's+blog)

R can be used also as a scripting tool. We just need to add shebang in the first line of a file (script):

#!/usr/bin/Rscript

and then the R code should follow.

Often we want to pass arguments to such a script, which can be collected in the script by the commandArgs() function. Then we need to parse the arguments and conditional on them do something. I came with a rather general way of parsing these arguments using simply these few lines:
## Collect arguments
args <- a="" href="http://inside-r.org/r-doc/base/commandArgs" style="color: #b81909; text-decoration: none;">commandArgs
(TRUE)   ## Default setting when no arguments passed if(length(args) < 1) { args <- a="" href="http://inside-r.org/r-doc/base/c" style="color: #b81909; text-decoration: none;">c("--help") }   ## Help section if("--help" %in% args) { cat(" The R Script   Arguments: --arg1=someValue - numeric, blah blah --arg2=someValue - character, blah blah --arg3=someValue - logical, blah blah --help - print this text   Example: ./test.R --arg1=1 --arg2="output.txt" --arg3=TRUE \n\n")   q(save="no") }   ## Parse arguments (we expect the form --arg=value) parseArgs <- a="" href="http://inside-r.org/r-doc/base/function" style="color: #b81909; text-decoration: none;">function(x) strsplit(sub("^--", "", x), "=") argsDF <- a="" href="http://inside-r.org/r-doc/base/as.data.frame" style="color: #b81909; text-decoration: none;">as.data.frame(do.call("rbind", parseArgs(args))) argsL <- a="" href="http://inside-r.org/r-doc/base/as.list" style="color: #b81909; text-decoration: none;">as.list(as.character(argsDF$V2)) names(argsL) <- argsdf="" nbsp="" span="" style="font-style: italic;">## Arg1 default if(is.null(args$arg1)) { ## do something }   ## Arg2 default if(is.null(args$arg2)) { ## do something }   ## Arg3 default if(is.null(args$arg3)) { ## do something }
 
## ... your code here ...
Created by Pretty R at inside-R.org

It is some work, but I find it pretty neat and use it for quite a while now. I do wonder what others have come up for this task. I hope I did not miss some very general solution.

2013年6月27日星期四

distinguish effects of geographic and ecological isolation on differentiation

Populations can be genetically isolated by both geographic distance and by differences in their ecology or environment that decrease the rate of successful migration. Empirical studies often seek to investigate the relationship between genetic differentiation and some ecological variable(s) while accounting for geographic distance, but common approaches to this problem (such as the partial Mantel test) have a number of drawbacks. In this article, we present a Bayesian method that enables users to quantify the relative contributions of geographic distance and ecological distance to genetic differentiation between sampled populations or individuals. We model the allele frequencies in a set of populations at a set of unlinked loci as spatially correlated Gaussian processes, in which the covariance structure is a decreasing function of both geographic and ecological distance. Parameters of the model are estimated using a Markov chain Monte Carlo algorithm. We call this method Bayesian Estimation of Differentiation in Alleles by Spatial Structure and Local Ecology (BEDASSLE), and have implemented it in a user-friendly format in the statistical platform R. We demonstrate its utility with a simulation study and empirical applications to human and teosinte datasets.

http://arxiv.org/abs/1302.3274