Skip to content

Instantly share code, notes, and snippets.

View jasper1918's full-sized avatar

Jeff S Jasper jasper1918

  • Q2 Solutions | EA Genomics
  • United States
View GitHub Profile
plot_fc<-function(df, key1_x, key1_y, key2_x, key2_y, plot_xlab="", plot_ylab=""){
l1x<-log2(df[,key1_x] +1)
l1y<-log2(df[,key1_y] +1)
l2x<-log2(df[,key2_x] +1)
l2y<-log2(df[,key2_y] +1)
diff1 <- l1x - l1y
diff2 <- l2x - l2y
names(diff1) <- "DIFF1"
names(diff2) <- "DIFF2"
plot_ma<- function(dat, rep1, rep2, main_title=""){
l1<-log2(dat[,rep1] +1)
l2<-log2(dat[,rep2] +1)
diff <- l1 - l2
names(diff) <- "LOG2FC"
ave <- rowMeans(cbind(l1, l2), na.rm=TRUE)
df <- data.frame(rep1=l1, rep2=l2, "LOG2FC"=diff, "AVE_EXP"=ave, check.names = F)
max_y<-ceiling(max(abs(max(df$LOG2FC)),abs(min(df$LOG2FC)), 2))
seq_y<-round(seq(-max_y, max_y, by = .5),1)
#df$OUT1<-ifelse(abs(df$LOG2FC)>1, 0,1)
@jasper1918
jasper1918 / ggplot_linearity.R
Created March 21, 2017 13:29
ggplot_linearity
# ggplot with equation
lm_eqn <- function(df, key_y, key_x){
m<-lm(formula(paste(key_y,"~",key_x)), df)
eq <- substitute(italic(y) == b %.% italic(x) + a*","~~italic(R)^2~"="~r2,
list(a = formatC(coef(m)[1], digits = 4,format="f", flag="#"),
b = formatC(coef(m)[2], digits = 4,format = "f", flag="#"),
r2 = formatC(summary(m)$r.squared, digits = 4,format = "f", flag="#")))
as.character(as.expression(eq))
}
@jasper1918
jasper1918 / mypca.R
Last active March 14, 2017 22:57
mypca
mypca<-function(x, mytitle="", ...)
{
par(mfrow=c(1,1))
this_pc <- prcomp(x, scale=FALSE)
this_pc_coord <- this_pc$x
pc1pct=round(summary(this_pc)$importance[2,1]*100,2)
pc2pct=round(summary(this_pc)$importance[2,2]*100,2)
par(mar = c(8, 5, 3, 8), xpd=T)
plot(this_pc_coord[,1], this_pc_coord[,2], pch = 19, cex=2,
@jasper1918
jasper1918 / pairs_mod.R
Created March 14, 2017 22:35
my favorite pairs
# pairs(df, lower.panel=panel.smooth, upper.panel=panel.cor, diag.panel=panel.hist)
panel.cor <- function(x, y, digits=2, prefix="", cex.cor)
{
usr <- par("usr"); on.exit(par(usr))
par(usr = c(0, 1, 0, 1))
r <- abs(cor(x, y))
txt <- format(c(r, 0.123456789), digits=digits)[1]
txt <- paste(prefix, txt, sep="")
if(missing(cex.cor)) cex <- 0.8/strwidth(txt)