Created
March 5, 2012 17:57
-
-
Save seandavi/1979862 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env Rscript | |
| suppressPackageStartupMessages(library("optparse")) | |
| # specify our desired options in a list | |
| # by default OptionParser will add an help option equivalent to | |
| # make_option(c("-h", "--help"), action="store_true", default=FALSE, | |
| # help="Show this help message and exit") | |
| option_list <- list( | |
| make_option(c("-m", "--metrics"), default=".dupmetrics", | |
| help="The file pattern to match (in dir) for finding hsmetrics files [default %default]", | |
| metavar="metrics"), | |
| make_option(c("-o","--outprefix"), default="dupmetrics", | |
| help="The output file prefix [default %default]; pdf, a bunch of pngs, and a text file of all samples will be generated with this prefix") | |
| ) | |
| # get command line options, if help option encountered print help and exit, | |
| # otherwise if options not found on command line then set | |
| parser <- OptionParser(usage = "%prog [options] directory_for_dupmetrics", option_list=option_list) | |
| args <- parse_args(parser,positional_arguments=TRUE) | |
| opts <- args$options | |
| if(length(args$args)!=1) { | |
| stop("We require the directory of the dupmetrics files as an argument") | |
| } | |
| metdirectory=args$args[1] | |
| fnames=dir(metdirectory,pattern=opts$metrics) | |
| tmp=do.call('rbind',sapply(dir(metdirectory,pattern=opts$metrics), | |
| function(x) { | |
| tmp1=read.table(file.path(metdirectory,x),nrows=1,header=TRUE,sep="\t") | |
| print(x) | |
| print(dim(tmp1)) | |
| return(tmp1) | |
| },simplify=FALSE)) | |
| tmp2=sapply(strsplit(fnames,'\\.'),function(x) {return(x[1])}) | |
| dtable = data.frame(sample=tmp2,tmp) | |
| rownames(dtable)=tmp2 | |
| write.table(dtable,paste(opts$outprefix,'.txt',sep=""),col.names=TRUE, | |
| row.names=FALSE,quote=FALSE,sep="\t") | |
| #summaryTable = apply(dtable[,-1],2,sum) | |
| #summaryTable = data.frame(KeyName=names(summaryTable),Value=summaryTable) | |
| #write.table(summaryTable,paste(opts$outprefix,'.summary.txt',sep=""),col.names=TRUE, | |
| # row.names=FALSE,quote=FALSE,sep="\t") | |
| pdf(paste(opts$outprefix,'.pdf',sep=""),width=11,height=8) | |
| par(las=2,mar=c(15,4,2,2),cex=0.5) | |
| for(i in colnames(dtable)[3:ncol(dtable)]){ | |
| barplot(dtable[,i],main=i,names.arg=tmp2) | |
| } | |
| dev.off() | |
| print('done') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment