#Script to generate AUC analyses and plots using package ROCR
#input: analysis file in format score <tab> case

###----------------------------


library(ROCR) 
library("stringr")

setwd("input")
tflist <- list.files()

for (i in 1:length(tflist)) {
	tfname <- tflist[[i]]
	tfname <- str_sub(tfname, 6, -5)
	input <- read.table(tflist[[i]], sep="\t",header=T)
	pred <- prediction(input$score, input$case)
	perf <- performance(pred, "tpr", "fpr")
	filename <- paste("output.png", sep="")
	png(filename, 400, 300)
	plot(perf, col="red", main=tfname)
	auc0 <- performance(pred,"auc")
	auc0 <- unlist(slot(auc0, "y.values"))
	auc0 <- min(round(auc0, digits = 2))
	auc0 <- paste(c("AUC = "),auc0,sep="")
	legend(0.7, 0.1, auc0, lty=1, lwd=2.5, col="red", bty='n', cex=.75)
	graphics.off()
}
graphics.off()

