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