def splot(datafn, plotfn, format): tf2 = tempfile.NamedTemporaryFile() o2 = open(tf2.name, "w") o2.write(plot.plot_format("%s.scatter" % (plotfn), format)) o2.write(""" d = as.matrix(read.table("%s")) par(mfrow=c(3,1), oma=c(2, 0, 3, 0), omi=c(0, 0, 0.8, 0)) plot(d[,2], d[,1], ylab="Posterior probability", xlab="BLAST score") plot(d[,3], d[,1], ylab="Posterior probability", xlab="GTG score") plot(d[,2], d[,3], xlab="BLAST score", ylab="GTG score") dev.off() """ % (datafn)) o2.write(plot.plot_format("%s.density" % (plotfn), format)) o2.write(""" par(mfrow=c(3,1), oma=c(2, 0, 3, 0), omi=c(0, 0, 0.8, 0)) plot(density(d[,1], from=0, to=1), xlab = "Posterior probability", main = "") plot(density(d[,2], from=0, to=max(d[,2])), xlab = "BLAST score", main = "") plot(density(d[,3], from=0, to=max(d[,3])), xlab = "GTG score", main = "") """) o2.write(plot.plot_format("%s.full-vs-naive" % (plotfn), format)) o2.write(""" par(mfrow=c(2,1), oma=c(2, 0, 3, 0), omi=c(0, 0, 0.8, 0)) plot(d[,1], d[,4], xlab = "Posterior, full model", ylab = "Posterior, naive model", main = "") plot(density(d[,5], from=min(d[,5]), to=max(d[,5])), xlab = "Log ratio, full vs naive", main = "") """) o2.flush() subprocess.call("R CMD BATCH %s" % (tf2.name), shell=True) o2.close()
def splot(datafn, plotfn, format): tf2 = tempfile.NamedTemporaryFile() o2 = open(tf2.name, "w") o2.write(plot.plot_format("%s.scatter" % (plotfn), format)) o2.write(""" d = as.matrix(read.table("%s")) par(mfrow=c(3,1), oma=c(2, 0, 3, 0), omi=c(0, 0, 0.8, 0)) plot(d[,2], d[,1], ylab="Posterior probability", xlab="BLAST score") plot(d[,3], d[,1], ylab="Posterior probability", xlab="GTG score") plot(d[,2], d[,3], xlab="BLAST score", ylab="GTG score") dev.off() """ % (datafn)) o2.write(plot.plot_format("%s.density" % (plotfn), format)) o2.write(""" par(mfrow=c(3,1), oma=c(2, 0, 3, 0), omi=c(0, 0, 0.8, 0)) plot(density(d[,1], from=0, to=1), xlab = "Posterior probability", main = "") plot(density(d[,2], from=0, to=max(d[,2])), xlab = "BLAST score", main = "") plot(density(d[,3], from=0, to=max(d[,3])), xlab = "GTG score", main = "") """) o2.write(plot.plot_format("%s.full-vs-naive" % (plotfn), format)) o2.write(""" par(mfrow=c(2,1), oma=c(2, 0, 3, 0), omi=c(0, 0, 0.8, 0)) plot(d[,1], d[,4], xlab = "Posterior, full model", ylab = "Posterior, naive model", main = "") plot(density(d[,5], from=min(d[,5]), to=max(d[,5])), xlab = "Log ratio, full vs naive", main = "") """) o2.flush() subprocess.call("R CMD BATCH %s" % (tf2.name), shell = True) o2.close()
def plot_single(ddir, species, roc_dir, format="pdf"): of = tempfile.NamedTemporaryFile() plotfn = "%s/%s/%s" % (ddir, roc_dir, species) fn1 = "%s/%s/%s.full" % (ddir, roc_dir, species) fn2 = "%s/%s/%s.naive" % (ddir, roc_dir, species) fn3 = "%s/%s/%s.blast" % (ddir, roc_dir, species) fn4 = "%s/%s/%s.gtg" % (ddir, roc_dir, species) fn5 = "%s/%s/%s.blasttree" % (ddir, roc_dir, species) fn6 = "%s/%s/%s.gtgtree" % (ddir, roc_dir, species) of.write(plot.plot_format(plotfn, format)) of.write(""" full = read.table("%s") naive = read.table("%s") blast = read.table("%s") gtg = read.table("%s") btree = read.table("%s") gtree = read.table("%s") plot(full[,2], full[,3], type="l", xlab="False positive rate", ylab="True positive rate") lines(naive[,2], naive[,3], type="l", pch=22, lty=1, col="red") lines(blast[,2], blast[,3], type="l", pch=22, lty=2, col="blue") lines(gtg[,2], gtg[,3], type="l", pch=22, lty=2, col="green") lines(btree[,2], btree[,3], type="l", pch=22, lty=1, col="purple") lines(gtree[,2], gtree[,3], type="l", pch=22, lty=1, col="orange") lines(c(0,1), c(0,1)) legend("bottomright", c("Full","Naive","BLAST","GTG", "BlastTree", "GTGTree"), cex=0.8, col=c("black","red","blue","green","purple","orange"), pch=c(21,21,21,21,21,21), lty=c(1,1,2,2,1,1), inset=0.01) dev.off() """ % (fn1, fn2, fn3, fn4, fn5, fn6)) plotfn2 = "%s/%s/%s-F1" % (ddir, roc_dir, species) of.write(plot.plot_format(plotfn2, format)) of.write(""" plot(full[3:nrow(full)-1,1], full[3:nrow(full)-1,4], type="l", ylim=c(0,1), xlab="Normalized score", ylab="") lines(naive[3:nrow(naive)-1,1], naive[3:nrow(naive)-1,4], col="red", lty=1) lines(blast[3:nrow(blast)-1,1] / max(blast[,1]), blast[3:nrow(blast)-1,4], col="blue", lty=2) lines(gtg[3:nrow(gtg)-1,1], gtg[3:nrow(gtg)-1,4], col="green", lty=2) lines(btree[3:nrow(btree)-1,1], btree[3:nrow(btree)-1,4], col="purple", lty=1) lines(gtree[3:nrow(gtree)-1,1], gtree[3:nrow(gtree)-1,4], col="orange", lty=1) legend("bottomleft", c("Full","Naive","BLAST","GTG","BlastTree","GTGTree"), cex=0.8, col=c("black","red","blue","green","purple","orange"), pch=c(21,21,21,21,21,21), lty=c(1,1,2,2,1,1), inset=0.01) dev.off() """) #par(mfrow=c(2,2), oma=c(2, 0, 3, 0), omi=c(0, 0, 0.8, 0)) # plot(naive[3:nrow(naive)-1,1], naive[3:nrow(naive)-1,4], ylim=c(0,1), type="l", xlab="Posterior probability, naive model", ylab="F1 score") # plot(blast[3:nrow(blast)-1,1] / max(blast[,1]), blast[3:nrow(blast)-1,4], ylim=c(0,1), type="l", xlab="BLAST score", ylab="F1 score") # plot(gtg[3:nrow(gtg)-1,1], gtg[3:nrow(gtg)-1,4], ylim=c(0,1), type="l", xlab="GTG score", ylab="F1 score") plotfn3 = "%s/%s/%s-sens" % (ddir, roc_dir, species) of.write(plot.plot_format(plotfn3, format)) of.write(""" plot(full[1:nrow(full),1], full[1:nrow(full),3], type="l", ylim=c(0,1), xlab="Normalized score", ylab="Sensitivity") lines(naive[1:nrow(naive),1], naive[1:nrow(naive),3], col="red", lty=1) lines(blast[1:nrow(blast),1] / max(blast[,1]), blast[1:nrow(blast),3], col="blue", lty=2) lines(gtg[1:nrow(gtg),1], gtg[1:nrow(gtg),3], col="green", lty=2) lines(btree[1:nrow(btree),1], btree[1:nrow(btree),3], col="purple", lty=1) lines(gtree[1:nrow(gtree),1], gtree[1:nrow(gtree),3], col="orange", lty=1) legend("bottomleft", c("Full","Naive","BLAST","GTG","BlastTree","GTGTree"), cex=0.8, col=c("black","red","blue","green","purple","orange"), pch=c(21,21,21,21,21,21), lty=c(1,1,2,2,1,1), inset=0.01) dev.off() """) plotfn4 = "%s/%s/%s-spec" % (ddir, roc_dir, species) of.write(plot.plot_format(plotfn4, format)) of.write(""" plot(full[1:nrow(full),1], full[1:nrow(full),5], type="l", ylim=c(0,1), lty=2, xlab="Normalized score", ylab="Specificity") lines(naive[1:nrow(naive),1], naive[1:nrow(naive),5], col="red", lty=2) lines(blast[1:nrow(blast),1] / max(blast[,1]), blast[1:nrow(blast),5], col="blue", lty=2) lines(gtg[1:nrow(gtg),1], gtg[1:nrow(gtg),5], col="green", lty=2) lines(btree[1:nrow(btree),1], btree[1:nrow(btree),5], col="purple", lty=2) lines(gtree[1:nrow(gtree),1], gtree[1:nrow(gtree),5], col="orange", lty=2) legend("bottomleft", c("Full","Naive","BLAST","GTG","BlastTree","GTGTree"), cex=0.8, col=c("black","red","blue","green","purple","orange"), pch=c(21,21,21,21,21,21), lty=c(1,1,1,1,1,1), inset=0.01) dev.off() """) of.flush() subprocess.call("R CMD BATCH %s" % (of.name), shell=True)
def plot_single(ddir, species, roc_dir, format = "pdf"): of = tempfile.NamedTemporaryFile() plotfn = "%s/%s/%s" % (ddir, roc_dir, species) fn1 = "%s/%s/%s.full" % (ddir, roc_dir, species) fn2 = "%s/%s/%s.naive" % (ddir, roc_dir, species) fn3 = "%s/%s/%s.blast" % (ddir, roc_dir, species) fn4 = "%s/%s/%s.gtg" % (ddir, roc_dir, species) fn5 = "%s/%s/%s.blasttree" % (ddir, roc_dir, species) fn6 = "%s/%s/%s.gtgtree" % (ddir, roc_dir, species) of.write(plot.plot_format(plotfn, format)) of.write(""" full = read.table("%s") naive = read.table("%s") blast = read.table("%s") gtg = read.table("%s") btree = read.table("%s") gtree = read.table("%s") plot(full[,2], full[,3], type="l", xlab="False positive rate", ylab="True positive rate") lines(naive[,2], naive[,3], type="l", pch=22, lty=1, col="red") lines(blast[,2], blast[,3], type="l", pch=22, lty=2, col="blue") lines(gtg[,2], gtg[,3], type="l", pch=22, lty=2, col="green") lines(btree[,2], btree[,3], type="l", pch=22, lty=1, col="purple") lines(gtree[,2], gtree[,3], type="l", pch=22, lty=1, col="orange") lines(c(0,1), c(0,1)) legend("bottomright", c("Full","Naive","BLAST","GTG", "BlastTree", "GTGTree"), cex=0.8, col=c("black","red","blue","green","purple","orange"), pch=c(21,21,21,21,21,21), lty=c(1,1,2,2,1,1), inset=0.01) dev.off() """ % (fn1, fn2, fn3, fn4, fn5, fn6)) plotfn2 = "%s/%s/%s-F1" % (ddir, roc_dir, species) of.write(plot.plot_format(plotfn2, format)) of.write(""" plot(full[3:nrow(full)-1,1], full[3:nrow(full)-1,4], type="l", ylim=c(0,1), xlab="Normalized score", ylab="") lines(naive[3:nrow(naive)-1,1], naive[3:nrow(naive)-1,4], col="red", lty=1) lines(blast[3:nrow(blast)-1,1] / max(blast[,1]), blast[3:nrow(blast)-1,4], col="blue", lty=2) lines(gtg[3:nrow(gtg)-1,1], gtg[3:nrow(gtg)-1,4], col="green", lty=2) lines(btree[3:nrow(btree)-1,1], btree[3:nrow(btree)-1,4], col="purple", lty=1) lines(gtree[3:nrow(gtree)-1,1], gtree[3:nrow(gtree)-1,4], col="orange", lty=1) legend("bottomleft", c("Full","Naive","BLAST","GTG","BlastTree","GTGTree"), cex=0.8, col=c("black","red","blue","green","purple","orange"), pch=c(21,21,21,21,21,21), lty=c(1,1,2,2,1,1), inset=0.01) dev.off() """) #par(mfrow=c(2,2), oma=c(2, 0, 3, 0), omi=c(0, 0, 0.8, 0)) # plot(naive[3:nrow(naive)-1,1], naive[3:nrow(naive)-1,4], ylim=c(0,1), type="l", xlab="Posterior probability, naive model", ylab="F1 score") # plot(blast[3:nrow(blast)-1,1] / max(blast[,1]), blast[3:nrow(blast)-1,4], ylim=c(0,1), type="l", xlab="BLAST score", ylab="F1 score") # plot(gtg[3:nrow(gtg)-1,1], gtg[3:nrow(gtg)-1,4], ylim=c(0,1), type="l", xlab="GTG score", ylab="F1 score") plotfn3 = "%s/%s/%s-sens" % (ddir, roc_dir, species) of.write(plot.plot_format(plotfn3, format)) of.write(""" plot(full[1:nrow(full),1], full[1:nrow(full),3], type="l", ylim=c(0,1), xlab="Normalized score", ylab="Sensitivity") lines(naive[1:nrow(naive),1], naive[1:nrow(naive),3], col="red", lty=1) lines(blast[1:nrow(blast),1] / max(blast[,1]), blast[1:nrow(blast),3], col="blue", lty=2) lines(gtg[1:nrow(gtg),1], gtg[1:nrow(gtg),3], col="green", lty=2) lines(btree[1:nrow(btree),1], btree[1:nrow(btree),3], col="purple", lty=1) lines(gtree[1:nrow(gtree),1], gtree[1:nrow(gtree),3], col="orange", lty=1) legend("bottomleft", c("Full","Naive","BLAST","GTG","BlastTree","GTGTree"), cex=0.8, col=c("black","red","blue","green","purple","orange"), pch=c(21,21,21,21,21,21), lty=c(1,1,2,2,1,1), inset=0.01) dev.off() """) plotfn4 = "%s/%s/%s-spec" % (ddir, roc_dir, species) of.write(plot.plot_format(plotfn4, format)) of.write(""" plot(full[1:nrow(full),1], full[1:nrow(full),5], type="l", ylim=c(0,1), lty=2, xlab="Normalized score", ylab="Specificity") lines(naive[1:nrow(naive),1], naive[1:nrow(naive),5], col="red", lty=2) lines(blast[1:nrow(blast),1] / max(blast[,1]), blast[1:nrow(blast),5], col="blue", lty=2) lines(gtg[1:nrow(gtg),1], gtg[1:nrow(gtg),5], col="green", lty=2) lines(btree[1:nrow(btree),1], btree[1:nrow(btree),5], col="purple", lty=2) lines(gtree[1:nrow(gtree),1], gtree[1:nrow(gtree),5], col="orange", lty=2) legend("bottomleft", c("Full","Naive","BLAST","GTG","BlastTree","GTGTree"), cex=0.8, col=c("black","red","blue","green","purple","orange"), pch=c(21,21,21,21,21,21), lty=c(1,1,1,1,1,1), inset=0.01) dev.off() """) of.flush() subprocess.call("R CMD BATCH %s" % (of.name), shell = True)