diff GEOQuery.R @ 4:2c9e44ff68dc draft

use optparse
author sblanck
date Wed, 12 Apr 2017 03:44:54 -0400
parents 93451f832736
children
line wrap: on
line diff
--- a/GEOQuery.R	Wed Apr 12 03:44:02 2017 -0400
+++ b/GEOQuery.R	Wed Apr 12 03:44:54 2017 -0400
@@ -1,17 +1,40 @@
+#!/usr/bin/env Rscript
+# setup R error handling to go to stderr
+options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } )
 
-library(GEOquery)
+# we need that to not crash galaxy with an UTF8 error on German LC settings.
+loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
+
+library("optparse")
 
-
-cargs<-commandArgs()
-cargs<-cargs[(which(cargs=="--args")+1):length(cargs)]
+##### Read options
+option_list=list(
+		make_option("--id",type="character",default=NULL,help="GSE ID from GEO databse (required)"),
+		make_option("--transformation",type="character",default=NULL,help="log2 transformation (required)"),
+		make_option("--data",type="character",default=NULL,help="A table containing the expression data"),
+		make_option("--rdata",type="character",default="NULL",help="rdata object containing eset object"),
+		make_option("--conditions",type="character",default=NULL,help="Text file summarizing conditions of the experiment")
+		
+);
 
-GEOQueryID<-cargs[[1]]
-GEOQueryData<-cargs[[2]]
-GEOQueryRData<-cargs[[3]]
-conditionFile<-cargs[[4]]
-transformation<-cargs[[5]]
+opt_parser = OptionParser(option_list=option_list);
+opt = parse_args(opt_parser);
+
+if(is.null(opt$id)){
+	print_help(opt_parser)
+	stop("GEOdata id required.", call.=FALSE)
+}
 
-data1 = getGEO(GEOQueryID)
+#loading libraries
+suppressPackageStartupMessages(require(GEOquery))
+
+GEOQueryID=opt$id
+GEOQueryData=opt$data
+GEOQueryRData=opt$rdata
+conditionFile=opt$conditions
+transformation=opt$transformation
+
+data1=getGEO(GEOQueryID)
 eset=data1[[1]]
 
 #check if datas are in log2 space