diff QDNAseq.R @ 72:fb2dfd8ba417 draft

Uploaded
author stef
date Fri, 05 Sep 2014 11:10:27 -0400
parents b4477584bb03
children 4db025c51b6e
line wrap: on
line diff
--- a/QDNAseq.R	Wed Aug 27 04:56:37 2014 -0400
+++ b/QDNAseq.R	Fri Sep 05 11:10:27 2014 -0400
@@ -38,6 +38,8 @@
 	l1 <- length(paths)
 	l2 <- length(names)
 	if ( l1 != l2 ) stop( "Unequal amount of bam-paths (", l1, ") and -names (", l2, ") in makeBamFileList!!!\n" )
+	if ( l1 == 0 ){ return(tmp) } # empty list in debug mode
+
 	for ( i in 1:length(paths) ){
 		path <- paths[i]
 		name <- names[i]
@@ -155,9 +157,6 @@
 
 ## desparate tries to make png text scale well, damn you R...!
 PLOT_RES  <- min( PLOT_WIDTH, PLOT_HEIGHT ) / 6.3 
-#PLOT_PS <- min( PLOT_WIDTH, PLOT_HEIGHT ) / 40
-#TXT_FACTOR <- PLOT_WIDTH/480
-#PAR_SET   <- list( pch=22, cex.lab=TXT_FACTOR, cex.main=TXT_FACTOR )
 PAR_SET   <- list( pch=22 )
 
 systemUser <- system("whoami",T)
@@ -176,8 +175,8 @@
 ## ------------------------
 ## DEBUG
 if ( debug ){
-	catMsg( c("Analysis run under user: ", systemUser ) )
-	catMsg( c("Here comes sessionInfo: " ) )
+	catMsg( c("Analysis run by user: ", systemUser ) )
+	catMsg( c("DEBUG SessionInfo: " ) )
 	print( sessionInfo() )
 }
 ## /DEBUG
@@ -189,7 +188,9 @@
 }
 
 ## copy source config file to output dir to include it in output zip
-file.copy( config, paste(outputPath, 'galaxyConfigFile.R', sep='/') )
+if ( inGalaxy ){
+	file.copy( config, paste(outputPath, 'galaxyConfigFile.R', sep='/') )	
+}
 
 ## setup bam filelist for easy retrieval later
 fileList    <- makeBamFileList( bamsPaths, bamsNames )
@@ -233,7 +234,13 @@
 	igvCopyNrPath  <- paste( outputPath, '/', igvCopyNrName, sep='')
 	noiseImgPath   <- paste( outputPath, '/', noiseImgName, sep='')
 
-	binAnnotations <- getBinAnnotations( binSize=binSize, type=experimentType )
+	binAnnFile <- paste( TOOL_PATH, '/static/binannotation/', binSize, 'kbp_binAnnotations.rds', sep="" )
+	if ( file.exists(binAnnFile) ){
+		binAnnotations <- readRDS( binAnnFile )
+		catMsg( c("Using local binAnnotations file" ) )
+	}else{
+		binAnnotations <- getBinAnnotations( binSize=binSize, type=experimentType )
+	}
 
 	## in case of debug just use inbuilt LGG data for speedup
 	if ( debug ){
@@ -493,8 +500,9 @@
 ## ------------------------
 ## creating main html output for galaxy history
 ## ------------------------
-sink( file = outputHtml, type = "output" )
-		
+if ( inGalaxy ){ # dont create when running outside Galaxy
+	sink( file = outputHtml, type = "output" )
+			
 		cat( "<head>", "\n")
 			cat( "\t", '<link rel="stylesheet" href="', PURE_CSS, '">', "\n", sep='' )
 
@@ -509,7 +517,8 @@
 		cat( '<p>Explore <a href="', htmlOutputName, '" class="button">the results</a> directly within galaxy</p>', "\n", sep="")
 		cat( '<p>Or download a <a href="', gzipOutputName, '" class="button">zipfile</a> with all output (', zippedSize, ')</p>', "\n", sep="" )
 
-sink()
+	sink()
+}
 
 ## ------------------------
 ## create final zip and quit with status 0 to tell galaxy all was fine