This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
entrez_search <- function(dbase, term, retmax=6,...){ | |
base_url <- "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=%s&term=%s&retmax=%i" | |
search <- sprintf(base_url, dbase, term, retmax) | |
raw_result <- getURL(search) | |
ids <- unlist(getNodeSet(xmlParse(raw_result), "//Id", fun=xmlValue)) | |
return(as.integer(ids)) | |
} | |
entrez_fetch <- function(dbase, ids, format, ...){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Summarise a variable in a BEAST logfile | |
arguments: | |
-h, --help show this help message and exit | |
-f or --file string whats the name of the BEAST file | |
-v or --variable string value you want to summarise | |
-b or --burnin int number of states to ignore | |
-g export graphs to summarise the sample? | |
-l export a logfile for just this variable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Code to parse the interesting bits of a PAML results file that contains | |
# statistics for several trees. Note, this approach contains some hacks that | |
# are probably specific to multiple-tree CODEML files, Biopython has a module | |
# for handling other PAML outputs, and it probably a better starting point for | |
# 'normal' (single tree) input files. | |
# | |
# TODO - should clean up handlng of resifues - use @property decorator and | |
# ._functions to simplify writing/reading. | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#calculate Cummings et al (2008) _gsi_ - a meaure of the exlusivity of a | |
#predefiend group of leaves in a phylogenetic tree | |
#example | |
# | |
# tr <- rtree(10) | |
# grp <- paste("t", 1:5, sep="") | |
# gsi(tr, grp) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
df0 <- data.frame(x=rnorm(100), y=rnorm(100), grp=factor(rep(letters[1:2], each=50))) | |
p <- ggplot(df0, aes(x,y, colour=grp, alpha=y)) | |
p + geom_point() | |
library(RColorBrewer) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chars <- c("ABC", NA, "DEF") | |
(urls <- paste("web-api&id=", chars, sep="")) | |
## [1] "my-fav-web-api/id=ABC" "my-fav-web-api/id=NA" "my-fav-web-api/id=DEF" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df1 <- data.frame(x=sample(letters, 20), y=rnorm(20)) | |
df2 <- data.frame(x=sample(letters, 20), z=rnorm(20)) | |
new_df <- merge(df1, df2, all.x=TRUE) | |
matched <- merged[complete.cases(merged),] | |
unmatched <- merged[!complete.cases(merged),] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model_diagnostics <- function(modlist, plot=TRUE){ | |
get_param_ranges <- function(x) { | |
res <- apply((sapply(x, posterior.mode)),1,range) | |
rownames(res) <- c("min", "max") | |
return(res) | |
} | |
n <- length(modlist) | |
on.exit(devAskNewPage(devAskNewPage())) #ie send it back the way it was |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f <- function(x,y) sin(x)/cos(y) | |
x <- seq(-5,5,0.1) | |
y <- seq(-5,5,0.1) | |
df <- expand.grid(x,y) #all possible combinations of x and y | |
df$value <- apply(df, 1, function(x) f(x[1], x[2])) | |
p <- ggplot(df, aes(Var1,Var2,fill=res>0)) | |
p + geom_raster() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def shotgun(iterable, size=12): | |
""" """ | |
start = random.choice(range(0, len(iterable)-size)) | |
return(start, iterable[start:start+size]) | |
def paired_end(iterable, read_size=10, gap_size=15): | |
""" """ | |
start = random.choice(range(0, len(iterable)-(read_size+gap_size))) |