Skip to content

Instantly share code, notes, and snippets.

View astatham's full-sized avatar

Aaron Statham astatham

  • Garvan Institute of Medical Research
  • Sydney, Australia
View GitHub Profile
@astatham
astatham / do_R_backup.sh
Created May 11, 2011 09:12
Hacked together script to find all my .R files, and git the changes (to be run daily as a cron job)
#!/bin/bash
#Important notes
#if backupdir is under homedir then backupdir must be included in the "$backupdir"/exclude file otherwise it will recurse
#also "$backupdir"/exclude file must not contain blank lines (match everything therefore backup nothing)
homedir="/home/aarsta"
backupdir="/home/aarsta/R_Backup"
find "$homedir" -name "*.R" | grep -v -f "$backupdir"/exclude | grep -o \\/.*\\/ | sort | uniq | sed -e "s%"$homedir"/%"$backupdir"/%" -e 's% %_%g'| xargs mkdir -p
SAVEIFS=$IFS
cufflinks2TranscriptDB <- function(filename, verbose=TRUE) {
require(rtracklayer)
require(GenomicRanges)
require(GenomicFeatures)
requiredAttribs <- c("gene_id", "transcript_id", "exon_number")
if (verbose) message("Importing ", filename)
tmp <- import.gff(filename, asRangedData=FALSE)
@astatham
astatham / NOMe_plot.R
Created June 18, 2012 02:13
NOMe chart generator
GpCplot <- function(amplicon, reads, main="", minScore=150) {
require(Biostrings)
require(GenomicRanges)
if (class(amplicon)=="character") amplicon <- DNAString(amplicon)
amplicon.conv <- DNAString(gsub("C", "T", gsub("GC", "GY", gsub("CG", "YG", amplicon))))
reads <- read.DNAStringSet(reads)
readsHitAll <- list("plus"=pairwiseAlignment(reads, amplicon.conv, type="local-global"), "minus"=pairwiseAlignment(reverseComplement(reads), amplicon.conv, type="local-global"))
readsStrand <- ifelse(score(readsHitAll$plus)>score(readsHitAll$minus), "+", "-")
reads2 <- reads
@astatham
astatham / lboxplot.R
Created July 5, 2012 05:58
lboxplot function - boxplots lists of lists
lboxplot <- function(x, cols=2:(length(x)+1), ...) {
xl <- length(x)
if (xl<2) stop("Length of x must be >=2")
xn <- sapply(x, length)
if (!all(xn==xn[1])) stop ("Element lengths of x must all be the same")
xnames <- sapply(x, names)
if (!all(apply(xnames, 1, function(y) all(y==y[1])))) stop("Each element of x must have matching names")
xn <- xn[1]
xu <- unlist(x, recursive=FALSE)[rep(1:xn, each=xl)+rep((1:xl-1)*xn, xn)]
boxplot(xu, col=cols, xaxt="n", ...)
@astatham
astatham / plotDensities.R
Created February 27, 2013 23:19
Lineplot of densities
plotDensities <- function(s, col=NULL, xlim=NULL, ylim=NULL, na.rm=TRUE, lty=rep(1, length(s)), ...) {
if (!is.list(s)) s <- list(s)
if (is.null(col)) col <- rainbow(length(s))
sD <- lapply(s, density, na.rm=na.rm)
if (is.null(xlim)) xlim <- range(sapply(sD, function(x) range(x$x)))
if (is.null(ylim))ylim <- range(sapply(sD, function(x) range(x$y)))
plot(0, type="n", xlim=xlim, ylim=ylim, ...)
for (i in 1:length(sD)) lines(sD[[i]], col=col[i], lty=lty[i], ...)
}
@astatham
astatham / download_SRA.R
Created March 25, 2014 03:03
Example to download an SRA study wholly within R on wolfpack (our internal cluster)
# wolfpack modules required: hugfre/R/3.0.2 fabbus/aspera/3.1.1.70290
ascpCMD <- "ascp -QT -l1000M -i /share/ClusterShare/software/contrib/fabbus/aspera/3.1.1.70290/asperaweb_id_dsa.putty"
library(SRAdb)
if (!file.exists("../SRAmetadb.sqlite")) db <- getSRAdbFile("../") else db <- "../SRAmetadb.sqlite"
con <- dbConnect(dbDriver("SQLite"), db) # load the SRA database
accession <- "SRP026604"
@astatham
astatham / 0_reuse_code.js
Created July 22, 2014 07:56
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@astatham
astatham / logging.schema
Created August 6, 2014 07:11
logging qstat (DIRRTTY)
CREATE TABLE log(
time TEXT TEXT,
account TEXT TEXT,
env_list TEXT,
gid TEXT,
grp TEXT,
job_name TEXT,
job_number TEXT,
jobshare TEXT,
mail_list TEXT,
@astatham
astatham / hg19_to_b37d5.sh
Last active September 9, 2015 01:22
Convert a hg19 vcf to a b37d5 vcf - only handles chr1-22, X, Y & M
#!/bin/bash -e
if [[ ! -f "${1}" ]] ; then
echo "File $1 does not exist, aborting."
exit 1
fi
# Replace double digit chromosomes first
cmd="sed"
for i in `seq 10 22` `seq 1 9` X Y; do
cmd="$cmd -e 's/chr$i/$i/g'"
@astatham
astatham / JIRAtable.R
Last active January 15, 2017 12:18
Print a data.frame in JIRA/Confluence markup
JIRAtable <- function(x) {
message(paste0("||", paste(names(x), collapse="||"), "||"))
for (i in 1:nrow(x)) message(paste0("|", paste(sapply(x[i,], as.character), collapse="|"), "|"))
}