Browse code

Function to merge celdaLists. Fixes #10

Sean Corbett authored on 07/01/2019 20:00:55
Showing 4 changed files

... ...
@@ -1,6 +1,7 @@
1 1
 # Generated by roxygen2: do not edit by hand
2 2
 
3 3
 export(DeconX)
4
+export(appendCeldaList)
4 5
 export(available_models)
5 6
 export(bestLogLikelihood)
6 7
 export(celda)
... ...
@@ -143,6 +143,27 @@ setMethod("celdaPerplexity",
143 143
            function(celda.mod){  celda.mod@perplexity  })
144 144
 
145 145
 
146
+#' @title Append two celdaList objects
147
+#' @description Returns a single celdaList representing the combination of two provided celdaList objects.
148
+#' @return A celdaList object. This object contains all resList entries and runParam records from both lists.
149
+#' @examples
150
+#' appended.list = appendCeldaList(celda.CG.grid.search.res, celda.CG.grid.search.res)
151
+#' @export
152
+appendCeldaList = function(list1, list2) {
153
+  if (!is.element("celdaList", class(list1)) | !is.element("celdaList", class(list2))) {
154
+    stop("Both parameters to appendCeldaList must be of class celdaList.")
155
+  }
156
+  if (!(list1@count.checksum == list2@count.checksum)) {
157
+    warning("Provided lists have different count.checksums and may have been generated from different count matrices. Using checksum from first list...")
158
+  }
159
+  newList = methods::new("celdaList",
160
+                         run.params = dplyr::bind_rows(list1@run.params, list2@run.params),
161
+                         res.list = c(list1@res.list, list2@res.list),
162
+                         count.checksum = list1@count.checksum,
163
+                         perplexity = matrix(nrow=0, ncol=0))
164
+  return(newList)
165
+}
166
+
146 167
 ################################################################################
147 168
 # Generics
148 169
 ################################################################################
149 170
new file mode 100644
... ...
@@ -0,0 +1,17 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/all_generics.R
3
+\name{appendCeldaList}
4
+\alias{appendCeldaList}
5
+\title{Append two celdaList objects}
6
+\usage{
7
+appendCeldaList(list1, list2)
8
+}
9
+\value{
10
+A celdaList object. This object contains all resList entries and runParam records from both lists.
11
+}
12
+\description{
13
+Returns a single celdaList representing the combination of two provided celdaList objects.
14
+}
15
+\examples{
16
+appended.list = appendCeldaList(celda.CG.grid.search.res, celda.CG.grid.search.res)
17
+}
... ...
@@ -12,3 +12,14 @@ test_that(desc = "Testing compareCountMatrix with numeric matrix input", {
12 12
   expect_true(compareCountMatrix(counts, model_CG, error.on.mismatch = TRUE))
13 13
 })
14 14
 
15
+test_that(desc = "Testing appendCeldaList", {
16
+  eg.list = celda::celda.CG.grid.search.res
17
+  expect_error(appendCeldaList(eg.list, matrix(0)),
18
+               "Both parameters to appendCeldaList must be of class celdaList.")
19
+  modified.eg.list = eg.list
20
+  modified.eg.list@count.checksum = "abcd12345"
21
+  expect_warning(appendCeldaList(eg.list, modified.eg.list),
22
+                 "Provided lists have different count.checksums and may have been generated from different count matrices. Using checksum from first list...")
23
+  expect_equal(length(eg.list@res.list)*2,
24
+               length(appendCeldaList(eg.list, eg.list)@res.list))
25
+})
15 26
\ No newline at end of file