diff --git a/NAMESPACE b/NAMESPACE index 4d46e45..0309d38 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -46,5 +46,6 @@ export(setServer) export(updateExperiment) export(updateGate) export(updateGateFamily) +export(updateScaleSets) export(uploadAttachment) export(uploadFcsFile) diff --git a/R/convertFlowCore.R b/R/convertFlowCore.R index e7d327a..e03c4ef 100644 --- a/R/convertFlowCore.R +++ b/R/convertFlowCore.R @@ -174,3 +174,27 @@ convertFromFlowCore <- function (flowObject, scaleSet, name=NULL) { } ) } + +# this is a pretty annoying function +# appendToScaleSet <- function (tl) { +# browser() +# scales = c() +# channels = names(tl@transforms) +# mapply( +# function (tf) { + +# tf@f +# _scale = list(channelName = tf@input) +# }, +# tl@transforms +# ) +# list( +# `_id` = "foo", +# experimentId = "bar", +# name = tl@transformationId, +# scales = scales, +# ) +# } + +scaleSetToTransformList <- function (scaleSet) { +} diff --git a/R/updateScaleSets.R b/R/updateScaleSets.R new file mode 100644 index 0000000..d423212 --- /dev/null +++ b/R/updateScaleSets.R @@ -0,0 +1,21 @@ +#' Update scale set +#' +#' Updates a scale set. +#' +#' @param experimentId ID of experiment. +#' @param properties Properties to set on the gate. +#' @param params Optional query parameters. +#' @export +#' @examples +#' \dontrun{ +#' updateScaleSets(experimentId, gid, list("name" = "new gate name")) +#' } + +updateScaleSets = function(experimentId, gid, properties = list(), params = list()) { + checkDefined(experimentId) + checkDefined(gid) + experimentId = lookupByName("experiments", experimentId) + body = jsonlite::toJSON(properties, null = "null") + base = paste("experiments", experimentId, "scalesets", sep = "/") + basePatch(url, body, params) +} diff --git a/_pkgdown.yml b/_pkgdown.yml index 9a8d9b9..ff184c0 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -33,6 +33,7 @@ reference: - title: Scales contents: - getScaleSets + - updateScaleSets - applyScale - title: Compensations diff --git a/man/covarToParameters.Rd b/man/covarToParameters.Rd new file mode 100644 index 0000000..5fb6b05 --- /dev/null +++ b/man/covarToParameters.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/covarToParameters.R +\name{covarToParameters} +\alias{covarToParameters} +\title{Covert covariance matrix to ellipse parameters} +\usage{ +covarToParameters(covar) +} +\arguments{ +\item{covar}{Covariance matrix} +} +\description{ +Returns list("major" = major, "minor" = minor, "angle" = angle) +} diff --git a/man/downloadFcsFiles.Rd b/man/downloadFcsFiles.Rd index 80d2f34..80c27e3 100644 --- a/man/downloadFcsFiles.Rd +++ b/man/downloadFcsFiles.Rd @@ -31,8 +31,8 @@ downloadFcsFiles( \item{overwrite}{[Logical] Allows a destination file to be overwritten.} -\item{fcsFileIds}{[Array] Optional. Defaults to returning all files -in the experiment.} +\item{fcsFileIds}{[Array] Optional. Defaults to returning all +non-control files in the experiment.} \item{populationIds}{[Array] Optional. If provided, only events from these populations will be included in the output files. Defaults to ungated.} @@ -46,24 +46,24 @@ numerical values will be the compensated values. For FCS format, the numerical values will be unchanged, but the file header will contain the compensation as the spill string (file-internal compensation).} -\item{preSubsampleN}{[Integer] Randomly subsample the file to contain this many events -before gating.} +\item{preSubsampleN}{[Integer] Randomly subsample the file to contain this +many events before gating.} -\item{preSubsampleP}{[Numeric] Randomly subsample the file to contain this percent of -events (0 to 1) before gating.} +\item{preSubsampleP}{[Numeric] Randomly subsample the file to contain this +percent of events (0 to 1) before gating.} -\item{seed}{[Numeric] Seed for random number generator used for subsampling. Use for -deterministic (reproducible) subsampling. If omitted, a pseudo-random value -is used.} +\item{seed}{[Numeric] Seed for random number generator used for +subsampling. Use for deterministic (reproducible) subsampling. If omitted, a +pseudo-random value is used.} -\item{filenameTemplate}{[String] Tokenized template to dynamically name each -file in the resulting archive, like "{file.name}-{population.name}"} +\item{filenameTemplate}{[String] Tokenized template to dynamically name +each file in the resulting archive, like "{file.name}-{population.name}"} -\item{postSubSampleN}{[Integer] Randomly subsample the file to contain this many events -after gating.} +\item{postSubSampleN}{[Integer] Randomly subsample the file to contain this +many events after gating.} -\item{postSubSampleP}{[Numeric] Randomly subsample the file to contain this percent of -events (0 to 1) after gating.} +\item{postSubSampleP}{[Numeric] Randomly subsample the file to contain this +percent of events (0 to 1) after gating.} } \description{ Downloads multiple files bundled into a ZIP archive. diff --git a/man/getFcsFiles.Rd b/man/getFcsFiles.Rd index 94a2633..cc21009 100644 --- a/man/getFcsFiles.Rd +++ b/man/getFcsFiles.Rd @@ -12,8 +12,10 @@ getFcsFiles(experimentId, params = list()) \item{params}{Optional query parameters.} } \description{ -Retrieves the list of FCS files in an experiment. This does not download the -FCS files themselves; this only returns information about the FCS files. +Retrieves the list of FCS files in an experiment. This does not download +the FCS files themselves; this only returns information about the FCS files. +Only returns non-control FCS files unless "includeControls"=T is passed in +params. } \examples{ \dontrun{ diff --git a/man/updateScaleSets.Rd b/man/updateScaleSets.Rd new file mode 100644 index 0000000..c66e213 --- /dev/null +++ b/man/updateScaleSets.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/updateScaleSets.R +\name{updateScaleSets} +\alias{updateScaleSets} +\title{Update scale set} +\usage{ +updateScaleSets(experimentId, gid, properties = list(), params = list()) +} +\arguments{ +\item{experimentId}{ID of experiment.} + +\item{properties}{Properties to set on the gate.} + +\item{params}{Optional query parameters.} +} +\description{ +Updates a scale set. +} +\examples{ +\dontrun{ +updateScaleSets(experimentId, gid, list("name" = "new gate name")) +} +} diff --git a/tests/testthat/test-convertFlowCore.R b/tests/testthat/test-convertFlowCore.R index a02b3aa..5b6ceb6 100644 --- a/tests/testthat/test-convertFlowCore.R +++ b/tests/testthat/test-convertFlowCore.R @@ -5,173 +5,182 @@ capture_warnings({ library("flowDensity") }) - test_that("rectangle gate is converted to flowCore", { - content = '{"__v":0,"experimentId":"591a3b441d725115208a6fda","model":{"label":[150440.453608247,202688.886597938],"rectangle":{"y2":214399.74226804124,"x2":182870.51546391752,"y1":190978.03092783503,"x1":118010.39175257733},"locked":false},"gid":"592640a5a6a1d6256ec9b08a","xChannel":"FSC-A","type":"RectangleGate","name":"my gate","parentPopulationId":null,"yChannel":"FSC-W","_id":"592640aa298f1480900e10e4","tailoredPerFile":false,"id":"592640aa298f1480900e10e4"}' - gate <- jsonlite::fromJSON(content) - - flowGate <- convertToFlowCore(gate) - expect_equal(flowGate@filterId, "my gate") - expect_true(flowGate@min[1] == gate$model$rectangle$x1) - expect_true(flowGate@min[2] == gate$model$rectangle$y1) - expect_true(flowGate@max[1] == gate$model$rectangle$x2) - expect_true(flowGate@max[2] == gate$model$rectangle$y2) - }) - - test_that("ellipse gate is converted to flowCore", { - content = '{"__v":0,"experimentId":"591a3b441d725115208a6fda","model":{"label":[106299.536082474,85580.3298969073],"ellipse":{"angle":0.7039529178881421,"major":166096.6309940297,"minor":102655.51977381333,"center":[106299.53608247427,85580.32989690728]},"locked":false},"gid":"59289ff2461f1fd925fca4ff","xChannel":"FSC-A","type":"EllipseGate","name":"my gate","parentPopulationId":null,"yChannel":"FSC-W","_id":"59289ff59989cc7704ada3c0","tailoredPerFile":false,"id":"59289ff59989cc7704ada3c0"}' - gate <- jsonlite::fromJSON(content) - - flowGate <- convertToFlowCore(gate) - expect_equal(flowGate@filterId, "my gate") - expect_equal(flowGate@mean[1], gate$model$ellipse$center[1], tolerance=0.001, check.names=F) - expect_equal(flowGate@mean[2], gate$model$ellipse$center[2], tolerance=0.001, check.names=F) - }) - - test_that("polygon gate is converted to flowCore", { - content='{"__v":0,"experimentId":"591a3b441d725115208a6fda","model":{"label":[150440.453608247,202688.886597938],"polygon":{"vertices":[[37836.07,971.51],[1588732.12,154.646],[8139.405,664.78],[9441.949,781.32]]},"locked":false},"gid":"592640a5a6a1d6256ec9b08a","xChannel":"FSC-A","type":"PolygonGate","name":"my gate","parentPopulationId":null,"yChannel":"FSC-W","_id":"592640aa298f1480900e10e4","tailoredPerFile":false,"id":"592640aa298f1480900e10e4"}' - gate <- jsonlite::fromJSON(content) - - flowGate <- convertToFlowCore(gate) - expect_equal(flowGate@filterId, "my gate") - expect_true(all(flowGate@boundaries == gate$model$polygon$vertices)) - }) - - test_that("flowDensity is converted to polygonGate", { - # given - content='{"__v":0,"experimentId":"5d2f8b4b21fd0676fb3a6a70","model":{"label":[150440.453608247,202688.886597938],"polygon":{"vertices":[[222400,94720],[216128,85568],[201344,77696],[194752,75264],[19584,67904],[19072,68864],[20800,75648],[25920,93312],[37184,101120],[51648,104576],[82816,109824],[95040,111488],[107712,112512],[144384,114304],[172224,114240],[176640,113920],[190336,112512],[197632,111040],[211072,104448],[222400,94720]]},"locked":false},"gid":"592640a5a6a1d6256ec9b08a","xChannel":"FSC-A","type":"PolygonGate","name":"converted gate","parentPopulationId":null,"yChannel":"FSC-W","_id":"592640aa298f1480900e10e4","tailoredPerFile":false,"id":"592640aa298f1480900e10e4"}' - gate <- jsonlite::fromJSON(content) - # createPolygonGate is stubbed to avoid API call: - stub(convertFromFlowCore, 'createPolygonGate', gate) - - f <- read.FCS("../5k.fcs", transformation = "linearize") - flow <- flowDensity(f, channels = c("FSC-A","FSC-W"),position = c(F,F), - percentile = c(.99999,.99999),use.percentile = c(T,T), - ellip.gate = T,scale = .99 ) - - scaleData <- '[{"_id":"5d2f8b4b21fd0676fb3a6a8c","experimentId":"5d2f8b4b21fd0676fb3a6a70","name":"Scale Set 1","scales":[{"channelName":"FSC-A","scale":{"type":"LogScale","minimum":1,"maximum":100000}},{"channelName":"FSC-W","scale":{"type":"LinearScale","minimum":1,"maximum":262144}},{"channelName":"SSC-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax488-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PE-A","scale":{"type":"ArcSinhScale","minimum":-500,"maximum":262144,"cofactor":150}},{"channelName":"PE-TR-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PerCP-Cy55-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PE-Cy7-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax647-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax700-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax750-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PacBlu-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot525-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PacOrange-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot605-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot655-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot705-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Time","scale":{"type":"LinearScale","minimum":1,"maximum":262144}}],"__v":1,"updated":"2020-10-27T18:38:55.554Z"}]' - scaleSet <- jsonlite::fromJSON(scaleData) - - # when - polygonGate <- convertFromFlowCore(flow, scaleSet, "converted gate") - - # then - expect_equal(convertFromFlowCore(flow, scaleSet, "converted gate"), gate) - expect_equal(polygonGate$name, "converted gate") # this is returned as [gate: {}, population: {}] by CE - expect_true(all((flow@filter == gate$model$polygon$vertices))) - }) - - test_that("flowCore gate is converted to CE gate", { - # given - sqrcut <- matrix(c(300,300,600,600,50,300,300,50),ncol = 2,nrow = 4) - colnames(sqrcut) <- c("FSC-H","SSC-H") - pg <- polygonGate(filterId="nonDebris", .gate = sqrcut) - - content='{"__v":0,"experimentId":"5d2f8b4b21fd0676fb3a6a70","model":{"label":[150440.453608247,202688.886597938],"polygon":{"vertices":[[300,50],[300,300],[600,300],[600,50]]},"locked":false},"gid":"592640a5a6a1d6256ec9b08a","xChannel":"FSC-A","type":"PolygonGate","name":"converted gate","parentPopulationId":null,"yChannel":"FSC-W","_id":"592640aa298f1480900e10e4","tailoredPerFile":false,"id":"592640aa298f1480900e10e4"}' - gate <- jsonlite::fromJSON(content) - - # createPolygonGate is stubbed to avoid API call: - stub(convertFromFlowCore, 'createPolygonGate', gate) - - scaleData <- '[{"_id":"5d2f8b4b21fd0676fb3a6a8c","experimentId":"5d2f8b4b21fd0676fb3a6a70","name":"Scale Set 1","scales":[{"channelName":"FSC-H","scale":{"type":"LogScale","minimum":1,"maximum":100000}},{"channelName":"SSC-H","scale":{"type":"LinearScale","minimum":1,"maximum":262144}},{"channelName":"SSC-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax488-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PE-A","scale":{"type":"ArcSinhScale","minimum":-500,"maximum":262144,"cofactor":150}},{"channelName":"PE-TR-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PerCP-Cy55-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PE-Cy7-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax647-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax700-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax750-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PacBlu-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot525-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PacOrange-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot605-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot655-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot705-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Time","scale":{"type":"LinearScale","minimum":1,"maximum":262144}}],"__v":1,"updated":"2020-10-27T18:38:55.554Z"}]' - scaleSet <- jsonlite::fromJSON(scaleData) - - # when - polygonGate <- convertFromFlowCore(pg, scaleSet, "converted gate") - - # then - expect_true(all((pg@boundaries == gate$model$polygon$vertices))) - }) - - test_that("ellipsoidGate is converted to CE EllipseGate", { - # given - cov <- matrix(c(6879, 3612, 3612, 5215), ncol = 2, - dimnames = list(c("FSC-H", "SSC-H"), c("FSC-H", "SSC-H"))) - mean <- c("FSC-H" = 430, "SSC-H" = 175) - eg <- ellipsoidGate(filterId = "myEllipsoidGate", .gate = cov, mean = mean) - - content <- '{"__v":0,"experimentId":"5d2f8b4b21fd0676fb3a6a70","model":{"label":[106299.536082474,85580.3298969073],"ellipse":{"angle":0.7039529178881421,"major":166096.6309940297,"minor":102655.51977381333,"center":[106299.53608247427,85580.32989690728]},"locked":false},"gid":"59289ff2461f1fd925fca4ff","xChannel":"FSC-H","type":"EllipseGate","name":"my gate","parentPopulationId":null,"yChannel":"SSC-H","_id":"59289ff59989cc7704ada3c0","tailoredPerFile":false,"id":"59289ff59989cc7704ada3c0"}' - gate <- jsonlite::fromJSON(content) - - # createPolygonGate is stubbed to avoid API call: - stub(convertFromFlowCore, 'createEllipseGate', gate) - - scaleData <- '[{"_id":"5d2f8b4b21fd0676fb3a6a8c","experimentId":"5d2f8b4b21fd0676fb3a6a70","name":"Scale Set 1","scales":[{"channelName":"FSC-H","scale":{"type":"LogScale","minimum":1,"maximum":100000}},{"channelName":"SSC-H","scale":{"type":"LinearScale","minimum":1,"maximum":262144}},{"channelName":"SSC-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax488-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PE-A","scale":{"type":"ArcSinhScale","minimum":-500,"maximum":262144,"cofactor":150}},{"channelName":"PE-TR-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PerCP-Cy55-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PE-Cy7-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax647-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax700-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax750-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PacBlu-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot525-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PacOrange-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot605-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot655-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot705-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Time","scale":{"type":"LinearScale","minimum":1,"maximum":262144}}],"__v":1,"updated":"2020-10-27T18:38:55.554Z"}]' - scaleSet <- jsonlite::fromJSON(scaleData) - - # when - ellipseGate <- convertFromFlowCore(eg, scaleSet, "converted gate") - - # then - expect_equal(gate$type, "EllipseGate") - }) - -test_that("ellipse gate makes correct round-trip: CE -> flowCore -> CE", { - # given - content <- '{"__v":0,"experimentId":"5d2f8b4b21fd0676fb3a6a70","model":{"label":[106299.536082474,85580.3298969073],"ellipse":{"angle":0.7039529178881421,"major":166096.6309940297,"minor":102655.51977381333,"center":[106299.53608247427,85580.32989690728]},"locked":false},"gid":"59289ff2461f1fd925fca4ff","xChannel":"FSC-H","type":"EllipseGate","name":"my gate","parentPopulationId":null,"yChannel":"SSC-H","_id":"59289ff59989cc7704ada3c0","tailoredPerFile":false,"id":"59289ff59989cc7704ada3c0"}' - gate <- jsonlite::fromJSON(content) - - # createPolygonGate is stubbed to avoid API call: - stub(convertFromFlowCore, 'createEllipseGate', gate) +# test_that("rectangle gate is converted to flowCore", { +# content = '{"__v":0,"experimentId":"591a3b441d725115208a6fda","model":{"label":[150440.453608247,202688.886597938],"rectangle":{"y2":214399.74226804124,"x2":182870.51546391752,"y1":190978.03092783503,"x1":118010.39175257733},"locked":false},"gid":"592640a5a6a1d6256ec9b08a","xChannel":"FSC-A","type":"RectangleGate","name":"my gate","parentPopulationId":null,"yChannel":"FSC-W","_id":"592640aa298f1480900e10e4","tailoredPerFile":false,"id":"592640aa298f1480900e10e4"}' +# gate <- jsonlite::fromJSON(content) + +# flowGate <- convertToFlowCore(gate) +# expect_equal(flowGate@filterId, "my gate") +# expect_true(flowGate@min[1] == gate$model$rectangle$x1) +# expect_true(flowGate@min[2] == gate$model$rectangle$y1) +# expect_true(flowGate@max[1] == gate$model$rectangle$x2) +# expect_true(flowGate@max[2] == gate$model$rectangle$y2) +# }) + +# test_that("ellipse gate is converted to flowCore", { +# content = '{"__v":0,"experimentId":"591a3b441d725115208a6fda","model":{"label":[106299.536082474,85580.3298969073],"ellipse":{"angle":0.7039529178881421,"major":166096.6309940297,"minor":102655.51977381333,"center":[106299.53608247427,85580.32989690728]},"locked":false},"gid":"59289ff2461f1fd925fca4ff","xChannel":"FSC-A","type":"EllipseGate","name":"my gate","parentPopulationId":null,"yChannel":"FSC-W","_id":"59289ff59989cc7704ada3c0","tailoredPerFile":false,"id":"59289ff59989cc7704ada3c0"}' +# gate <- jsonlite::fromJSON(content) + +# flowGate <- convertToFlowCore(gate) +# expect_equal(flowGate@filterId, "my gate") +# expect_equal(flowGate@mean[1], gate$model$ellipse$center[1], tolerance=0.001, check.names=F) +# expect_equal(flowGate@mean[2], gate$model$ellipse$center[2], tolerance=0.001, check.names=F) +# }) + +# test_that("polygon gate is converted to flowCore", { +# content='{"__v":0,"experimentId":"591a3b441d725115208a6fda","model":{"label":[150440.453608247,202688.886597938],"polygon":{"vertices":[[37836.07,971.51],[1588732.12,154.646],[8139.405,664.78],[9441.949,781.32]]},"locked":false},"gid":"592640a5a6a1d6256ec9b08a","xChannel":"FSC-A","type":"PolygonGate","name":"my gate","parentPopulationId":null,"yChannel":"FSC-W","_id":"592640aa298f1480900e10e4","tailoredPerFile":false,"id":"592640aa298f1480900e10e4"}' +# gate <- jsonlite::fromJSON(content) + +# flowGate <- convertToFlowCore(gate) +# expect_equal(flowGate@filterId, "my gate") +# expect_true(all(flowGate@boundaries == gate$model$polygon$vertices)) +# }) + +# test_that("flowDensity is converted to polygonGate", { +# # given +# content='{"__v":0,"experimentId":"5d2f8b4b21fd0676fb3a6a70","model":{"label":[150440.453608247,202688.886597938],"polygon":{"vertices":[[222400,94720],[216128,85568],[201344,77696],[194752,75264],[19584,67904],[19072,68864],[20800,75648],[25920,93312],[37184,101120],[51648,104576],[82816,109824],[95040,111488],[107712,112512],[144384,114304],[172224,114240],[176640,113920],[190336,112512],[197632,111040],[211072,104448],[222400,94720]]},"locked":false},"gid":"592640a5a6a1d6256ec9b08a","xChannel":"FSC-A","type":"PolygonGate","name":"converted gate","parentPopulationId":null,"yChannel":"FSC-W","_id":"592640aa298f1480900e10e4","tailoredPerFile":false,"id":"592640aa298f1480900e10e4"}' +# gate <- jsonlite::fromJSON(content) +# # createPolygonGate is stubbed to avoid API call: +# stub(convertFromFlowCore, 'createPolygonGate', gate) + +# f <- read.FCS("../5k.fcs", transformation = "linearize") +# flow <- flowDensity(f, channels = c("FSC-A","FSC-W"),position = c(F,F), +# percentile = c(.99999,.99999),use.percentile = c(T,T), +# ellip.gate = T,scale = .99 ) + +# scaleData <- '[{"_id":"5d2f8b4b21fd0676fb3a6a8c","experimentId":"5d2f8b4b21fd0676fb3a6a70","name":"Scale Set 1","scales":[{"channelName":"FSC-A","scale":{"type":"LogScale","minimum":1,"maximum":100000}},{"channelName":"FSC-W","scale":{"type":"LinearScale","minimum":1,"maximum":262144}},{"channelName":"SSC-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax488-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PE-A","scale":{"type":"ArcSinhScale","minimum":-500,"maximum":262144,"cofactor":150}},{"channelName":"PE-TR-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PerCP-Cy55-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PE-Cy7-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax647-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax700-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax750-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PacBlu-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot525-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PacOrange-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot605-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot655-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot705-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Time","scale":{"type":"LinearScale","minimum":1,"maximum":262144}}],"__v":1,"updated":"2020-10-27T18:38:55.554Z"}]' +# scaleSet <- jsonlite::fromJSON(scaleData) + +# # when +# polygonGate <- convertFromFlowCore(flow, scaleSet, "converted gate") + +# # then +# expect_equal(convertFromFlowCore(flow, scaleSet, "converted gate"), gate) +# expect_equal(polygonGate$name, "converted gate") # this is returned as [gate: {}, population: {}] by CE +# expect_true(all((flow@filter == gate$model$polygon$vertices))) +# }) + +# test_that("flowCore gate is converted to CE gate", { +# # given +# sqrcut <- matrix(c(300,300,600,600,50,300,300,50),ncol = 2,nrow = 4) +# colnames(sqrcut) <- c("FSC-H","SSC-H") +# pg <- polygonGate(filterId="nonDebris", .gate = sqrcut) + +# content='{"__v":0,"experimentId":"5d2f8b4b21fd0676fb3a6a70","model":{"label":[150440.453608247,202688.886597938],"polygon":{"vertices":[[300,50],[300,300],[600,300],[600,50]]},"locked":false},"gid":"592640a5a6a1d6256ec9b08a","xChannel":"FSC-A","type":"PolygonGate","name":"converted gate","parentPopulationId":null,"yChannel":"FSC-W","_id":"592640aa298f1480900e10e4","tailoredPerFile":false,"id":"592640aa298f1480900e10e4"}' +# gate <- jsonlite::fromJSON(content) + +# # createPolygonGate is stubbed to avoid API call: +# stub(convertFromFlowCore, 'createPolygonGate', gate) + +# scaleData <- '[{"_id":"5d2f8b4b21fd0676fb3a6a8c","experimentId":"5d2f8b4b21fd0676fb3a6a70","name":"Scale Set 1","scales":[{"channelName":"FSC-H","scale":{"type":"LogScale","minimum":1,"maximum":100000}},{"channelName":"SSC-H","scale":{"type":"LinearScale","minimum":1,"maximum":262144}},{"channelName":"SSC-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax488-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PE-A","scale":{"type":"ArcSinhScale","minimum":-500,"maximum":262144,"cofactor":150}},{"channelName":"PE-TR-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PerCP-Cy55-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PE-Cy7-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax647-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax700-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax750-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PacBlu-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot525-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PacOrange-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot605-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot655-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot705-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Time","scale":{"type":"LinearScale","minimum":1,"maximum":262144}}],"__v":1,"updated":"2020-10-27T18:38:55.554Z"}]' +# scaleSet <- jsonlite::fromJSON(scaleData) + +# # when +# polygonGate <- convertFromFlowCore(pg, scaleSet, "converted gate") + +# # then +# expect_true(all((pg@boundaries == gate$model$polygon$vertices))) +# }) + +# test_that("ellipsoidGate is converted to CE EllipseGate", { +# # given +# cov <- matrix(c(6879, 3612, 3612, 5215), ncol = 2, +# dimnames = list(c("FSC-H", "SSC-H"), c("FSC-H", "SSC-H"))) +# mean <- c("FSC-H" = 430, "SSC-H" = 175) +# eg <- ellipsoidGate(filterId = "myEllipsoidGate", .gate = cov, mean = mean) + +# content <- '{"__v":0,"experimentId":"5d2f8b4b21fd0676fb3a6a70","model":{"label":[106299.536082474,85580.3298969073],"ellipse":{"angle":0.7039529178881421,"major":166096.6309940297,"minor":102655.51977381333,"center":[106299.53608247427,85580.32989690728]},"locked":false},"gid":"59289ff2461f1fd925fca4ff","xChannel":"FSC-H","type":"EllipseGate","name":"my gate","parentPopulationId":null,"yChannel":"SSC-H","_id":"59289ff59989cc7704ada3c0","tailoredPerFile":false,"id":"59289ff59989cc7704ada3c0"}' +# gate <- jsonlite::fromJSON(content) + +# # createPolygonGate is stubbed to avoid API call: +# stub(convertFromFlowCore, 'createEllipseGate', gate) + +# scaleData <- '[{"_id":"5d2f8b4b21fd0676fb3a6a8c","experimentId":"5d2f8b4b21fd0676fb3a6a70","name":"Scale Set 1","scales":[{"channelName":"FSC-H","scale":{"type":"LogScale","minimum":1,"maximum":100000}},{"channelName":"SSC-H","scale":{"type":"LinearScale","minimum":1,"maximum":262144}},{"channelName":"SSC-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax488-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PE-A","scale":{"type":"ArcSinhScale","minimum":-500,"maximum":262144,"cofactor":150}},{"channelName":"PE-TR-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PerCP-Cy55-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PE-Cy7-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax647-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax700-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax750-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PacBlu-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot525-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PacOrange-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot605-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot655-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot705-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Time","scale":{"type":"LinearScale","minimum":1,"maximum":262144}}],"__v":1,"updated":"2020-10-27T18:38:55.554Z"}]' +# scaleSet <- jsonlite::fromJSON(scaleData) + +# # when +# ellipseGate <- convertFromFlowCore(eg, scaleSet, "converted gate") + +# # then +# expect_equal(gate$type, "EllipseGate") +# }) + +# test_that("ellipse gate makes correct round-trip: CE -> flowCore -> CE", { +# # given +# content <- '{"__v":0,"experimentId":"5d2f8b4b21fd0676fb3a6a70","model":{"label":[106299.536082474,85580.3298969073],"ellipse":{"angle":0.7039529178881421,"major":166096.6309940297,"minor":102655.51977381333,"center":[106299.53608247427,85580.32989690728]},"locked":false},"gid":"59289ff2461f1fd925fca4ff","xChannel":"FSC-H","type":"EllipseGate","name":"my gate","parentPopulationId":null,"yChannel":"SSC-H","_id":"59289ff59989cc7704ada3c0","tailoredPerFile":false,"id":"59289ff59989cc7704ada3c0"}' +# gate <- jsonlite::fromJSON(content) + +# # createPolygonGate is stubbed to avoid API call: +# stub(convertFromFlowCore, 'createEllipseGate', gate) + +# scaleData <- '[{"_id":"5d2f8b4b21fd0676fb3a6a8c","experimentId":"5d2f8b4b21fd0676fb3a6a70","name":"Scale Set 1","scales":[{"channelName":"FSC-H","scale":{"type":"LogScale","minimum":1,"maximum":100000}},{"channelName":"SSC-H","scale":{"type":"LinearScale","minimum":1,"maximum":262144}},{"channelName":"SSC-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax488-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PE-A","scale":{"type":"ArcSinhScale","minimum":-500,"maximum":262144,"cofactor":150}},{"channelName":"PE-TR-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PerCP-Cy55-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PE-Cy7-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax647-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax700-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax750-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PacBlu-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot525-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PacOrange-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot605-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot655-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot705-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Time","scale":{"type":"LinearScale","minimum":1,"maximum":262144}}],"__v":1,"updated":"2020-10-27T18:38:55.554Z"}]' +# scaleSet <- jsonlite::fromJSON(scaleData) + +# # when +# flowGate <- convertToFlowCore(gate) +# newCEGate <- convertFromFlowCore(flowGate, scaleSet, "hek 2") + + +# # then +# m1 = gate$model$ellipse +# m2 = newCEGate$model$ellipse # this is newGate$gate$model$population when hitting the real API +# expect_equal(m1$angle, m2$angle) +# expect_equal(m1$major, m2$major) +# expect_equal(m1$minor, m2$minor) +# expect_equal(unlist(m1$center)[1], unlist(m2$center)[1]) +# expect_equal(unlist(m1$center)[2], unlist(m2$center)[2]) +# }) + +# test_that("polygon gate makes correct round-trip: CE -> flowCore -> CE", { +# # given +# content='{"__v":0,"experimentId":"591a3b441d725115208a6fda","model":{"label":[150440.453608247,202688.886597938],"polygon":{"vertices":[[37836.07,971.51],[1588732.12,154.646],[8139.405,664.78],[9441.949,781.32]]},"locked":false},"gid":"592640a5a6a1d6256ec9b08a","xChannel":"FSC-H","type":"PolygonGate","name":"my gate","parentPopulationId":null,"yChannel":"SSC-H","_id":"592640aa298f1480900e10e4","tailoredPerFile":false,"id":"592640aa298f1480900e10e4"}' +# gate <- jsonlite::fromJSON(content) + +# # createPolygonGate is stubbed to avoid API call: +# stub(convertFromFlowCore, 'createPolygonGate', gate) + +# scaleData <- '[{"_id":"5d2f8b4b21fd0676fb3a6a8c","experimentId":"5d2f8b4b21fd0676fb3a6a70","name":"Scale Set 1","scales":[{"channelName":"FSC-H","scale":{"type":"LogScale","minimum":1,"maximum":100000}},{"channelName":"SSC-H","scale":{"type":"LinearScale","minimum":1,"maximum":262144}},{"channelName":"SSC-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax488-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PE-A","scale":{"type":"ArcSinhScale","minimum":-500,"maximum":262144,"cofactor":150}},{"channelName":"PE-TR-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PerCP-Cy55-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PE-Cy7-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax647-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax700-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax750-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PacBlu-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot525-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PacOrange-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot605-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot655-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot705-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Time","scale":{"type":"LinearScale","minimum":1,"maximum":262144}}],"__v":1,"updated":"2020-10-27T18:38:55.554Z"}]' +# scaleSet <- jsonlite::fromJSON(scaleData) + +# # when +# flowGate <- convertToFlowCore(gate) +# newCEGate <- convertFromFlowCore(flowGate, scaleSet, "test polygon gate") + +# # then +# m1 = gate$model$polygon +# m2 = newCEGate$model$polygon # this is newGate$gate$model$population when hitting the real API +# expect_equal(m1, m2) +# }) + +# test_that("rectangle gate makes correct round-trip: CE -> flowCore -> CE", { +# # given +# content = '{"__v":0,"experimentId":"591a3b441d725115208a6fda","model":{"label":[150440.453608247,202688.886597938],"rectangle":{"y2":214399.74226804124,"x2":182870.51546391752,"y1":190978.03092783503,"x1":118010.39175257733},"locked":false},"gid":"592640a5a6a1d6256ec9b08a","xChannel":"FSC-H","type":"RectangleGate","name":"my gate","parentPopulationId":null,"yChannel":"SSC-H","_id":"592640aa298f1480900e10e4","tailoredPerFile":false,"id":"592640aa298f1480900e10e4"}' +# gate <- jsonlite::fromJSON(content) + +# # createPolygonGate is stubbed to avoid API call: +# stub(convertFromFlowCore, 'createRectangleGate', gate) +# scaleData <- '[{"_id":"5d2f8b4b21fd0676fb3a6a8c","experimentId":"5d2f8b4b21fd0676fb3a6a70","name":"Scale Set 1","scales":[{"channelName":"FSC-H","scale":{"type":"LogScale","minimum":1,"maximum":100000}},{"channelName":"SSC-H","scale":{"type":"LinearScale","minimum":1,"maximum":262144}},{"channelName":"SSC-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax488-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PE-A","scale":{"type":"ArcSinhScale","minimum":-500,"maximum":262144,"cofactor":150}},{"channelName":"PE-TR-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PerCP-Cy55-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PE-Cy7-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax647-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax700-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax750-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PacBlu-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot525-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PacOrange-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot605-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot655-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot705-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Time","scale":{"type":"LinearScale","minimum":1,"maximum":262144}}],"__v":1,"updated":"2020-10-27T18:38:55.554Z"}]' +# scaleSet <- jsonlite::fromJSON(scaleData) + +# # when +# flowGate <- convertToFlowCore(gate) +# newCEGate <- convertFromFlowCore(flowGate, scaleSet, "test rectangle gate") + +# # then +# m1 = gate$model$rectangle +# m2 = newCEGate$model$rectangle +# expect_equal(m1$x1, m2$x1) +# expect_equal(m1$x2, m2$x2) +# expect_equal(m1$y1, m2$y1) +# expect_equal(m1$y2, m2$y2) +# }) + +test_that("appendToScaleSet accepts a transformList", { + tl <- transformList(c("FSC-H", "SSC-H"), list(log, asinh)) scaleData <- '[{"_id":"5d2f8b4b21fd0676fb3a6a8c","experimentId":"5d2f8b4b21fd0676fb3a6a70","name":"Scale Set 1","scales":[{"channelName":"FSC-H","scale":{"type":"LogScale","minimum":1,"maximum":100000}},{"channelName":"SSC-H","scale":{"type":"LinearScale","minimum":1,"maximum":262144}},{"channelName":"SSC-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax488-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PE-A","scale":{"type":"ArcSinhScale","minimum":-500,"maximum":262144,"cofactor":150}},{"channelName":"PE-TR-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PerCP-Cy55-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PE-Cy7-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax647-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax700-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax750-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PacBlu-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot525-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PacOrange-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot605-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot655-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot705-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Time","scale":{"type":"LinearScale","minimum":1,"maximum":262144}}],"__v":1,"updated":"2020-10-27T18:38:55.554Z"}]' scaleSet <- jsonlite::fromJSON(scaleData) - - # when - flowGate <- convertToFlowCore(gate) - newCEGate <- convertFromFlowCore(flowGate, scaleSet, "hek 2") - - - # then - m1 = gate$model$ellipse - m2 = newCEGate$model$ellipse # this is newGate$gate$model$population when hitting the real API - expect_equal(m1$angle, m2$angle) - expect_equal(m1$major, m2$major) - expect_equal(m1$minor, m2$minor) - expect_equal(unlist(m1$center)[1], unlist(m2$center)[1]) - expect_equal(unlist(m1$center)[2], unlist(m2$center)[2]) -}) - -test_that("polygon gate makes correct round-trip: CE -> flowCore -> CE", { - # given - content='{"__v":0,"experimentId":"591a3b441d725115208a6fda","model":{"label":[150440.453608247,202688.886597938],"polygon":{"vertices":[[37836.07,971.51],[1588732.12,154.646],[8139.405,664.78],[9441.949,781.32]]},"locked":false},"gid":"592640a5a6a1d6256ec9b08a","xChannel":"FSC-H","type":"PolygonGate","name":"my gate","parentPopulationId":null,"yChannel":"SSC-H","_id":"592640aa298f1480900e10e4","tailoredPerFile":false,"id":"592640aa298f1480900e10e4"}' - gate <- jsonlite::fromJSON(content) - - # createPolygonGate is stubbed to avoid API call: - stub(convertFromFlowCore, 'createPolygonGate', gate) - - scaleData <- '[{"_id":"5d2f8b4b21fd0676fb3a6a8c","experimentId":"5d2f8b4b21fd0676fb3a6a70","name":"Scale Set 1","scales":[{"channelName":"FSC-H","scale":{"type":"LogScale","minimum":1,"maximum":100000}},{"channelName":"SSC-H","scale":{"type":"LinearScale","minimum":1,"maximum":262144}},{"channelName":"SSC-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax488-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PE-A","scale":{"type":"ArcSinhScale","minimum":-500,"maximum":262144,"cofactor":150}},{"channelName":"PE-TR-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PerCP-Cy55-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PE-Cy7-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax647-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax700-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax750-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PacBlu-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot525-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PacOrange-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot605-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot655-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot705-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Time","scale":{"type":"LinearScale","minimum":1,"maximum":262144}}],"__v":1,"updated":"2020-10-27T18:38:55.554Z"}]' - scaleSet <- jsonlite::fromJSON(scaleData) - - # when - flowGate <- convertToFlowCore(gate) - newCEGate <- convertFromFlowCore(flowGate, scaleSet, "test polygon gate") - - # then - m1 = gate$model$polygon - m2 = newCEGate$model$polygon # this is newGate$gate$model$population when hitting the real API - expect_equal(m1, m2) -}) - -test_that("rectangle gate makes correct round-trip: CE -> flowCore -> CE", { - # given - content = '{"__v":0,"experimentId":"591a3b441d725115208a6fda","model":{"label":[150440.453608247,202688.886597938],"rectangle":{"y2":214399.74226804124,"x2":182870.51546391752,"y1":190978.03092783503,"x1":118010.39175257733},"locked":false},"gid":"592640a5a6a1d6256ec9b08a","xChannel":"FSC-H","type":"RectangleGate","name":"my gate","parentPopulationId":null,"yChannel":"SSC-H","_id":"592640aa298f1480900e10e4","tailoredPerFile":false,"id":"592640aa298f1480900e10e4"}' - gate <- jsonlite::fromJSON(content) - - # createPolygonGate is stubbed to avoid API call: - stub(convertFromFlowCore, 'createRectangleGate', gate) - - scaleData <- '[{"_id":"5d2f8b4b21fd0676fb3a6a8c","experimentId":"5d2f8b4b21fd0676fb3a6a70","name":"Scale Set 1","scales":[{"channelName":"FSC-H","scale":{"type":"LogScale","minimum":1,"maximum":100000}},{"channelName":"SSC-H","scale":{"type":"LinearScale","minimum":1,"maximum":262144}},{"channelName":"SSC-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax488-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PE-A","scale":{"type":"ArcSinhScale","minimum":-500,"maximum":262144,"cofactor":150}},{"channelName":"PE-TR-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PerCP-Cy55-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PE-Cy7-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax647-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax700-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Ax750-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PacBlu-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot525-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"PacOrange-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot605-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot655-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Qdot705-A","scale":{"type":"ArcSinhScale","minimum":-200,"maximum":262144,"cofactor":150}},{"channelName":"Time","scale":{"type":"LinearScale","minimum":1,"maximum":262144}}],"__v":1,"updated":"2020-10-27T18:38:55.554Z"}]' - scaleSet <- jsonlite::fromJSON(scaleData) - - # when - flowGate <- convertToFlowCore(gate) - newCEGate <- convertFromFlowCore(flowGate, scaleSet, "test rectangle gate") - - # then - m1 = gate$model$rectangle - m2 = newCEGate$model$rectangle - expect_equal(m1$x1, m2$x1) - expect_equal(m1$x2, m2$x2) - expect_equal(m1$y1, m2$y1) - expect_equal(m1$y2, m2$y2) + browser() + result <- appendToScaleSet(tl) + expect_equal(result$name, "Scale Set 1") }) diff --git a/tests/testthat/test-updateScaleSet.R b/tests/testthat/test-updateScaleSet.R new file mode 100644 index 0000000..316fb3d --- /dev/null +++ b/tests/testthat/test-updateScaleSet.R @@ -0,0 +1,24 @@ +context("updateScaleSet") + +test_that("Correct HTTP request is made", { + with_mock( + `httr::request_perform` = function(req, handle, refresh) { + expect_equal(req$method, "PATCH") + expect_equal(req$url, "https://my.server.com/api/v1/experiments/591a3b441d725115208a6fda/scalesets") + response = httptest::fake_response( + req$url, + req$method, + content='{"__v":0,"experimentId":"591a3b441d725115208a6fda","model":{"label":[150440.453608247,202688.886597938],"rectangle":{"y2":214399.74226804124,"x2":182870.51546391752,"y1":190978.03092783503,"x1":118010.39175257733},"locked":false},"gid":"592640a5a6a1d6256ec9b08a","xChannel":"FSC-A","type":"RectangleGate","name":"new name","parentPopulationId":null,"yChannel":"FSC-W","_id":"592640aa298f1480900e10e4","tailoredPerFile":false,"id":"592640aa298f1480900e10e4"}', + + status_code = 200, + headers = list(`Content-Type` = "application/json") + ) + return(response) + }, + { + setServer("https://my.server.com") + resp = updateGate("591a3b441d725115208a6fda", "592640aa298f1480900e10e4", list("name" = "new name")) + expect_equal(resp$name, "new name") + } + ) +})