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
cat hg18.fa | awk '{
if (substr($0, 1, 1)==">") {filename=(substr($0,2) ".fa")}
print $0 > filename
}'
@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="|"), "|"))
}
@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 / 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 / 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
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 / 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
plotRNAcoverage <- function(rs, tx, what=c("transcripts", "exons", "introns"),
nsamples=100, main="RNA-seq bias plot", verbose="TRUE") {
what <- match.arg(what)
if (what=="transcripts") {
genes <- exonsBy(txdb, "tx")
values(genes) <- NULL
} else if (what=="exons") {
genes <- exons(txdb)
values(genes) <- NULL
genes <- split(genes, 1:length(genes))
@astatham
astatham / getimg.py
Created February 22, 2011 03:46 — forked from stchris/getimg.py
#!/usr/bin/env python
"""
getimg.py
##oh hai dere
Gets the current image of the day from NASA and sets it as the
background in Gnome. The summary / description text is written
to the image.
library(Repitools)
library(chipseq)
library(BSgenome.Hsapiens.UCSC.hg18)
library(rtracklayer)
rootdir <- "/home/data/NGS_New"
NGS <- read.csv(paste(rootdir, "NGS_Log14.csv", sep="/"), stringsAsFactors=FALSE, header=T)
load(paste(NGS$Path[1], NGS$RdataGR[1], sep="/"))