diff extractCN.R @ 4:3fcbb8030fcc draft

"planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 40eda5ea3551e8b3bae32d0a8f405fe90ef22646-dirty"
author sblanck
date Mon, 12 Apr 2021 14:47:09 +0000
parents 4d539083cf7f
children
line wrap: on
line diff
--- a/extractCN.R	Tue Jun 16 04:34:09 2020 -0400
+++ b/extractCN.R	Mon Apr 12 14:47:09 2021 +0000
@@ -3,14 +3,16 @@
 options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } )
 
 # we need that to not crash galaxy with an UTF8 error on German LC settings.
-loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
+# loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
 
 library("optparse")
+library("zip")
 
 ##### Read options
 option_list=list(
 		make_option("--chrom",type="character",default=NULL, dest="chrom"),
 		make_option("--input",type="character",default=NULL, dest="input"),
+		make_option("--zip",type="character",default=NULL, dest="zip"),
 		make_option("--output",type="character",default=NULL, dest="output"),
 		make_option("--new_file_path",type="character",default=NULL, dest="new_file_path"),
 		make_option("--settings_type",type="character",default=NULL, dest="settings_type"),
@@ -35,6 +37,7 @@
 
 chrom=opt$chrom
 input=opt$input
+zip=opt$zip
 tmp_dir=opt$new_file_path
 output=opt$output
 settingsType=opt$settings_type
@@ -47,9 +50,24 @@
 user=opt$userid
 
 library(MPAgenomics)
-workdir=file.path(tmp_dir, "mpagenomics",user)
+library(aroma.affymetrix)
+library(R.utils)
+#workdir=file.path(tmp_dir, "mpagenomics",user)
+tmp_dir
+tmp_dir=file.path(tmp_dir)
+if (!dir.exists(tmp_dir))
+  dir.create(tmp_dir, showWarnings = TRUE, recursive = TRUE)
+setwd(tmp_dir)
+# tmpzip=file.copy(from = zip,to=paste0(workdir,"/tmp.zip"))
+# tmpzip
+unzip(zipfile = zip,exdir = ".")
+# if (file.exists(tmpzip)) {
+#   #Delete file if it exists
+#   file.remove(fn)
+# }
+
+workdir=file.path(tmp_dir,user)
 setwd(workdir)
-
 inputDataset=read.table(file=input,stringsAsFactors=FALSE)
 dataset=inputDataset[1,2]
 
@@ -75,7 +93,7 @@
 			CN=getCopyNumberSignal(dataset,chromosome=chrom_vec, onlySNP=snp)
 					
 	  	} else {
-	  		CN=getCopyNumberSignal(dataset,chromosome=chrom_vec, normalTumorArray=tumorcsv, onlySNP=snp)
+	  	CN=getCopyNumberSignal(dataset,chromosome=chrom_vec, normalTumorArray=tumorcsv, onlySNP=snp)
 	  	}
 	} else {
 		input_tmp <- strsplit(settingsType,",")
@@ -109,7 +127,9 @@
 		}
 		
 		symFracB_global=data.frame(check.names = FALSE)
-		
+		tumorFile=read.csv(tumorcsv,header=TRUE)
+		tumor=tumorFile$tumor
+		input_vecstring=input_vecstring[which(input_vecstring %in% tumor)]
 		for (currentFile in input_vecstring) {
 			cat(paste0("extracting signal from ",currentFile,".\n"))
 			currentSymFracB=data.frame()
@@ -124,7 +144,11 @@
 			if (is.null(symFracB_global) || nrow(symFracB_global)==0) {
 				symFracB_global=currentSymFracB
 			} else {
-				symFracB_global=cbind(symFracB_global,currentFile=currentSymFracB[[3]])
+				#symFracB_global=cbind(symFracB_global,currentFile=currentSymFracB[[3]])
+				
+				symFracB_global=merge(symFracB_global,currentSymFracB[,c(3,4)],by="featureNames")
+				symFracB_global=symFracB_global[c(2:ncol(symFracB_global),1)]
+				symFracB_global=symFracB_global[order(symFracB_global$chromosome, symFracB_global$position),]
 			}
 		}
 		names(symFracB_global)[names(symFracB_global)=="featureNames"] <- "probeName"
@@ -163,8 +187,11 @@
 	
 }
 
+if (dir.exists(workdir))
+  system(paste0("rm -r ", workdir))
+
 if (outputlog){
 	sink(type="output")
 	sink(type="message")
 	close(sinklog)
-} 
\ No newline at end of file
+}