PageRenderTime 30ms CodeModel.GetById 23ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/R/AllClasses.R

http://github.com/tengfei/visnab
R | 65 lines | 60 code | 5 blank | 0 comment | 8 complexity | df1bcc2251356cd4a942bce50fb2d94f MD5 | raw file
 1setClassUnion("BSgenomeORNULL",c("BSgenome","NULL"))
 2
 3setOldClass("QIcon")
 4setOldClass("QWidget")
 5setOldClass("QDockWidget")
 6setOldClass("QStackedWidget")
 7setOldClass("QMainWindow")
 8setOldClass("mutalist")
 9setOldClass("QGraphicsScene")
10setOldClass("QGraphicsView")
11setOldClass("Qanviz::RLayer")
12setOldClass("Qanviz::PlotView")
13setOldClass("mutaframe")
14
15setClassUnion("QWidgetORNULL",c("QWidget","NULL"))
16setClassUnion("QMainWindowORNULL",c("QMainWindow","NULL"))
17setClassUnion("QGraphicsSceneORNULL", c("QGraphicsScene","NULL"))
18setClassUnion("Qanviz::RLayerORNULL", c("Qanviz::RLayer","NULL"))
19setClassUnion("Qanviz::PlotViewORNULL", c("Qanviz::PlotView","NULL"))
20setClassUnion("numericORcharacter", c("numeric", "character"))
21setClassUnion("numericORNULL", c("numeric","NULL"))
22setClassUnion("logicalORNULL", c("logical","NULL"))
23
24
25setAs("MutableGRanges", "mutaframe", function(from) {
26  makeValueBindingFun <- function(cn) {
27    function(val) {
28      if (missing(val))
29        values(from)[[cn]]
30      else values(from)[[cn]] <- val
31    }
32  }
33  cn <- colnames(values(from))
34  closures <- sapply(, makeValueBindingFun)
35  makeBindingFun <- function(accessor) {
36    function(val) {
37      if (missing(val))
38        accessor(from)
39      else accessor(from) <- val
40    }
41  }
42  closures <- c(seqnames = makeBindingFun(seqnames),
43                start = makeBindingFun(start), end = makeBindingFun(end),
44                width = makeBindingFun(width), strand = makeBindingFun(strand),
45                closures)
46  mf <- do.call(mutaframe, closures)
47  from$elementMetadataChanged$connect(function(i, j) {
48    if (!is.null(j)) {
49      j <- j + 5 # take into account the location columns
50      notify_listeners(mf, i, j)
51    } else { ## Assumption: columns can be added/removed but not rows
52      newcn <- colnames(values(from))
53      newCols <- setdiff(newcn, cn)
54      for (newCol in newCols)
55        mf[[newCol]] <- values(from)[[newCol]]
56      remCols <- setdiff(cn, newcn)
57      for (remCol in remCols)
58        mf[[remCol]] <- NULL
59      cn <<- newcn
60    }
61  })
62  from$locationsChanged$connect(function(i) notify_listeners(mf, i, 1:5))
63  mf
64})
65