Browse code

*gmapR option name for returning system calls is now "systemCallMode"

*asSystemCall.R added

*previous code that calls .system had to account for the case of when
getOption("systemCallMode") is TRUE. Since exception is now being
thrown, this logic was removed from gsnap() function

*LungCancerLines no longer mentioned in NAMESPACE


git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/gmapR@69338 bc3139a8-67e5-0310-9ffc-ced21a209358

Cory Barr authored on 11/09/2012 22:12:30
Showing 5 changed files

... ...
@@ -10,7 +10,7 @@ Description: GSNAP and GMAP are a pair of tools to align short-read
10 10
     to work with GMAP and GSNAP from within R. In addition, it provides 
11 11
     methods to tally alignment results on a per-nucleotide basis using 
12 12
     the bam_tally tool.
13
-Version: 0.99.17
13
+Version: 0.99.18
14 14
 Depends: R (>= 2.15.0), methods, GenomicRanges
15 15
 Imports: IRanges, Rsamtools (>= 1.7.4), rtracklayer (>= 1.17.15), GenomicRanges,
16 16
          GenomicFeatures, Biostrings, VariantAnnotation, tools, Biobase
... ...
@@ -43,4 +43,5 @@ Collate: GmapBamReader-class.R
43 43
          makeGmapGenomePackage.R
44 44
          TP53Genome.R
45 45
          utils.R
46
-         
46
+	 asSystemCall.R
47
+         
47 48
\ No newline at end of file
... ...
@@ -8,7 +8,6 @@ importFrom(Biobase, createPackage)
8 8
 import(IRanges)
9 9
 import(GenomicRanges)
10 10
 import(parallel)
11
-import(LungCancerLines)
12 11
 importFrom(Biostrings, getSeq, read.DNAStringSet)
13 12
 importFrom(GenomicRanges, genome, seqinfo)
14 13
 importMethodsFrom(GenomicRanges, seqnames, strand)
15 14
new file mode 100644
... ...
@@ -0,0 +1,11 @@
1
+##written to get the string of the system call rather than having the
2
+##system call actually executed. Initial motivation was for unit
3
+##testing.
4
+asSystemCall <- function(x) {
5
+  expr <- substitute(x)
6
+  options(systemCallMode = TRUE)
7
+  on.exit(options(systemCallMode = FALSE))
8
+  error <- tryCatch(eval(expr, parent.frame()),
9
+                         error = function(e) return(e))
10
+  error$systemCall
11
+}
... ...
@@ -38,20 +38,13 @@ setMethod("gsnap", c("character", "characterORNULL", "GsnapParam"),
38 38
                          c(list(.input_a = input_a, .input_b = input_b,
39 39
                                 format = "sam"),
40 40
                            params_list))
41
-            ##users can provide a function to the "gmapRSysCall"
42
-            ##option. If this has happened, the return value of .gsnap
43
-            ##(and consequently .system) is returned instead of a
44
-            ##GsnapOutput object
45
-            if (is.null(getOption("gmapRSysCall"))) {
46
-              gsnap_output <- GsnapOutput(path = output_path,
47
-                                          version = gsnapVersion(),
48
-                                          param = params)
49
-              asBam(gsnap_output)
50
-              if (consolidate)
51
-                consolidate(gsnap_output)
52
-              res <- gsnap_output
53
-            }
54
-            return(res)
41
+            gsnap_output <- GsnapOutput(path = output_path,
42
+                                        version = gsnapVersion(),
43
+                                        param = params)
44
+            asBam(gsnap_output)
45
+            if (consolidate)
46
+              consolidate(gsnap_output)
47
+            return(gsnap_output)
55 48
           })
56 49
 
57 50
 ### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
... ...
@@ -100,15 +100,16 @@ commandLine <- function(binary = "gsnap",
100 100
 ## at some point, mxbay want to customize this
101 101
 .system <- function(...) {
102 102
 
103
-  sysopt <- getOption("gmapRSysCall")
104
-  
105
-  if (is.null(sysopt)) {
106
-    res <- system(...)
107
-  } else if (class(sysopt) == "function") {
108
-    res <- sysopt(...)
103
+  if (is.null(getOption("systemCallMode"))) {
104
+    options(systemCallMode = FALSE)
105
+  }
106
+
107
+  sysCallModeStatus <- getOption("systemCallMode")
108
+  if (sysCallModeStatus == TRUE) {
109
+    error <- simpleError("system command")
110
+    error$systemCall <- as.character(as.list(...))
111
+    stop(error)
109 112
   } else {
110
-    stop("If the gmapRSysCall option is provided, it must be a function.")
113
+    system(...)
111 114
   }
112
-  
113
-  return(res)
114 115
 }