library(hexbin) args=commandArgs(TRUE) mir_delta_file=args[1] #data file with all mir deltas rna_delta_file=args[2] #data file with all rna deltas links_file=args[3] #all mir-rna links to graph, in the format mir,rna,hgnc name outdir=args[4] rna_deltas=read.table(rna_delta_file, row.names=1, header=TRUE, sep=",") mir_deltas=read.table(mir_delta_file, row.names=1, header=TRUE, sep=",") links=read.table(links_file, header=FALSE, sep=",", as.is=c(TRUE,TRUE,TRUE)) drawgraph = function (mir, rna, mir_name, rna_name, outdir) { fit = lm(as.matrix(rna_deltas[rna]) ~ as.matrix(mir_deltas[mir])) adj_r_sq = sprintf("%.3f", summary(fit)$adj.r.squared) png(filename=paste(outdir,"/",adj_r_sq,"_",mir_name,"_",rna_name,".png", sep=""), width=800, height=800) plot(as.matrix(mir_deltas[mir]), as.matrix(rna_deltas[rna]), col="blue", xlab=paste("delta(ln ",mir_name,")",sep=""), ylab=paste("delta(ln ",rna_name,")",sep=""), main=paste(mir_name," vs. ",rna_name,"(",rna,")\n Adjusted R-squared = ",adj_r_sq, sep="")) abline(fit, col="red") dev.off() } drawbin = function (mir, rna, mir_name, rna_name, outdir) { fit = lm(as.matrix(rna_deltas[rna]) ~ as.matrix(mir_deltas[mir])) adj_r_sq = sprintf("%.3f", summary(fit)$adj.r.squared) png(filename=paste(outdir,"/",adj_r_sq,"_",mir_name,"_",rna_name,".png", sep=""), width=800, height=800) bins = hexbin(as.matrix(mir_deltas[mir]), as.matrix(rna_deltas[rna]), xbin=100, xlab=paste("delta(ln ",mir_name,")",sep=""), ylab=paste("delta(ln ",rna_name,")",sep="")) hplt = plot(bins, main=paste(mir_name," vs. ",rna_name,"(",rna,")\n Adjusted R-squared = ",adj_r_sq, sep="")) pushHexport(hplt$plot.vp) panel.abline(fit, col="red") dev.off() } for (i in c(1:nrow(links))) { mir_name=links[i,1] mir=gsub('-','.',mir_name) #R converts - to . in the mir_delta headers rna=links[i,2] rna=gsub('|','.',rna,fixed=TRUE) #R converts | to . in the rna_delta headers rna_name=links[i,3] rna_name=gsub('|','.',rna_name,fixed=TRUE) #file names doesn't like | neither #drawgraph(mir, rna, mir_name, rna_name, outdir) drawbin(mir, rna, mir_name, rna_name, outdir) }