2
|
1 #!/usr/bin/Rscript
|
|
2
|
|
3 ## --------------------
|
|
4 ## prints all arguments as msg
|
|
5 ## --------------------
|
|
6 catMsg <- function( msg=c() ){
|
|
7 cat( MAIN_NAME, paste( msg, collapse="" ), "\n", sep='')
|
|
8 }
|
|
9 ## --------------------
|
28
|
10 ## return the location of this script
|
2
|
11 ## --------------------
|
|
12 getScriptPath <- function(){
|
|
13 cmd.args <- commandArgs()
|
|
14 m <- regexpr("(?<=^--file=).+", cmd.args, perl=TRUE)
|
|
15 script.dir <- dirname(regmatches(cmd.args, m))
|
42
|
16 if( length(script.dir) == 0 ) stop("[ERR] Can't determine script dir: please call the script with Rscript\n")
|
|
17 if( length(script.dir) > 1 ) stop("[ERR] Can't determine script dir: more than one '--file' argument detected\n")
|
2
|
18 return(script.dir)
|
|
19 }
|
|
20 ## --------------------
|
28
|
21 ## Some html creation functions
|
2
|
22 ## --------------------
|
|
23 htmlTableRow <- function( string_array=c() ){
|
|
24 td_cells <- ''
|
|
25 for ( i in string_array ){
|
|
26 td_cells <- paste( td_cells, '<td>', i, '</td>', sep='' )
|
|
27 }
|
|
28 return( paste( "<tr>", td_cells, "</tr>") )
|
|
29 }
|
|
30 htmlLink <- function( path, desc="LINK" ){
|
|
31 return( paste( '<a href="', path, '">', desc, "</a>", sep='') )
|
|
32 }
|
|
33 ## --------------------
|
28
|
34 ## constructs a list with input bam file info
|
2
|
35 ## --------------------
|
|
36 makeBamFileList <- function( paths, names ){
|
|
37 tmp <- list()
|
|
38 l1 <- length(paths)
|
|
39 l2 <- length(names)
|
42
|
40 if ( l1 != l2 ) stop( "Unequal amount of bam-paths (", l1, ") and -names (", l2, ") in makeBamFileList!!!\n" )
|
2
|
41 for ( i in 1:length(paths) ){
|
|
42 path <- paths[i]
|
|
43 name <- names[i]
|
|
44 file <- basename(path)
|
|
45
|
|
46 tmp[[ file ]] <- name
|
|
47 tmp[[ 'all_paths' ]] <- c( tmp[[ 'all_paths' ]], path )
|
|
48 tmp[[ 'all_files' ]] <- c( tmp[[ 'all_files' ]], file )
|
|
49 tmp[[ 'all_names' ]] <- c( tmp[[ 'all_names' ]], name )
|
|
50 }
|
|
51 return( tmp )
|
|
52 }
|
|
53
|
|
54 ## --------------------
|
28
|
55 ## copied code for extracting the regions by segment call status
|
2
|
56 ## --------------------
|
|
57 fuse.regions_test <- function(cgh, onlyCalled=T) {
|
|
58 if (ncol(cgh) > 1) stop('Please specify which sample...')
|
|
59
|
|
60 x <- data.frame(cgh@featureData@data[,1:3], calls(cgh), copynumber(cgh), segmented(cgh), check.names=FALSE, stringsAsFactors=FALSE)
|
|
61 colnames( x ) <- c( "chr", "start", "end", "call", "log2", "segmentval" )
|
|
62
|
|
63 fused.data <- data.frame()
|
|
64 curr.bin <- 1
|
|
65 for (chr in unique(x$chr)) {
|
|
66
|
|
67 chr.data <- x[x$chr == chr,]
|
|
68 prev.bin <- curr.bin
|
|
69 prev.call <- chr.data[1, 'call']
|
|
70 prev.log2 <- chr.data[1, 'log2']
|
|
71 prev.segm <- chr.data[1, 'segmentval']
|
|
72 start <- chr.data[1, 'start']
|
|
73
|
|
74 if ( nrow(chr.data) > 1) {
|
|
75 for ( i in 2:nrow(chr.data) ) {
|
|
76
|
|
77 curr.bin <- curr.bin + 1
|
|
78 curr.call <- chr.data[ i, 'call']
|
|
79 curr.segm <- chr.data[ i, 'segmentval']
|
|
80
|
|
81 if ( curr.segm != prev.segm ) {
|
|
82
|
|
83 fused.data <- rbind( fused.data, data.frame( chr=chr, start=start, end=chr.data[ i-1, 'end'], call=prev.call, segmentval=round(prev.segm, digits=DECIMALS) ) )
|
|
84 if ( prev.call != 0 ){
|
42
|
85 catMsg( c(" ...found called/segmented region (", chr, ':', start, ' call=', prev.call, ' segment=', prev.segm, ")" ) )
|
2
|
86 }
|
|
87 prev.call <- curr.call
|
|
88 prev.segm <- curr.segm
|
|
89 prev.bin <- curr.bin
|
|
90 start <- chr.data[ i, 'start']
|
|
91 }
|
|
92 }
|
|
93 fused.data <- rbind( fused.data, data.frame( chr=chr, start=start, end=chr.data[ i-1, 'end'], call=prev.call, segmentval=round(prev.segm, digits=DECIMALS) ) )
|
|
94 }else {
|
|
95 fused.data <- rbind( fused.data, data.frame( chr=chr, start=start, end=chr.data[ i-1, 'end'], call=prev.call, segmentval=round(prev.segm, digits=DECIMALS) ) )
|
|
96 }
|
|
97 }
|
|
98 if ( onlyCalled == T ){
|
|
99 fused.data <- fused.data[ fused.data$call != 0, ]
|
|
100 }
|
|
101 fused.data
|
|
102 }
|
|
103
|
|
104 ## DESC: takes the output of fuse.regions and outputs a txt file per sample
|
|
105 outputRegionsFromList <- function ( regionsList, outputBasename, outputDir="./" ){
|
|
106 if ( missing(regionsList) ) stop( 'Please provide regionsList...' )
|
|
107 if ( missing(outputBasename) ) stop( 'Please provide outputBasename...' )
|
|
108 if ( !is.list(regionsList) ) stop( 'Input not a list...?' )
|
|
109 if ( length(regionsList) < 1 ) stop( 'List seems empty...?' )
|
42
|
110 if ( file.exists( outputDir ) ) catMsg( c(" Using dir ", outputDir, " for output") )
|
2
|
111 else dir.create( outputDir )
|
|
112 outFiles <- list()
|
|
113
|
|
114 ## have to set R output options otherwise scientific method is used at some point
|
|
115 options( "scipen"=100 )
|
|
116
|
|
117 sampleCount <- length( regionsList )
|
|
118 sampleNames <- names( regionsList )
|
|
119 bedgraphColumns <- c( 'chr', 'start', 'end', 'segmentval' )
|
30
|
120
|
42
|
121 catMsg( c( " There are ", sampleCount, " samples found in input list") )
|
2
|
122
|
|
123 for ( sample in sampleNames ){
|
42
|
124 catMsg( c(" Working on sample ", sample ) )
|
2
|
125 regionCount <- nrow( regionsList[[sample]] )
|
|
126
|
|
127 outSampleBase <- paste( outputBasename, '_', sample, '_QDNAseqRegions', sep='')
|
|
128 outBedFile <- paste( outSampleBase, '.bed', sep="" )
|
|
129 outBedPath <- paste( outputDir, '/', outBedFile, sep="" )
|
|
130 outBedgraphFile <- paste( outSampleBase, '.bedGraph', sep="" )
|
|
131 outBedgraphPath <- paste( outputDir, '/', outBedgraphFile, sep="" )
|
|
132
|
|
133 ## ---------- BED ----------
|
|
134 txt <- "#"
|
|
135 sink( outBedPath )
|
|
136 cat( txt )
|
|
137 sink()
|
|
138 write.table( regionsList[[sample]], outBedPath, quote=F, sep="\t", row.names=F, append=T)
|
|
139
|
|
140 ## ---------- BEDGRAPH ----------
|
|
141 txt <- paste( "track type=bedGraph color=0,100,0 altColor=255,0,0 name=", sample,"_segmReg description=segmented_regions_from_QDNAseq\n", sep="")
|
|
142 sink( outBedgraphPath )
|
|
143 cat( txt )
|
|
144 sink()
|
|
145 write.table( regionsList[[sample]][,bedgraphColumns], outBedgraphPath, quote=F, sep="\t", row.names=F, append=T, col.names=F)
|
|
146 outFiles[[sample]] <- c( outBedFile, outBedgraphFile )
|
|
147 }
|
|
148 outFiles
|
|
149 }
|
|
150
|
|
151 ## ==================================================
|
|
152 ## Start of analysis
|
|
153 ## ==================================================
|
42
|
154 MAIN_NAME <- '[INFO] '
|
2
|
155 TOOL_PATH <- getScriptPath()
|
|
156 CSS_FILE <- paste( TOOL_PATH, '/QDNAseq.css', sep="" )
|
|
157 DECIMALS <- 3
|
|
158 WEB_LINK <- 'http://www.bioconductor.org/packages/release/bioc/html/QDNAseq.html'
|
|
159
|
|
160 catMsg( "Starting QDNAseq wrapper" )
|
|
161 catMsg( "Loading R libraries" )
|
|
162 suppressWarnings( suppressMessages( library( QDNAseq, quietly = TRUE ) ) )
|
|
163 suppressWarnings( suppressMessages( library( CGHcall, quietly = TRUE ) ) )
|
25
|
164
|
2
|
165 ## only one param: the tmp config file
|
|
166 cmdLineArgs <- commandArgs(TRUE)
|
|
167 config <- cmdLineArgs[1]
|
|
168
|
|
169 ## sourcing the config file will load all input params
|
42
|
170 ## many variables are created in sourced "config"
|
2
|
171 source( config )
|
|
172
|
42
|
173 PLOT_RES <- min( PLOT_WIDTH, PLOT_HEIGHT ) / 6.3 # desparate try to make png text scale well, damn you R...!
|
2
|
174 if ( doOutputCallsRds == TRUE ){ doCall <- TRUE }
|
|
175
|
42
|
176 systemUser <- system("whoami",T)
|
|
177 qdnaseqVersion <- packageDescription( "QDNAseq" )$Version
|
|
178 catMsg( c("Analysis run with user: ", systemUser ) )
|
|
179 catMsg( c("QDNAseq version loaded: ", qdnaseqVersion) )
|
45
|
180 catMsg( c( sessionInfo()$R.version$version.string ) )
|
42
|
181
|
2
|
182 ## get the comma separated list of chromosomes to exclude
|
|
183 excludeChrs <- unlist( strsplit( excludeChrsString, ",") )
|
|
184
|
|
185 ## ------------------------
|
|
186 ## DEBUG
|
|
187 #catMsg( "PARAM" )
|
|
188 #catMsg( galaxy_path )
|
|
189 #catMsg( repos_path )
|
|
190 #catMsg( instal_path )
|
|
191 ## /DEBUG
|
|
192 ## ------------------------
|
|
193
|
|
194 ## setup bam filelist for easy retrieval later
|
|
195 fileList <- makeBamFileList( bamsPaths, bamsNames )
|
|
196 bamCount <- length( fileList[[ 'all_paths' ]] )
|
|
197
|
42
|
198 ## help msg for running script separate still needs work!
|
28
|
199 #if ( length(cmdLineArgs) == 0 || cmdLineArgs[1] == "-h" || cmdLineArgs[1] == "--help"){
|
42
|
200 # catMsg( c( "Usage: ", paste(params_help,sep=",") ) )
|
28
|
201 # quit( save = 'no', status=0, runLast=F )
|
|
202 #}
|
2
|
203
|
|
204 if ( !file.exists( outputPath) ){
|
|
205 dir.create( outputPath )
|
|
206 }
|
|
207
|
|
208 ## because we circumvent params that galaxy can save, we want to
|
|
209 ## copy source config file to output dir to include it in output zip
|
|
210 file.copy( config, paste(outputPath, 'qdnaseq_config_file.R', sep='/') )
|
|
211
|
|
212 ## ------------------------
|
|
213 ## construct output file-names and -paths
|
|
214 ## ------------------------
|
|
215 htmlOutputName <- 'index.html'
|
|
216 gzipOutputName <- paste( 'QDNAseqResults_', outputName, '.zip', sep='' )
|
|
217 robjReadCoName <- paste( binSize, 'kbp_QDNAseqReadCounts.rds', sep='')
|
|
218 robjCopyNrName <- paste( binSize, 'kbp_QDNAseqCopyNumbers.rds', sep='')
|
|
219 robjCalledName <- paste( binSize, 'kbp_QDNAseqCalledSegments.rds', sep='')
|
|
220 regiOutputName <- paste( binSize, 'kbp_QDNAseqRegions.rds', sep='')
|
|
221 igvCalledName <- paste( binSize, 'kbp_QDNAseq-calls.igv', sep='')
|
|
222 igvCopyNrName <- paste( binSize, 'kbp_QDNAseq-normalized.igv', sep='')
|
42
|
223 noiseImgName <- paste( 'QDNAseqNoisePlot.png', sep='')
|
|
224 freqImgName <- paste( 'QDNAseqFrequencyPlot.png', sep='')
|
2
|
225
|
42
|
226
|
|
227 gzipOutputPath <- paste( outputPath, '/', gzipOutputName, sep='')
|
|
228 htmlOutputPath <- paste( outputPath, '/', htmlOutputName, sep='')
|
|
229 robjReadCoPath <- paste( outputPath, '/', robjReadCoName, sep='')
|
|
230 robjCopyNrPath <- paste( outputPath, '/', robjCopyNrName, sep='')
|
|
231 robjCalledPath <- paste( outputPath, '/', robjCalledName, sep='')
|
|
232 robjRegionPath <- paste( outputPath, '/', regiOutputName, sep='')
|
|
233 igvCalledPath <- paste( outputPath, '/', igvCalledName, sep='')
|
|
234 igvCopyNrPath <- paste( outputPath, '/', igvCopyNrName, sep='')
|
|
235 noiseImgPath <- paste( outputPath, '/', noiseImgName, sep='' )
|
|
236 freqImgPath <- paste( outputPath, '/', freqImgName, sep='' )
|
2
|
237
|
|
238
|
|
239 ## ------------------------
|
|
240 ## performing QDNAseq analysis steps
|
|
241 ## ------------------------
|
|
242 if ( debug ){
|
|
243 ## in case of debug just use inbuilt LGG data for speedup
|
|
244 data(LGG150)
|
|
245 readCounts <- LGG150
|
|
246 }else{
|
|
247 if ( nchar(binAnnotations) == 0 ){
|
|
248 binAnnotations <- getBinAnnotations( binSize=binSize, type=experimentType )
|
|
249 }else{
|
|
250 ## if user provided file, check if correct class
|
|
251 if ( class(binAnnotations)[1] != 'AnnotatedDataFrame' ){
|
|
252 stop( "Provided binAnnotations file is not of class 'AnnotatedDataFrame'\n" )
|
|
253 }
|
|
254 binAnnotations <- readRDS( binAnnotations )
|
|
255 }
|
|
256 ## provide bamnames because in galaxy everyting is called "dataset_###"
|
|
257 readCounts <- binReadCounts( binAnnotations, bamfiles=fileList[[ 'all_paths' ]], bamnames=bamsNames )
|
|
258 }
|
|
259
|
|
260 readCountsFiltered <- applyFilters( readCounts, residual=TRUE, blacklist=filterBlacklistedBins, mappability=mappabilityCutoff, chromosomes=excludeChrs )
|
|
261 readCountsFiltered <- estimateCorrection( readCountsFiltered )
|
|
262 copyNumbers <- correctBins( readCountsFiltered )
|
|
263 copyNumbersNormalized <- normalizeBins( copyNumbers )
|
|
264 copyNumbersSmooth <- smoothOutlierBins( copyNumbersNormalized )
|
28
|
265 sampleNames <- readCountsFiltered@phenoData@data$name
|
2
|
266
|
|
267 ## save objects to output dir
|
42
|
268 saveRDS( readCountsFiltered, robjReadCoPath );
|
29
|
269 saveRDS( copyNumbersSmooth, robjCopyNrPath );
|
42
|
270 exportBins( copyNumbersSmooth, file=igvCopyNrPath, format="igv" )
|
2
|
271
|
|
272 ## also save objects for galaxy history output if requested
|
|
273 if ( doOutputReadcountsRds ){
|
|
274 saveRDS( readCountsFiltered, readCountsDatasetFile );
|
|
275 }
|
|
276 if ( doOutputCopynumbersRds ){
|
|
277 saveRDS( copyNumbersSmooth, copyNumbersDatasetFile );
|
|
278 }
|
|
279
|
|
280 ## proceed with calling if requested
|
|
281 if ( doCall ){
|
|
282 copyNumbersSegmented <- segmentBins( copyNumbersSmooth, undo.splits=undoSplits, undo.SD=undoSD )
|
|
283 copyNumbersSegmented <- normalizeSegmentedBins( copyNumbersSegmented )
|
|
284 copyNumbersCalled <- callBins( copyNumbersSegmented )
|
|
285 cgh <- makeCgh( copyNumbersCalled )
|
|
286 saveRDS( copyNumbersCalled, robjCalledPath );
|
|
287 if ( doOutputCallsRds ){
|
|
288 saveRDS( copyNumbersCalled, calledSegmentsDatasetFile );
|
|
289 }
|
31
|
290 exportBins( copyNumbersCalled, file=igvCalledPath, format="igv")
|
42
|
291
|
2
|
292 }
|
|
293
|
28
|
294
|
2
|
295
|
|
296 ## ------------------------
|
|
297 ## create output files
|
|
298 ## ------------------------
|
|
299 plotted_images <- list() # to keep track of images for later linking
|
|
300 regions <- list() # will contain the (called) segments
|
|
301
|
42
|
302 png( noiseImgPath, width=PLOT_HEIGHT, height=PLOT_HEIGHT, res=PLOT_RES );
|
|
303 noisePlot( readCountsFiltered, col="darkgreen" )
|
2
|
304 dev.off()
|
|
305
|
42
|
306 if ( doCall ){
|
|
307 png( freqImgPath, width=PLOT_WIDTH, height=PLOT_HEIGHT, res=PLOT_RES );
|
|
308 frequencyPlot( copyNumbersCalled )
|
|
309 dev.off()
|
|
310 }
|
|
311
|
|
312
|
2
|
313 for (i in 1:length(sampleNames) ){
|
|
314 #for (sample in sampleNames(copyNumbersSmooth) ){
|
|
315 sample <- sampleNames[i]
|
|
316 usedReads <- readCountsFiltered@phenoData@data$used.reads[i]
|
|
317 catMsg( c("Creating plots for sample: ", sample ) )
|
|
318
|
|
319 type <- 'CopyNumbers'
|
|
320 img_file <- paste( sample, '_', binSize, 'kbp_QDNAseq', type, '.png', sep='')
|
|
321 img_file_path <- paste( outputPath, '/', img_file, sep='' )
|
42
|
322 png( img_file_path, width=PLOT_WIDTH, height=PLOT_HEIGHT, res=PLOT_RES );
|
|
323 plot( copyNumbersSmooth[ ,sample ] );
|
|
324 dev.off()
|
2
|
325 plotted_images[[ sample ]][[ type ]] <- img_file
|
|
326
|
|
327 if ( doCall ){
|
|
328 type <- 'Called'
|
|
329 img_file <- paste( sample, '_', binSize, 'kbp_QDNAseq', type, '.png', sep='')
|
|
330 img_file_path <- paste( outputPath, '/', img_file, sep='' )
|
42
|
331 png( img_file_path, width=PLOT_WIDTH, height=PLOT_HEIGHT, res=PLOT_RES );
|
2
|
332 plot( copyNumbersCalled[ ,sample ] );
|
|
333 dev.off()
|
|
334 plotted_images[[ sample ]][[ type ]] <- img_file
|
|
335
|
42
|
336 catMsg( c(" Fusing regions of sample: ", sample) )
|
2
|
337 regions[[ sample ]] <- fuse.regions_test( cgh[, sample] )
|
|
338 region_count <- nrow( data.frame( regions[[ sample ]] ) )
|
42
|
339 catMsg( c( ' sample "', sample, '" has ', region_count, " regions" ) )
|
2
|
340 plotted_images[[ sample ]][[ 'region_count' ]] <- region_count
|
|
341 }
|
|
342
|
30
|
343 ## add USED read counts
|
2
|
344 plotted_images[[ sample ]][[ 'usedReads' ]] <- usedReads
|
|
345 }
|
|
346
|
|
347 if ( doCall ){
|
|
348 saveRDS( regions, robjRegionPath )
|
|
349 printedFiles <- outputRegionsFromList( regions, outputBasename=outputName, outputDir=outputPath )
|
|
350 }
|
|
351
|
|
352 ## ------------------------
|
|
353 ## prepare output
|
|
354 ## ------------------------
|
42
|
355 catMsg( "...zipping output")
|
2
|
356 zip_cmd <- paste( "zip -j", gzipOutputPath, paste(outputPath,'/*',sep='') ) ## -j is for removing dirs from the tree
|
|
357 system( zip_cmd )
|
|
358
|
|
359 ## ------------------------
|
|
360 ## get filesizes for report
|
|
361 ## ------------------------
|
|
362 zippedSize <- paste( round( file.info( gzipOutputPath )[["size"]] / 1000000, digits=2 ), 'MB' )
|
|
363 readCoSize <- paste( round( file.info( robjReadCoPath )[["size"]] / 1000000, digits=2 ), 'MB' )
|
|
364 copyNrSize <- paste( round( file.info( robjCopyNrPath )[["size"]] / 1000000, digits=2 ), 'MB' )
|
|
365 calledSize <- paste( round( file.info( robjCalledPath )[["size"]] / 1000000, digits=2 ), 'MB' )
|
|
366 regionSize <- paste( round( file.info( robjRegionPath )[["size"]] / 1000000, digits=2 ), 'MB' )
|
31
|
367 igvCopyNrSize <- paste( round( file.info( igvCopyNrPath )[["size"]] / 1000000, digits=2 ), 'MB' )
|
34
|
368 igvCalledSize <- paste( round( file.info( igvCalledPath )[["size"]] / 1000000, digits=2 ), 'MB' )
|
2
|
369
|
|
370 ## ------------------------
|
|
371 ## creating html output to be linked to from the middle galaxy pane
|
|
372 ## ------------------------
|
|
373
|
|
374 #sink( file = outputHtml, type = "output" )
|
|
375 sink( file = htmlOutputPath, type = "output" )
|
|
376 cat( "<html>\n")
|
|
377 cat( "<head>\n")
|
|
378 #cat( '<link rel="stylesheet" type="text/css" href="test.css" media="screen" />', "\n" )
|
|
379 cat( "\t", '<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.4.2/pure-min.css">', "\n" )
|
|
380 cat( "\t<style>\n")
|
|
381 ## have to include CSS into html file, because css referencing outside own dir doesn't seem to work...
|
|
382 cat( paste( "\t\t", '/* the css here originates from ', CSS_FILE,' */', "\n") )
|
|
383 cat( paste( "\t\t", readLines( CSS_FILE, n = -1)), sep="\n" )
|
|
384 #cat( "\t\th1 {color:red;}", "\n")
|
|
385
|
|
386 cat( "\t</style>\n" )
|
|
387
|
|
388 cat( "\n</head>\n")
|
|
389 cat( "\n<body>\n")
|
|
390
|
|
391 cat( "<h1>QDNAseq Report</h1>", "\n")
|
|
392
|
|
393 cat( '<h3 class="qdnaseq">About this analysis</h3>', "\n")
|
42
|
394 cat( '<p>This page provides access to all results. To have a local copy of this report just download the <a href="', gzipOutputName, '" class="button-success button-small pure-button">zipfile</a> with all output (', zippedSize, ')</p>', "\n", sep='')
|
2
|
395
|
|
396 ## ------------------------
|
|
397 ## table with general info
|
|
398 ## ------------------------
|
|
399 cat( '<h3 class="qdnaseq">Settings</h3><p>', "\n")
|
|
400 cat( '<table class="pure-table pure-table-striped"><thead><tr><th>setting</th><th>value</th></tr></thead><tbody>' )
|
|
401 cat( htmlTableRow( c( "AnalysisName", outputName ) ) )
|
|
402 cat( htmlTableRow( c( "AnalysisDate", 'todo' ) ) )
|
|
403 cat( htmlTableRow( c( "BinSize (kb)", binSize ) ) )
|
|
404
|
|
405 for ( galaxyName in fileList[[ 'all_files' ]] ){
|
|
406 sampleName <- fileList[[ galaxyName ]]
|
|
407 cat( htmlTableRow( c( "InputBam", paste( galaxyName, ' (', sampleName, ')', sep='' ) ) ) )
|
|
408 }
|
|
409 cat( "</tbody></table></p>", "\n")
|
|
410
|
|
411 ## ------------------------
|
|
412 ## list with links to all output files
|
|
413 ## ------------------------
|
|
414 r_code <- '<p>'
|
|
415 r_code <- paste( r_code, '<code class="code">## R code to load files</code><br />', sep="\n" )
|
|
416 r_code <- paste( r_code, '<code class="code">library( QDNAseq )</code><br />', sep="\n")
|
|
417
|
|
418 cat( '<h3 class="qdnaseq">Output files</h3><p>', "\n")
|
|
419 cat( '<dl>', "\n" )
|
|
420 cat( '<dt>', htmlLink( path=robjReadCoName, robjReadCoName ), '</dt>', "\n" )
|
|
421 cat( '<dd>QDNAseq object with read counts per bin, ', readCoSize,'</dd>', "\n" )
|
|
422 r_code <- paste( r_code, '<code class="code">readCounts <- readRDS(', robjReadCoName, ")</code><br />", sep="")
|
|
423
|
|
424 cat( '<dt>', htmlLink( path=robjCopyNrName, robjCopyNrName ), '</dt>', "\n" )
|
|
425 cat( '<dd>QDNAseq object with copy numbers per bin, ', copyNrSize,'</dd>', "\n" )
|
|
426 r_code <- paste( r_code, '<code class="code">copyNumbersSmooth <- readRDS(', robjCopyNrName, ")</code><br />", sep="")
|
|
427
|
31
|
428 cat( '<dt>', htmlLink( path=igvCopyNrName, igvCopyNrName ), '</dt>', "\n" )
|
|
429 cat( '<dd>IGV formatted text file with copy numbers per bin, ', igvCopyNrSize,'</dd>', "\n" )
|
|
430
|
2
|
431 if ( doCall ){
|
|
432 cat( '<dt>', htmlLink( path=robjCalledName, robjCalledName ), '</dt>', "\n" )
|
|
433 cat( '<dd>QDNAseq object with segment and call status per bin, ', calledSize,'</dd>', "\n" )
|
|
434 r_code <- paste( r_code, '<code class="code">copyNumbersCalled <- readRDS(', robjCalledName, ")</code><br />", sep="")
|
|
435
|
|
436 cat( '<dt>', htmlLink( path=regiOutputName, regiOutputName ), '</dt>', "\n" )
|
|
437 cat( '<dd>list with segmented/called regions for each sample, ', regionSize, '</dd>', "\n" )
|
|
438 r_code <- paste( r_code, '<code class="code">calledRegions <- readRDS(', regiOutputName, ")</code><br />", sep="")
|
|
439
|
31
|
440 cat( '<dt>', htmlLink( path=igvCalledName, igvCalledName ), '</dt>', "\n" )
|
|
441 cat( '<dd>IGV formatted text file with calls per bin , ', igvCalledSize,'</dd>', "\n" )
|
|
442
|
2
|
443 }
|
|
444 cat( '</dl></p>', "\n" )
|
|
445
|
42
|
446 ## r_code shows example code on how to load output files
|
25
|
447 #cat( r_code, "</p>\n", sep="\n")
|
2
|
448 cat( '<p>See ', htmlLink( WEB_LINK, 'the bioconductor QDNAseq documentation' ), ' for more information on how to work with these files</p>', "\n", sep='' )
|
|
449
|
|
450 ## ------------------------
|
|
451 ## table with links to files
|
|
452 ## ------------------------
|
|
453 cat( '<h3 class="qdnaseq">Results: overview</h3><p>', "\n")
|
|
454 plots_html <- ''
|
|
455
|
40
|
456 cat( '<table class="pure-table pure-table-striped"><thead><tr><th>Sample / File</th><th>CopyNr</th><th>Calls</th><th>Reads</th><th>Regions</th><th>Files</th></tr></thead><tbody>' )
|
2
|
457
|
|
458 for ( bam_file in sampleNames ){
|
|
459
|
|
460 #width <- 600; height <- 240
|
|
461 width <- PLOT_WIDTH; height <- PLOT_HEIGHT
|
|
462 width_t <- 100; height_t <- 40
|
|
463
|
|
464 ## add thumbnails to table with links to anchors on html page
|
|
465 copy_img <- plotted_images[[ bam_file ]][[ 'CopyNumbers' ]]
|
|
466 usedReads <- plotted_images[[ bam_file ]][[ 'usedReads' ]]
|
|
467 usedReads <- format( as.integer(usedReads), digits=4, decimal.mark=".", big.mark="," )
|
|
468
|
|
469 html_copy_thumb <- htmlLink( path=paste('#', copy_img, sep=''), paste('<img src="',copy_img,'" alt="', bam_file, '" width="', width_t, '" height="', height_t, '">', sep='') )
|
|
470 html_copy_img <- htmlLink( path=copy_img, paste('<img id="', copy_img,'" src="',copy_img,'" alt="',bam_file, '" width="', width, '" height="', height, '">', sep='') )
|
|
471 html_call_thumb <- 'NA'
|
|
472 html_call_img <- ''
|
|
473 html_bed <- 'NA'
|
|
474 html_bedGraph <- 'NA'
|
|
475 region_count <- 'NA'
|
|
476
|
|
477 if ( doCall ){
|
|
478 call_img <- plotted_images[[ bam_file ]][[ 'Called' ]]
|
|
479 region_count <- plotted_images[[ bam_file ]][[ 'region_count' ]]
|
|
480 html_call_thumb <- htmlLink( path=paste('#', call_img, sep=''), paste('<img src="', call_img, '" alt="', bam_file, '" width="', width_t,'" height="', height_t,'">', sep='') )
|
|
481
|
|
482 files <- printedFiles[[ bam_file ]]
|
|
483 html_bed <- htmlLink( path=files[1], 'bed' )
|
|
484 html_bedGraph <- htmlLink( path=files[2], 'bedGraph' )
|
|
485 html_call_img <- htmlLink( path=call_img, paste('<img id="', call_img,'" src="', call_img,'" alt="', bam_file, '" width="', width, '" height="', height,'">', sep='') )
|
|
486 }
|
|
487
|
|
488 ## add info to overview table, including small thumbnails
|
|
489 cat( htmlTableRow( c(bam_file, html_copy_thumb, html_call_thumb, usedReads, region_count, paste( html_bed, html_bedGraph, sep=", ")) ), "\n" )
|
|
490 ## now include (large) images in html page
|
|
491 plots_html <- paste( plots_html, html_copy_img, "\n", html_call_img, "\n<hr \\>\n", sep='' )
|
|
492 }
|
|
493 cat( "</tbody></table></p>", "\n")
|
|
494
|
42
|
495 ## ------------------------
|
|
496 ## create the noise and frequency plots
|
|
497 ## ------------------------
|
|
498 html_noise_img <- htmlLink(
|
|
499 path=noiseImgName,
|
|
500 paste('<img id="', noiseImgName,'" src="', noiseImgName,'" alt="NoisePlot">', sep='')
|
|
501 )
|
|
502 html_freq_img <- htmlLink(
|
|
503 path=freqImgName,
|
|
504 paste('<img id="', freqImgName,'" src="', freqImgName,'" alt="FrequenceyPlot">', sep='')
|
|
505 )
|
|
506 extra_plots_html <- paste(
|
|
507 html_noise_img, "\n<br \\>\n",
|
|
508 html_freq_img, "\n", sep=''
|
|
509 )
|
2
|
510
|
|
511 ## ------------------------
|
|
512 ## section with various output shown
|
|
513 ## ------------------------
|
42
|
514 cat( '<h3 class="qdnaseq">Results: Analysis plots</h3><p>', "\n")
|
|
515 cat( extra_plots_html, "\n")
|
|
516 cat( '<h3 class="qdnaseq">Results: Sample plots</h3><p>', "\n")
|
2
|
517 cat( plots_html, "\n")
|
|
518 cat( "\n</p></body>\n")
|
|
519 cat( "\n</html>\n")
|
|
520 sink()
|
|
521
|
|
522 ## ------------------------
|
42
|
523 ## creating main html output for galaxy history
|
2
|
524 ## ------------------------
|
|
525 sink( file = outputHtml, type = "output" )
|
|
526
|
|
527 cat( "<head>", "\n")
|
|
528 cat( "\t", '<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.4.2/pure-min.css">', "\n" )
|
|
529
|
|
530 cat( "<style>", "\n")
|
42
|
531 ## include CSS directly into html file
|
2
|
532 cat( paste( "\t", '/* the css here originates from ', CSS_FILE,' */', "\n") )
|
|
533 cat( paste( "\t", readLines( CSS_FILE, n = -1)), sep="\n" )
|
|
534 cat( "</style>", "\n")
|
|
535 cat( "</head>", "\n")
|
|
536
|
|
537 cat( '<h1>QDNAseq Results (', outputName,')</h1>', "\n", sep="")
|
|
538 cat( '<p>Explore <a href="', htmlOutputName, '" class="button-success button-small pure-button">the results</a> directly within galaxy</p>', "\n", sep="")
|
|
539 cat( '<p>Or download a <a href="', gzipOutputName, '" class="button-success button-small pure-button">zipfile</a> with all output (', zippedSize, ')</p>', "\n", sep="" )
|
|
540
|
|
541 cat( '<p>The zip file contains all output files, including *.rds files allowing you to load the R copyNumber object(s) and perform further detailed analysis or create your own output for further processing. You can load the rds file with <code class="code">loadRDS(file.rds)</code></p>', "\n", sep="")
|
|
542
|
|
543 sink()
|
|
544
|
42
|
545 ## ------------------------
|
|
546 ## create final zip and quit with status 0 to tell galaxy all was fine
|
|
547 ## ------------------------
|
|
548 catMsg( "zipping all output")
|
|
549 system( paste( "zip -j ", gzipOutputPath, paste(outputPath,'/', htmlOutputName, sep='') ) )
|
|
550 catMsg( "done" )
|
25
|
551 q(status=0)
|