diff metams.r @ 1:142fbe102a9d draft

Uploaded version 2.0
author yguitton
date Wed, 24 May 2017 07:25:50 -0400
parents 2066efbafd7c
children c75532b75ba1
line wrap: on
line diff
--- a/metams.r	Wed Jul 13 06:46:45 2016 -0400
+++ b/metams.r	Wed May 24 07:25:50 2017 -0400
@@ -1,7 +1,7 @@
 #!/usr/local/public/bin/Rscript --vanilla --slave --no-site-file
-# metams.r version="0.99.9"
+# metams.r version="2.0"
 #created by Yann GUITTON 
-
+#use RI options
 
 #Redirect all stdout to the log file
 log_file=file("metams.log", open = "wt")
@@ -20,13 +20,23 @@
 
 
 listArguments = parseCommandArgs(evaluate=FALSE) #interpretation of arguments given in command line as an R list of objects
-print("new version 8")
+print("new version 2.0")
 
 
 print(listArguments)
- 
+
+
 if (listArguments[["ri"]]!="NULL"){
-    RIarg=read.table(listArguments[["ri"]], h=T)
+    RIarg=read.table(listArguments[["ri"]])
+	if (ncol(RIarg) < 2) RIarg=read.table(listArguments[["ri"]], h=T, sep=";")
+	if (ncol(RIarg) < 2) RIarg=read.table(listArguments[["ri"]], h=T, sep="\t")
+	if (ncol(RIarg) < 2) RIarg=read.table(listArguments[["ri"]], h=T, sep=",")
+	if (ncol(RIarg) < 2) {
+		error_message="Your RI file seems not well formatted. The column separators accepted are ; , and tabulation"
+		print(error_message)
+		stop(error_message)
+	}
+#to do check real column names
     colnames(RIarg)<-c("rt","RI")
     # print(RIarg)
 } else {
@@ -34,26 +44,32 @@
     # cat("Ri= ",RIarg)
 }
 
+if (listArguments[["rishift"]]!="none"){
+    RIshift=listArguments[["rishift"]]
+   cat("Rishift used= ",RIshift, "\n")
+} else {
+    RIshift = "none"
+    cat("Rishift NONE= ",RIshift, "\n")
+}
 
 DBarg=listArguments[["db"]]
 # if (listArguments[["use_db"]]!="NULL"){
 if (DBarg!="NULL"){
     DBarg=listArguments[["db"]]
-    cat("Db= ",DBarg)
+    cat("Db= ",DBarg, "\n")
 } else {
     DBarg = NULL
-    cat("NO Db : ",DBarg)
+    cat("NO Db : ",DBarg, "\n")
 }
 
 
 
-
 #for unknown EIC printing
 
-if (listArguments[["unkn"]]!="NULL") {
+if (listArguments[["unkn"]][1]!="NULL") {
+    unknarg<-listArguments[["unkn"]]
+} else { 
     unknarg<-""
-} else { 
-    unknarg<-listArguments[["unkn"]]
 }
 
 print(paste("Unkn:",unknarg))
@@ -62,6 +78,7 @@
 listArguments[["unkn"]]<-NULL
 listArguments[["db"]] <- NULL
 listArguments[["ri"]] <- NULL
+listArguments[["rishift"]] <- NULL
 
 print(" step2")
 
@@ -164,7 +181,18 @@
 		manual <- read.msp(DBarg)
 		DBarg <- createSTDdbGC(stdInfo = NULL, settings = TSQXLS.GC, manualDB = manual)
 	}
-    nSlaves=listArguments[["nSlaves"]]
+	
+	#use RI instead of rt for time comparison vs DB
+	if (RIshift!="none"){
+		TSQXLS.GC@match2DB.timeComparison<-"RI"
+		TSQXLS.GC@match2DB.RIdiff<-as.numeric(RIshift)
+		TSQXLS.GC@betweenSamples.timeComparison<-"RI"
+		TSQXLS.GC@betweenSamples.RIdiff<-as.numeric(RIshift)
+	}
+	
+   nSlaves=listArguments[["nSlaves"]]
+	
+	
     if(!metams_zip_file=="") {
         resGC<-runGC(files=samples,settings=TSQXLS.GC, rtrange=rtrange, DB= DBarg, removeArtefacts = TRUE, findUnknowns = TRUE, returnXset = TRUE, RIstandards = RIarg, nSlaves = nSlaves) #default settings for GC from Wehrens et al
     }
@@ -189,11 +217,11 @@
 	listArguments[["settings"]]=NULL #delete from the list of arguments
 	fwhmparam=listArguments[["fwhm"]]
 	rtdiffparam=listArguments[["rtdiff"]]
-	#RIdiffparam=listArguments[["RIdiff"]] #only if timeComparison = "RI"
 	minfeatparam=listArguments[["minfeat"]]
 	simthreshparam=listArguments[["simthreshold"]]
     minclassfractionparam=listArguments[["minclassfraction"]]
     minclasssizeparam=listArguments[["minclasssize"]]
+	
     if (listArguments[["rtrange"]]!="NULL") {
         rtrange=listArguments[["rtrange"]]
         cat("rtrange= ",rtrange)
@@ -201,6 +229,8 @@
         rtrange=NULL
         cat("rtrange= ",rtrange)
     }
+	
+	
     nSlaves=listArguments[["nSlaves"]]
 	
 	GALAXY.GC <- metaMSsettings("protocolName" = "GALAXY.GC",
@@ -227,13 +257,16 @@
 				rtdiff = rtdiffparam,
 				RIdiff = 5,
 				minfeat = minfeatparam)
-    #to be used when DB option will be available
-	# metaSetting(GALAXY.GC, "matchIrrelevants") <- list(
-				# irrelevantClasses = c("Bleeding", "Plasticizers"),
-				# timeComparison = "rt",
-				# RIdiff = 2,    
-				# rtdiff = rtdiffparam,
-				# simthresh = simthreshparam)
+				
+    #to used if contaminant filter
+	
+		# metaSetting(GALAXY.GC, "matchIrrelevants") <- list(
+					# irrelevantClasses = c("Bleeding", "Plasticizers"),
+					# timeComparison = "RI",
+					# RIdiff = RIdiffparam,    
+					# rtdiff = rtdiffparam,
+					# simthresh = simthreshparam)
+	
 	metaSetting(GALAXY.GC, "betweenSamples") <- list(
 				min.class.fraction = minclassfractionparam,
 				min.class.size = minclasssizeparam,
@@ -242,7 +275,13 @@
 				RIdiff = 2,    
 				simthresh = simthreshparam)
 
-	
+	#ONLY use RI instead of rt for time comparison vs DB or samples
+	if (RIshift!="none"){
+		GALAXY.GC@match2DB.timeComparison<-"RI"
+		GALAXY.GC@match2DB.RIdiff<-as.numeric(RIshift)
+		GALAXY.GC@betweenSamples.timeComparison<-"RI"
+		GALAXY.GC@betweenSamples.RIdiff<-as.numeric(RIshift)
+	}
         # files, xset, settings, rtrange = NULL, DB = NULL,
        # removeArtefacts = TRUE, findUnknowns = nexp > 1,
        # returnXset = FALSE, RIstandards = NULL, nSlaves = 0
@@ -302,6 +341,7 @@
        
 print("Step QC plot")
 
+#to do check if no peaks found
 #Quality controls plots but only working in R (don't know why)
 a<-plotUnknowns(resGC=resGC, unkn=unknarg) #use unknparam value