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 ## --------------------
|
|
10 ## return the directory this script exists
|
|
11 ## --------------------
|
|
12 getScriptPath <- function(){
|
|
13 cmd.args <- commandArgs()
|
|
14 m <- regexpr("(?<=^--file=).+", cmd.args, perl=TRUE)
|
|
15 script.dir <- dirname(regmatches(cmd.args, m))
|
|
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")
|
|
18 return(script.dir)
|
|
19 }
|
|
20 ## --------------------
|
|
21 ## Some html helper functions
|
|
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 ## --------------------
|
|
34 ## constructs a list with bam file info
|
|
35 ## --------------------
|
|
36 makeBamFileList <- function( paths, names ){
|
|
37 tmp <- list()
|
|
38 l1 <- length(paths)
|
|
39 l2 <- length(names)
|
|
40 if ( l1 != l2 ) stop( "Unequal amount of bam-paths (",l1,") and -names (",l2,") in makeBamFileList!!!\n" )
|
|
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 ## --------------------
|
|
55 ## took a function from Matias/MarkVdWuel? for extracting the regions by call
|
|
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 ){
|
|
85 cat( MAIN_NAME, " ...found called/segmented region (", chr, ':', start, ' call=', prev.call, ' segment=', prev.segm, ")\n", sep="" )
|
|
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...?' )
|
|
110 if ( file.exists( outputDir ) ) cat( MAIN_NAME, " Using dir ", outputDir, " for output\n", sep="")
|
|
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 systemUser <- system("whoami",T)
|
|
120 bedgraphColumns <- c( 'chr', 'start', 'end', 'segmentval' )
|
|
121
|
|
122 cat( MAIN_NAME, " Hello ", systemUser, "!!\n", sep="")
|
|
123 cat( MAIN_NAME, " There are ", sampleCount, " samples found in input list...\n", sep="")
|
|
124
|
|
125 for ( sample in sampleNames ){
|
|
126 cat( MAIN_NAME, " Working on sample ", sample, "\n", sep="")
|
|
127 regionCount <- nrow( regionsList[[sample]] )
|
|
128
|
|
129 outSampleBase <- paste( outputBasename, '_', sample, '_QDNAseqRegions', sep='')
|
|
130 outBedFile <- paste( outSampleBase, '.bed', sep="" )
|
|
131 outBedPath <- paste( outputDir, '/', outBedFile, sep="" )
|
|
132 outBedgraphFile <- paste( outSampleBase, '.bedGraph', sep="" )
|
|
133 outBedgraphPath <- paste( outputDir, '/', outBedgraphFile, sep="" )
|
|
134
|
|
135 ## ---------- BED ----------
|
|
136 txt <- "#"
|
|
137 sink( outBedPath )
|
|
138 cat( txt )
|
|
139 sink()
|
|
140 write.table( regionsList[[sample]], outBedPath, quote=F, sep="\t", row.names=F, append=T)
|
|
141
|
|
142 ## ---------- BEDGRAPH ----------
|
|
143 txt <- paste( "track type=bedGraph color=0,100,0 altColor=255,0,0 name=", sample,"_segmReg description=segmented_regions_from_QDNAseq\n", sep="")
|
|
144 sink( outBedgraphPath )
|
|
145 cat( txt )
|
|
146 sink()
|
|
147 write.table( regionsList[[sample]][,bedgraphColumns], outBedgraphPath, quote=F, sep="\t", row.names=F, append=T, col.names=F)
|
|
148 outFiles[[sample]] <- c( outBedFile, outBedgraphFile )
|
|
149 }
|
|
150 outFiles
|
|
151 }
|
|
152
|
|
153 printIgvFile <- function( dat, filename ){
|
|
154
|
|
155 if ( 'calls' %in% assayDataElementNames(dat) ) {
|
|
156 #output <- paste(output, '-called.igv', sep="")
|
|
157 cat('#type=COPY_NUMBER\n#track coords=1\n', file=filename)
|
|
158 df <- data.frame(chromosome=as.character(chromosomes(dat)), start=bpstart(dat), end=bpend(dat), feature=featureNames(dat), calls(dat), check.names=FALSE, stringsAsFactors=FALSE)
|
|
159 }else {
|
|
160 #output <- paste(output, '-normalized.igv', sep="")
|
|
161 cat('#type=COPY_NUMBER\n#track coords=1\n', file=filename)
|
|
162 df <- data.frame(chromosome=as.character(chromosomes(dat)), start=bpstart(dat), end=bpend(dat), feature=featureNames(dat), round(copynumber(dat), digits=2), check.names=FALSE, stringsAsFactors=FALSE)
|
|
163 }
|
|
164
|
|
165 df$chromosome[df$chromosome == '23'] <- 'X'
|
|
166 df$chromosome[df$chromosome == '24'] <- 'Y'
|
|
167 df$chromosome[df$chromosome == '25'] <- 'MT'
|
|
168 #return( df )
|
|
169 write.table( df, file=filename, append=TRUE, quote=FALSE, sep='\t', row.names=FALSE )
|
|
170 }
|
|
171
|
|
172
|
|
173 ## ==================================================
|
|
174 ## Start of analysis
|
|
175 ## ==================================================
|
|
176 TOOL_PATH <- getScriptPath()
|
|
177 MAIN_NAME <- '[INFO] '
|
|
178 CSS_FILE <- paste( TOOL_PATH, '/QDNAseq.css', sep="" )
|
|
179 DECIMALS <- 3
|
|
180 WEB_LINK <- 'http://www.bioconductor.org/packages/release/bioc/html/QDNAseq.html'
|
|
181
|
|
182 catMsg( "Starting QDNAseq wrapper" )
|
|
183 catMsg( "Loading R libraries" )
|
|
184 suppressWarnings( suppressMessages( library( QDNAseq, quietly = TRUE ) ) )
|
|
185 suppressWarnings( suppressMessages( library( CGHcall, quietly = TRUE ) ) )
|
25
|
186
|
|
187 qdnaseqVersion <- packageDescription( "QDNAseq" )$Version
|
|
188 qdnaseqDate <- packageDescription( "QDNAseq" )$Date
|
26
|
189 catMsg( paste("QDNAseq info: version(", qdnaseqVersion, ") and date (", qdnaseqDate, ")", sep="") )
|
2
|
190
|
|
191 ## only one param: the tmp config file
|
|
192 cmdLineArgs <- commandArgs(TRUE)
|
|
193 config <- cmdLineArgs[1]
|
|
194
|
|
195 ## sourcing the config file will load all input params
|
|
196 source( config )
|
|
197
|
|
198 ## if call output requested, set doCall such that we will segment and call
|
|
199 if ( doOutputCallsRds == TRUE ){ doCall <- TRUE }
|
|
200
|
|
201 ## get the comma separated list of chromosomes to exclude
|
|
202 excludeChrs <- unlist( strsplit( excludeChrsString, ",") )
|
|
203
|
|
204 ## ------------------------
|
|
205 ## DEBUG
|
|
206 #catMsg( "PARAM" )
|
|
207 #catMsg( galaxy_path )
|
|
208 #catMsg( repos_path )
|
|
209 #catMsg( instal_path )
|
|
210 ## /DEBUG
|
|
211 ## ------------------------
|
|
212
|
|
213 ## setup bam filelist for easy retrieval later
|
|
214 catMsg( "Setting up input bam list" )
|
|
215 cat( bamsPaths, "\n" )
|
|
216 catMsg( "Namews" )
|
|
217 cat( bamsNames, "\n" )
|
|
218 fileList <- makeBamFileList( bamsPaths, bamsNames )
|
|
219 bamCount <- length( fileList[[ 'all_paths' ]] )
|
|
220
|
|
221 ## help msg still needs work!
|
|
222 if ( length(cmdLineArgs) == 0 || cmdLineArgs[1] == "-h" || cmdLineArgs[1] == "--help"){
|
|
223 cat( paste( MAIN_NAME, "Usage: ", params_help, sep=''), "\n" )
|
|
224 quit( save = 'no', status=0, runLast=F )
|
|
225 }
|
|
226
|
|
227 if ( !file.exists( outputPath) ){
|
|
228 dir.create( outputPath )
|
|
229 }
|
|
230
|
|
231 ## because we circumvent params that galaxy can save, we want to
|
|
232 ## copy source config file to output dir to include it in output zip
|
|
233 file.copy( config, paste(outputPath, 'qdnaseq_config_file.R', sep='/') )
|
|
234
|
|
235 ## ------------------------
|
|
236 ## construct output file-names and -paths
|
|
237 ## ------------------------
|
|
238 htmlOutputName <- 'index.html'
|
|
239 gzipOutputName <- paste( 'QDNAseqResults_', outputName, '.zip', sep='' )
|
|
240 robjReadCoName <- paste( binSize, 'kbp_QDNAseqReadCounts.rds', sep='')
|
|
241 robjCopyNrName <- paste( binSize, 'kbp_QDNAseqCopyNumbers.rds', sep='')
|
|
242 robjCalledName <- paste( binSize, 'kbp_QDNAseqCalledSegments.rds', sep='')
|
|
243 regiOutputName <- paste( binSize, 'kbp_QDNAseqRegions.rds', sep='')
|
|
244 igvCalledName <- paste( binSize, 'kbp_QDNAseq-calls.igv', sep='')
|
|
245 igvCopyNrName <- paste( binSize, 'kbp_QDNAseq-normalized.igv', sep='')
|
|
246
|
|
247 gzipOutputPath <- paste( outputPath, '/', gzipOutputName, sep="")
|
|
248 htmlOutputPath <- paste( outputPath, '/', htmlOutputName, sep="")
|
|
249 robjReadCoPath <- paste( outputPath, '/', robjReadCoName, sep="")
|
|
250 robjCopyNrPath <- paste( outputPath, '/', robjCopyNrName, sep="")
|
|
251 robjCalledPath <- paste( outputPath, '/', robjCalledName, sep="")
|
|
252 robjRegionPath <- paste( outputPath, '/', regiOutputName, sep="")
|
|
253 igv_calledPath <- paste( outputPath, '/', igvCalledName, sep="")
|
|
254 igv_copyNrPath <- paste( outputPath, '/', igvCopyNrName, sep="")
|
|
255
|
|
256
|
|
257 ## ------------------------
|
|
258 ## performing QDNAseq analysis steps
|
|
259 ## ------------------------
|
|
260 if ( debug ){
|
|
261 ## in case of debug just use inbuilt LGG data for speedup
|
|
262 data(LGG150)
|
|
263 readCounts <- LGG150
|
|
264 }else{
|
|
265 if ( nchar(binAnnotations) == 0 ){
|
|
266 binAnnotations <- getBinAnnotations( binSize=binSize, type=experimentType )
|
|
267 }else{
|
|
268 ## if user provided file, check if correct class
|
|
269 if ( class(binAnnotations)[1] != 'AnnotatedDataFrame' ){
|
|
270 stop( "Provided binAnnotations file is not of class 'AnnotatedDataFrame'\n" )
|
|
271 }
|
|
272 binAnnotations <- readRDS( binAnnotations )
|
|
273 }
|
|
274 ## provide bamnames because in galaxy everyting is called "dataset_###"
|
|
275 readCounts <- binReadCounts( binAnnotations, bamfiles=fileList[[ 'all_paths' ]], bamnames=bamsNames )
|
|
276 }
|
|
277
|
|
278 readCountsFiltered <- applyFilters( readCounts, residual=TRUE, blacklist=filterBlacklistedBins, mappability=mappabilityCutoff, chromosomes=excludeChrs )
|
|
279 readCountsFiltered <- estimateCorrection( readCountsFiltered )
|
|
280 copyNumbers <- correctBins( readCountsFiltered )
|
|
281 copyNumbersNormalized <- normalizeBins( copyNumbers )
|
|
282 copyNumbersSmooth <- smoothOutlierBins( copyNumbersNormalized )
|
|
283
|
|
284 ## save objects to output dir
|
|
285 saveRDS( readCounts, robjReadCoPath );
|
|
286 saveRDS( copyNumbersSmooth, robjCopyNrPath );
|
|
287 #printIgvFile( copyNumbersSmooth, igvCopyNrName )
|
|
288 #exportBins(copyNumbersSmooth, file=igvCopyNrName, format="igv")
|
|
289
|
|
290 ## also save objects for galaxy history output if requested
|
|
291 if ( doOutputReadcountsRds ){
|
|
292 saveRDS( readCountsFiltered, readCountsDatasetFile );
|
|
293 }
|
|
294 if ( doOutputCopynumbersRds ){
|
|
295 saveRDS( copyNumbersSmooth, copyNumbersDatasetFile );
|
|
296 }
|
|
297
|
|
298 ## proceed with calling if requested
|
|
299 if ( doCall ){
|
|
300 copyNumbersSegmented <- segmentBins( copyNumbersSmooth, undo.splits=undoSplits, undo.SD=undoSD )
|
|
301 copyNumbersSegmented <- normalizeSegmentedBins( copyNumbersSegmented )
|
|
302 copyNumbersCalled <- callBins( copyNumbersSegmented )
|
|
303 cgh <- makeCgh( copyNumbersCalled )
|
|
304 saveRDS( copyNumbersCalled, robjCalledPath );
|
|
305 if ( doOutputCallsRds ){
|
|
306 saveRDS( copyNumbersCalled, calledSegmentsDatasetFile );
|
|
307 }
|
|
308 #df <- getIGVdf( copyNumbersCalled )
|
|
309 #printIgvFile( copyNumbersCalled, igvCalledName )
|
|
310 #write.table( df, file=igvCalledName, append=TRUE, quote=FALSE, sep='\t', row.names=FALSE )
|
|
311 }
|
|
312
|
|
313 sampleNames <- readCountsFiltered@phenoData@data$name
|
|
314
|
|
315 ## ------------------------
|
|
316 ## create output files
|
|
317 ## ------------------------
|
|
318 plotted_images <- list() # to keep track of images for later linking
|
|
319 regions <- list() # will contain the (called) segments
|
|
320
|
|
321 noise_img_file <- paste( binSize, 'kbp_QDNAseqNoisePlot.png', sep='')
|
|
322 noise_img_file_path <- paste( outputPath, '/', noise_img_file, sep='' )
|
|
323 png( noise_img_file_path, width=480, height=480 );
|
|
324 noisePlot( readCountsFiltered )
|
|
325 dev.off()
|
|
326
|
|
327 for (i in 1:length(sampleNames) ){
|
|
328 #for (sample in sampleNames(copyNumbersSmooth) ){
|
|
329 sample <- sampleNames[i]
|
|
330 usedReads <- readCountsFiltered@phenoData@data$used.reads[i]
|
|
331 catMsg( c("Creating plots for sample: ", sample ) )
|
|
332
|
|
333 type <- 'CopyNumbers'
|
|
334 img_file <- paste( sample, '_', binSize, 'kbp_QDNAseq', type, '.png', sep='')
|
|
335 img_file_path <- paste( outputPath, '/', img_file, sep='' )
|
|
336 png( img_file_path, width=PLOT_WIDTH, height=PLOT_HEIGHT ); plot( copyNumbersSmooth[ ,sample ] ); dev.off()
|
|
337 plotted_images[[ sample ]][[ type ]] <- img_file
|
|
338
|
|
339 if ( doCall ){
|
|
340 type <- 'Called'
|
|
341 img_file <- paste( sample, '_', binSize, 'kbp_QDNAseq', type, '.png', sep='')
|
|
342 img_file_path <- paste( outputPath, '/', img_file, sep='' )
|
|
343 png( img_file_path, width=PLOT_WIDTH, height=PLOT_HEIGHT );
|
|
344 plot( copyNumbersCalled[ ,sample ] );
|
|
345 dev.off()
|
|
346 plotted_images[[ sample ]][[ type ]] <- img_file
|
|
347
|
|
348 cat( MAIN_NAME, " Fusing regions of sample: ", sample, "\n", sep="")
|
|
349 regions[[ sample ]] <- fuse.regions_test( cgh[, sample] )
|
|
350 region_count <- nrow( data.frame( regions[[ sample ]] ) )
|
|
351 cat( MAIN_NAME, ' sample "', sample, '" has ', region_count, " regions\n", sep="" )
|
|
352 plotted_images[[ sample ]][[ 'region_count' ]] <- region_count
|
|
353 }
|
|
354
|
|
355 ## add read counts
|
|
356 catMsg( "Used")
|
|
357 catMsg( usedReads )
|
|
358
|
|
359 plotted_images[[ sample ]][[ 'usedReads' ]] <- usedReads
|
|
360 }
|
|
361 #cat( MAIN_NAME, "PLOTTED_IMAGES: ", names(plotted_images), "\n", sep="" )
|
|
362
|
|
363 if ( doCall ){
|
|
364 saveRDS( regions, robjRegionPath )
|
|
365 printedFiles <- outputRegionsFromList( regions, outputBasename=outputName, outputDir=outputPath )
|
|
366 }
|
|
367
|
|
368 ## ------------------------
|
|
369 ## prepare output
|
|
370 ## ------------------------
|
|
371 cat( MAIN_NAME, "...zipping output\n")
|
|
372 zip_cmd <- paste( "zip -j", gzipOutputPath, paste(outputPath,'/*',sep='') ) ## -j is for removing dirs from the tree
|
|
373 system( zip_cmd )
|
|
374
|
|
375 ## ------------------------
|
|
376 ## get filesizes for report
|
|
377 ## ------------------------
|
|
378 zippedSize <- paste( round( file.info( gzipOutputPath )[["size"]] / 1000000, digits=2 ), 'MB' )
|
|
379 readCoSize <- paste( round( file.info( robjReadCoPath )[["size"]] / 1000000, digits=2 ), 'MB' )
|
|
380 copyNrSize <- paste( round( file.info( robjCopyNrPath )[["size"]] / 1000000, digits=2 ), 'MB' )
|
|
381 calledSize <- paste( round( file.info( robjCalledPath )[["size"]] / 1000000, digits=2 ), 'MB' )
|
|
382 regionSize <- paste( round( file.info( robjRegionPath )[["size"]] / 1000000, digits=2 ), 'MB' )
|
|
383
|
|
384 ## ------------------------
|
|
385 ## creating html output to be linked to from the middle galaxy pane
|
|
386 ## ------------------------
|
|
387
|
|
388 #sink( file = outputHtml, type = "output" )
|
|
389 sink( file = htmlOutputPath, type = "output" )
|
|
390 cat( "<html>\n")
|
|
391 cat( "<head>\n")
|
|
392 #cat( '<link rel="stylesheet" type="text/css" href="test.css" media="screen" />', "\n" )
|
|
393 #cat( '<link rel="stylesheet" type="text/css" href="../../../../static/style/test.css" media="screen" />',
|
|
394 cat( "\t", '<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.4.2/pure-min.css">', "\n" )
|
|
395 cat( "\t<style>\n")
|
|
396 ## have to include CSS into html file, because css referencing outside own dir doesn't seem to work...
|
|
397 cat( paste( "\t\t", '/* the css here originates from ', CSS_FILE,' */', "\n") )
|
|
398 cat( paste( "\t\t", readLines( CSS_FILE, n = -1)), sep="\n" )
|
|
399 #cat( "\t\th1 {color:red;}", "\n")
|
|
400
|
|
401 cat( "\t</style>\n" )
|
|
402
|
|
403 cat( "\n</head>\n")
|
|
404 cat( "\n<body>\n")
|
|
405
|
|
406 cat( "<h1>QDNAseq Report</h1>", "\n")
|
|
407
|
|
408 cat( '<h3 class="qdnaseq">About this analysis</h3>', "\n")
|
|
409 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='')
|
|
410 #cat( '<a href="#" class="button-success button-xsmall pure-button">test</a>' )
|
|
411
|
|
412
|
|
413 ## ------------------------
|
|
414 ## table with general info
|
|
415 ## ------------------------
|
|
416 cat( '<h3 class="qdnaseq">Settings</h3><p>', "\n")
|
|
417 cat( '<table class="pure-table pure-table-striped"><thead><tr><th>setting</th><th>value</th></tr></thead><tbody>' )
|
|
418 cat( htmlTableRow( c( "AnalysisName", outputName ) ) )
|
|
419 cat( htmlTableRow( c( "AnalysisDate", 'todo' ) ) )
|
|
420 cat( htmlTableRow( c( "BinSize (kb)", binSize ) ) )
|
|
421 #cat( htmlTableRow( c( "undoSD", undoSD ) ) )
|
|
422 #cat( htmlTableRow( c( "useBlacklist", filterBlacklistedBins ) ) )
|
|
423
|
|
424 for ( galaxyName in fileList[[ 'all_files' ]] ){
|
|
425 sampleName <- fileList[[ galaxyName ]]
|
|
426 cat( htmlTableRow( c( "InputBam", paste( galaxyName, ' (', sampleName, ')', sep='' ) ) ) )
|
|
427 }
|
|
428 cat( "</tbody></table></p>", "\n")
|
|
429
|
|
430 ## ------------------------
|
|
431 ## list with links to all output files
|
|
432 ## ------------------------
|
|
433 r_code <- '<p>'
|
|
434 r_code <- paste( r_code, '<code class="code">## R code to load files</code><br />', sep="\n" )
|
|
435 r_code <- paste( r_code, '<code class="code">library( QDNAseq )</code><br />', sep="\n")
|
|
436
|
|
437 cat( '<h3 class="qdnaseq">Output files</h3><p>', "\n")
|
|
438 cat( '<dl>', "\n" )
|
|
439 #cat( '<dt>Definition term</dt>', "\n", '<dd>Definition term</dd>', "\n" )
|
|
440 cat( '<dt>', htmlLink( path=robjReadCoName, robjReadCoName ), '</dt>', "\n" )
|
|
441 cat( '<dd>QDNAseq object with read counts per bin, ', readCoSize,'</dd>', "\n" )
|
|
442 r_code <- paste( r_code, '<code class="code">readCounts <- readRDS(', robjReadCoName, ")</code><br />", sep="")
|
|
443
|
|
444 cat( '<dt>', htmlLink( path=robjCopyNrName, robjCopyNrName ), '</dt>', "\n" )
|
|
445 cat( '<dd>QDNAseq object with copy numbers per bin, ', copyNrSize,'</dd>', "\n" )
|
|
446 r_code <- paste( r_code, '<code class="code">copyNumbersSmooth <- readRDS(', robjCopyNrName, ")</code><br />", sep="")
|
|
447
|
|
448 if ( doCall ){
|
|
449 cat( '<dt>', htmlLink( path=robjCalledName, robjCalledName ), '</dt>', "\n" )
|
|
450 cat( '<dd>QDNAseq object with segment and call status per bin, ', calledSize,'</dd>', "\n" )
|
|
451 r_code <- paste( r_code, '<code class="code">copyNumbersCalled <- readRDS(', robjCalledName, ")</code><br />", sep="")
|
|
452
|
|
453 cat( '<dt>', htmlLink( path=regiOutputName, regiOutputName ), '</dt>', "\n" )
|
|
454 cat( '<dd>list with segmented/called regions for each sample, ', regionSize, '</dd>', "\n" )
|
|
455 r_code <- paste( r_code, '<code class="code">calledRegions <- readRDS(', regiOutputName, ")</code><br />", sep="")
|
|
456
|
|
457 }
|
|
458 cat( '</dl></p>', "\n" )
|
|
459
|
25
|
460 #cat( r_code, "</p>\n", sep="\n")
|
2
|
461 cat( '<p>See ', htmlLink( WEB_LINK, 'the bioconductor QDNAseq documentation' ), ' for more information on how to work with these files</p>', "\n", sep='' )
|
|
462
|
|
463 ## ------------------------
|
|
464 ## table with links to files
|
|
465 ## ------------------------
|
|
466 cat( '<h3 class="qdnaseq">Results: overview</h3><p>', "\n")
|
|
467 plots_html <- ''
|
|
468
|
|
469 cat( '<table class="pure-table pure-table-striped"><thead><tr><th>Sample</th><th>CopyNumber</th><th>Called</th><th>ReadCount</th><th>RegionCount</th><th>Files</th></tr></thead><tbody>' )
|
|
470
|
|
471 for ( bam_file in sampleNames ){
|
|
472
|
|
473 #width <- 600; height <- 240
|
|
474 width <- PLOT_WIDTH; height <- PLOT_HEIGHT
|
|
475 width_t <- 100; height_t <- 40
|
|
476
|
|
477 ## add thumbnails to table with links to anchors on html page
|
|
478 copy_img <- plotted_images[[ bam_file ]][[ 'CopyNumbers' ]]
|
|
479 usedReads <- plotted_images[[ bam_file ]][[ 'usedReads' ]]
|
|
480 usedReads <- format( as.integer(usedReads), digits=4, decimal.mark=".", big.mark="," )
|
|
481
|
|
482 html_copy_thumb <- htmlLink( path=paste('#', copy_img, sep=''), paste('<img src="',copy_img,'" alt="', bam_file, '" width="', width_t, '" height="', height_t, '">', sep='') )
|
|
483 html_copy_img <- htmlLink( path=copy_img, paste('<img id="', copy_img,'" src="',copy_img,'" alt="',bam_file, '" width="', width, '" height="', height, '">', sep='') )
|
|
484 html_call_thumb <- 'NA'
|
|
485 html_call_img <- ''
|
|
486 html_bed <- 'NA'
|
|
487 html_bedGraph <- 'NA'
|
|
488 region_count <- 'NA'
|
|
489
|
|
490 if ( doCall ){
|
|
491 call_img <- plotted_images[[ bam_file ]][[ 'Called' ]]
|
|
492 region_count <- plotted_images[[ bam_file ]][[ 'region_count' ]]
|
|
493 html_call_thumb <- htmlLink( path=paste('#', call_img, sep=''), paste('<img src="', call_img, '" alt="', bam_file, '" width="', width_t,'" height="', height_t,'">', sep='') )
|
|
494
|
|
495 files <- printedFiles[[ bam_file ]]
|
|
496 html_bed <- htmlLink( path=files[1], 'bed' )
|
|
497 html_bedGraph <- htmlLink( path=files[2], 'bedGraph' )
|
|
498 html_call_img <- htmlLink( path=call_img, paste('<img id="', call_img,'" src="', call_img,'" alt="', bam_file, '" width="', width, '" height="', height,'">', sep='') )
|
|
499 }
|
|
500
|
|
501 ## add info to overview table, including small thumbnails
|
|
502 cat( htmlTableRow( c(bam_file, html_copy_thumb, html_call_thumb, usedReads, region_count, paste( html_bed, html_bedGraph, sep=", ")) ), "\n" )
|
|
503 ## now include (large) images in html page
|
|
504 plots_html <- paste( plots_html, html_copy_img, "\n", html_call_img, "\n<hr \\>\n", sep='' )
|
|
505 }
|
|
506 cat( "</tbody></table></p>", "\n")
|
|
507
|
|
508 ## add noise plot
|
|
509 html_noise_img <- htmlLink( path=noise_img_file, paste('<img id="', noise_img_file,'" src="',noise_img_file,'" alt="NoisePlot">', sep='') )
|
|
510 plots_html <- paste( plots_html, html_noise_img, "\n<hr \\>\n", sep='' )
|
|
511
|
|
512 ## ------------------------
|
|
513 ## section with various output shown
|
|
514 ## ------------------------
|
|
515 cat( '<h3 class="qdnaseq">Results: plots</h3><p>', "\n")
|
|
516 cat( plots_html, "\n")
|
|
517 cat( "\n</p></body>\n")
|
|
518 cat( "\n</html>\n")
|
|
519 sink()
|
|
520
|
|
521 ## ------------------------
|
|
522 ## creating html output to be viewed in middle galaxy pane
|
|
523 ## ------------------------
|
|
524 #sink( file = htmlOutputPath, type = "output" )
|
|
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")
|
|
531 ## have to include CSS into html file, because css referencing outside own dir doesn't seem to work...makes it more portable anyway :P
|
|
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
|
|
538 cat( '<h1>QDNAseq Results (', outputName,')</h1>', "\n", sep="")
|
|
539 cat( '<p>Explore <a href="', htmlOutputName, '" class="button-success button-small pure-button">the results</a> directly within galaxy</p>', "\n", sep="")
|
|
540 cat( '<p>Or download a <a href="', gzipOutputName, '" class="button-success button-small pure-button">zipfile</a> with all output (', zippedSize, ')</p>', "\n", sep="" )
|
|
541
|
|
542 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="")
|
|
543
|
|
544 sink()
|
|
545
|
|
546
|
|
547 cat( MAIN_NAME, "...zipping output\n")
|
|
548 zip_cmd <- paste( "zip -j ", gzipOutputPath, paste(outputPath,'/', htmlOutputName, sep='') ) ## -j is for removing dirs from the tree
|
|
549 system( zip_cmd )
|
|
550 cat( MAIN_NAME, "done...\n", sep="")
|
25
|
551 q(status=0)
|