Browse code

be more flexible when getting genome name

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

Michael Lawrence authored on 14/12/2016 18:20:28
Showing1 changed files

... ...
@@ -52,6 +52,17 @@ setMethod("genomeName", "character", function(x) x)
52 52
 setMethod("genomeName", "BSgenome", function(x) providerVersion(x))
53 53
 setMethods("genomeName", list("RTLFile", "RsamtoolsFile"),
54 54
            function(x) file_path_sans_ext(basename(path(x)), TRUE))
55
+setMethod("genomeName", "ANY", function(x) {
56
+    if (hasMethod("seqinfo", class(x))) {
57
+        ans <- unique(genome(x))
58
+        if (length(ans) > 1L) {
59
+            stop("genome is ambiguous")
60
+        }
61
+        ans
62
+    } else {
63
+        stop("cannot derive a genome name")
64
+    }
65
+})
55 66
 
56 67
 file_path_is_absolute <- function(x) {
57 68
   ## hack that is unlikely to work on e.g. Windows