Skip to content

Instantly share code, notes, and snippets.

View dwinter's full-sized avatar
🐢
I may be slow to respond.

David Winter dwinter

🐢
I may be slow to respond.
View GitHub Profile
---
title: rentrez tutorial
layout: tutorial
packge_version: 0.2.1
---
```{r, eval=TRUE, echo=FALSE}
opts_chunk$set(fig.path="../assets/tutorial-images/rentrez/")
```
#!/usr/bin/env python
"""
Fetch all FASTQ files associated with an SRA ID
usage:
sra_fetch.py [sra-id]
"""
{
"metadata": {
"name": "",
"signature": "sha256:98f1acba9791082035860796ccf52294670282ba8deb7745219206b5182498d8"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
@dwinter
dwinter / ex.r
Last active August 29, 2015 14:00
gb_acc <- "JF493405"
nuc_id <- entrez_search(db="nuccore", term=paste(gb_acc, "[accn]", sep=""))$id
tax_links <- entrez_link(db="taxonomy", dbfrom="nuccore", id=nuc_id)
tax_summ <- entrez_summary(db="taxonomy", id=tax_links$nuccore_taxonomy)
library(stringr)
library(rjson)
geocode <- function(loc_string){
clean_loc <- str_replace_all(str_replace_all(loc_string, "[[:punct:]]", ""), " ", "+")
base_url <- "http://maps.googleapis.com/maps/api/geocode/json?address="
loc_url <- paste(base_url, clean_loc, "&sensor=false", sep="")
geocode <- fromJSON(paste(readLines(loc_url), collapse=""))
if( length(geocode$results) > 0 ){
return(geocode$results[[1]]$geometry$location)
@dwinter
dwinter / fetch_abstract.r
Created July 12, 2013 11:23
Fetch abstracts using rentrez
library(rentrez) #written for devel-version on github
fetch_abstract <- function(doi){
search <- entrez_search(term=paste(doi, "[doi]", sep=""), db="pubmed")
rec <- parse_pubmed_xml(entrez_fetch(db="pubmed", id=search$ids, rettype="xml"))
return(rec$abstract)
}
fetch_abstract("10.1111/j.1461-0248.2010.01509.x")
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)))
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()
@dwinter
dwinter / MCMCglmm_diag.r
Created May 24, 2013 03:57
Quckly run a bunch of diagnostic tests on a list of MCMC runs
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
@dwinter
dwinter / complete_cases.r
Last active December 15, 2015 22:39
complete_cases.r
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),]