comparison QDNAseq.R @ 72:fb2dfd8ba417 draft

Uploaded
author stef
date Fri, 05 Sep 2014 11:10:27 -0400
parents b4477584bb03
children 4db025c51b6e
comparison
equal deleted inserted replaced
71:a93649056969 72:fb2dfd8ba417
36 makeBamFileList <- function( paths, names ){ 36 makeBamFileList <- function( paths, names ){
37 tmp <- list() 37 tmp <- list()
38 l1 <- length(paths) 38 l1 <- length(paths)
39 l2 <- length(names) 39 l2 <- length(names)
40 if ( l1 != l2 ) stop( "Unequal amount of bam-paths (", l1, ") and -names (", l2, ") in makeBamFileList!!!\n" ) 40 if ( l1 != l2 ) stop( "Unequal amount of bam-paths (", l1, ") and -names (", l2, ") in makeBamFileList!!!\n" )
41 if ( l1 == 0 ){ return(tmp) } # empty list in debug mode
42
41 for ( i in 1:length(paths) ){ 43 for ( i in 1:length(paths) ){
42 path <- paths[i] 44 path <- paths[i]
43 name <- names[i] 45 name <- names[i]
44 file <- basename(path) 46 file <- basename(path)
45 47
153 ## many variables are imported via sourced "config" 155 ## many variables are imported via sourced "config"
154 source( config ) 156 source( config )
155 157
156 ## desparate tries to make png text scale well, damn you R...! 158 ## desparate tries to make png text scale well, damn you R...!
157 PLOT_RES <- min( PLOT_WIDTH, PLOT_HEIGHT ) / 6.3 159 PLOT_RES <- min( PLOT_WIDTH, PLOT_HEIGHT ) / 6.3
158 #PLOT_PS <- min( PLOT_WIDTH, PLOT_HEIGHT ) / 40
159 #TXT_FACTOR <- PLOT_WIDTH/480
160 #PAR_SET <- list( pch=22, cex.lab=TXT_FACTOR, cex.main=TXT_FACTOR )
161 PAR_SET <- list( pch=22 ) 160 PAR_SET <- list( pch=22 )
162 161
163 systemUser <- system("whoami",T) 162 systemUser <- system("whoami",T)
164 qdnaseqVersion <- packageDescription( "QDNAseq" )$Version 163 qdnaseqVersion <- packageDescription( "QDNAseq" )$Version
165 rVersion <- R.version.string 164 rVersion <- R.version.string
174 173
175 174
176 ## ------------------------ 175 ## ------------------------
177 ## DEBUG 176 ## DEBUG
178 if ( debug ){ 177 if ( debug ){
179 catMsg( c("Analysis run under user: ", systemUser ) ) 178 catMsg( c("Analysis run by user: ", systemUser ) )
180 catMsg( c("Here comes sessionInfo: " ) ) 179 catMsg( c("DEBUG SessionInfo: " ) )
181 print( sessionInfo() ) 180 print( sessionInfo() )
182 } 181 }
183 ## /DEBUG 182 ## /DEBUG
184 ## ------------------------ 183 ## ------------------------
185 184
187 if ( !file.exists( outputPath) ){ 186 if ( !file.exists( outputPath) ){
188 dir.create( outputPath ) 187 dir.create( outputPath )
189 } 188 }
190 189
191 ## copy source config file to output dir to include it in output zip 190 ## copy source config file to output dir to include it in output zip
192 file.copy( config, paste(outputPath, 'galaxyConfigFile.R', sep='/') ) 191 if ( inGalaxy ){
192 file.copy( config, paste(outputPath, 'galaxyConfigFile.R', sep='/') )
193 }
193 194
194 ## setup bam filelist for easy retrieval later 195 ## setup bam filelist for easy retrieval later
195 fileList <- makeBamFileList( bamsPaths, bamsNames ) 196 fileList <- makeBamFileList( bamsPaths, bamsNames )
196 bamCount <- length( fileList[[ 'all_paths' ]] ) 197 bamCount <- length( fileList[[ 'all_paths' ]] )
197 198
231 robjSegmntPath <- paste( outputPath, '/', robjSegmntName, sep='') 232 robjSegmntPath <- paste( outputPath, '/', robjSegmntName, sep='')
232 robjRegionPath <- paste( outputPath, '/', regiOutputName, sep='') 233 robjRegionPath <- paste( outputPath, '/', regiOutputName, sep='')
233 igvCopyNrPath <- paste( outputPath, '/', igvCopyNrName, sep='') 234 igvCopyNrPath <- paste( outputPath, '/', igvCopyNrName, sep='')
234 noiseImgPath <- paste( outputPath, '/', noiseImgName, sep='') 235 noiseImgPath <- paste( outputPath, '/', noiseImgName, sep='')
235 236
236 binAnnotations <- getBinAnnotations( binSize=binSize, type=experimentType ) 237 binAnnFile <- paste( TOOL_PATH, '/static/binannotation/', binSize, 'kbp_binAnnotations.rds', sep="" )
238 if ( file.exists(binAnnFile) ){
239 binAnnotations <- readRDS( binAnnFile )
240 catMsg( c("Using local binAnnotations file" ) )
241 }else{
242 binAnnotations <- getBinAnnotations( binSize=binSize, type=experimentType )
243 }
237 244
238 ## in case of debug just use inbuilt LGG data for speedup 245 ## in case of debug just use inbuilt LGG data for speedup
239 if ( debug ){ 246 if ( debug ){
240 data(LGG150) 247 data(LGG150)
241 readCounts <- LGG150 248 readCounts <- LGG150
491 sink() 498 sink()
492 499
493 ## ------------------------ 500 ## ------------------------
494 ## creating main html output for galaxy history 501 ## creating main html output for galaxy history
495 ## ------------------------ 502 ## ------------------------
496 sink( file = outputHtml, type = "output" ) 503 if ( inGalaxy ){ # dont create when running outside Galaxy
497 504 sink( file = outputHtml, type = "output" )
505
498 cat( "<head>", "\n") 506 cat( "<head>", "\n")
499 cat( "\t", '<link rel="stylesheet" href="', PURE_CSS, '">', "\n", sep='' ) 507 cat( "\t", '<link rel="stylesheet" href="', PURE_CSS, '">', "\n", sep='' )
500 508
501 cat( "<style>", "\n") 509 cat( "<style>", "\n")
502 ## include CSS directly into html file 510 ## include CSS directly into html file
507 515
508 cat( '<h1>QDNAseq Results (', outputName,')</h1>', "\n", sep="") 516 cat( '<h1>QDNAseq Results (', outputName,')</h1>', "\n", sep="")
509 cat( '<p>Explore <a href="', htmlOutputName, '" class="button">the results</a> directly within galaxy</p>', "\n", sep="") 517 cat( '<p>Explore <a href="', htmlOutputName, '" class="button">the results</a> directly within galaxy</p>', "\n", sep="")
510 cat( '<p>Or download a <a href="', gzipOutputName, '" class="button">zipfile</a> with all output (', zippedSize, ')</p>', "\n", sep="" ) 518 cat( '<p>Or download a <a href="', gzipOutputName, '" class="button">zipfile</a> with all output (', zippedSize, ')</p>', "\n", sep="" )
511 519
512 sink() 520 sink()
521 }
513 522
514 ## ------------------------ 523 ## ------------------------
515 ## create final zip and quit with status 0 to tell galaxy all was fine 524 ## create final zip and quit with status 0 to tell galaxy all was fine
516 ## ------------------------ 525 ## ------------------------
517 catMsg( "zipping all output") 526 catMsg( "zipping all output")