Mercurial > repos > stef > qdnaseq_test
comparison QDNAseq-export.R @ 27:f89205f51e27 draft default tip
Uploaded
| author | stef |
|---|---|
| date | Mon, 06 Jul 2015 05:41:08 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 26:069289631381 | 27:f89205f51e27 |
|---|---|
| 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 ## ================================================== | |
| 11 ## Start of analysis | |
| 12 ## ================================================== | |
| 13 MAIN_NAME <- '[INFO] ' | |
| 14 catMsg( "Starting QDNAseq-export wrapper" ) | |
| 15 | |
| 16 ## supress msg to allow R to finish with non-error msg | |
| 17 catMsg( "Loading R libraries" ) | |
| 18 suppressWarnings( suppressMessages( library( QDNAseq, quietly = TRUE ) ) ) | |
| 19 suppressWarnings( suppressMessages( library( CGHcall, quietly = TRUE ) ) ) | |
| 20 | |
| 21 ## only one param: the tmp config file | |
| 22 cmdLineArgs <- commandArgs(TRUE) | |
| 23 config <- cmdLineArgs[1] | |
| 24 | |
| 25 ## sourcing the config file will load all input params | |
| 26 ## many variables are imported via sourced "config" | |
| 27 source( config ) # outputFile, outputName, outputFormat, sampleIndex, filterBins | |
| 28 | |
| 29 systemUser <- system("whoami",T) | |
| 30 qdnaseqVersion <- packageDescription( "QDNAseq" )$Version | |
| 31 rVersion <- R.version.string | |
| 32 rPath <- R.home() | |
| 33 catMsg( c("QDNAseq version ", qdnaseqVersion) ) | |
| 34 catMsg( c( rVersion ) ) | |
| 35 qdnaseqObject <- readRDS( rdsFilePath ) | |
| 36 logTransform <- TRUE | |
| 37 | |
| 38 sampleNames <- sampleNames( qdnaseqObject ) | |
| 39 elements <- assayDataElementNames(qdnaseqObject) | |
| 40 element <- dataLevel | |
| 41 if (dataLevel == "segments") element <- "segmented" | |
| 42 if (element == "calls") logTransform <- FALSE | |
| 43 | |
| 44 ## sanity checks | |
| 45 if ( ! element %in% elements ) stop( paste( "Data-level \"", element, "\" not present in object", sep='') ) | |
| 46 if ( outputFormat == "bed" ){ | |
| 47 if ( sampleIndex == "None") stop("Bed option requires sample index") | |
| 48 if ( sampleIndex > length(sampleNames) ) stop("Chosen sample index not present in object") | |
| 49 qdnaseqObject <- qdnaseqObject[ ,sampleIndex] | |
| 50 } | |
| 51 | |
| 52 ## output | |
| 53 exportBins( qdnaseqObject, | |
| 54 file=outputFile, | |
| 55 format=outputFormat, | |
| 56 filter=filterBins, | |
| 57 type=dataLevel, | |
| 58 logTransform=logTransform | |
| 59 ) | |
| 60 | |
| 61 ## tell galaxy all seems ok | |
| 62 q(status=0) |
