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
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
#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
# | |
# 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
""" | |
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
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
from Bio import Entrez | |
#Let NCBI know who you are in case you do something stupid :) | |
Entrez.email = '[email protected]' | |
search_s ='"ectomycorrhizal root tip" AND "New Zealand"' | |
handle = Entrez.esearch(db='nucleotide', term=search_s, retmax=100) | |
ids = Entrez.read(handle)['IdList'] | |
ids[:5] |
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 numpy as np | |
from scipy import cluster | |
from matplotlib import pyplot | |
#fake some data | |
tests = np.reshape( np.random.uniform(0,100,60), (30,2) ) | |
#plot remaining variance for each value for 'k' between 1,10 | |
initial = [cluster.vq.kmeans(tests,i) for i in range(1,10)] | |
pyplot.plot([var for (cent,var) in initial]) |
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 written to answer stackoverflow question on substitution matrices: | |
http://stackoverflow.com/questions/5686211/ | |
""" | |
from Bio.SubsMat import MatrixInfo | |
def score_match(pair, matrix): | |
""" | |
Return score for a given pair of residues in a give matrix. |
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 writted to answer this challenge at Biostar: | |
http://biostar.stackexchange.com/questions/5902/ | |
(This code includes improvements from Brad Chapman) | |
""" | |
class ORFFinder: | |
"""Find the longest ORF in a given sequence | |
"seq" is a string, if "start" is not provided any codon can be the start of |