OPM_DB {opm} | R Documentation |
These child classes of DBTABLES
from the
pkgutils package hold intermediary objects that can
be used for database input and output of
OPMX
objects. These classes are not
normally directly dealt with by an opm user but are
documented here for completeness. See
opm_dbput
for methods that internally use
these classes for database I/O.
See their documentation for details on OPMX
objects themselves. We here define the following
additional classes:
Holds all
data that occur in an OPM
object, or in
several such objects as contained in an
OPMS
object.
Holds all data
that occur in an OPMA
object, or in several
such objects as contained in an OPMS
object.
Holds all data that occur in an
OPMD
object, or in several such objects as
contained in an OPMS
object.
The
inheritance relationships thus mirror those of the
OPMX
objects (with the exception of
OPMS
). Conversion with as
is
implemented from all OPMX
classes to all
classes defined here. Lists can also be converted
provided they only contain OPMX
objects (or
lists of such objects).
Conversion in the other direction, yielding one of the
OPMX
classes, is also implemented.
Attempting to convert several plates to an
OPMX
class other than OPMS
will yield an error, however, as well as trying to
convert a single plate to OPMS
, or several
plates with distinct plate types. In contrast, conversion
to a list will work in all instances, and such a list
could further be processed with the opms
function, irrespective of the number of plates contained.
In contrast to the OPMX
classes, the three
ones defined here can be created using new
,
yielding empty objects. These can neither be converted to
OPMX
objects nor combined with them using
c
. Instead, they are useful in conjunction with
by
from the pkgutils package with
do_inline
set to TRUE
. They contain all
fkeys
information and can be filled using a
suitable FUN
argument.
methods::Methods methods::new opm::opms
Other classes: FOE
, MOPMX
,
OPM
, OPMA
,
OPMD
, OPMS
,
OPMX
, OPM_MCP_OUT
,
WMD
, WMDS
,
WMDX
, XOPMX
,
YAML_VIA_LIST
library(pkgutils)
## overview on the classes
showClass("OPM_DB")
## Class "OPM_DB" [package "opm"]
##
## Slots:
##
## Name: plates wells measurements
## Class: data.frame data.frame data.frame
##
## Extends: "DBTABLES"
##
## Known Subclasses:
## Class "OPMA_DB", directly
## Class "OPMD_DB", by class "OPMA_DB", distance 2
showClass("OPMA_DB")
## Class "OPMA_DB" [package "opm"]
##
## Slots:
##
## Name: plates wells measurements aggr_settings
## Class: data.frame data.frame data.frame data.frame
##
## Name: aggregated
## Class: data.frame
##
## Extends:
## Class "OPM_DB", directly
## Class "DBTABLES", by class "OPM_DB", distance 2
##
## Known Subclasses: "OPMD_DB"
showClass("OPMD_DB")
## Class "OPMD_DB" [package "opm"]
##
## Slots:
##
## Name: plates wells measurements aggr_settings
## Class: data.frame data.frame data.frame data.frame
##
## Name: aggregated disc_settings discretized
## Class: data.frame data.frame data.frame
##
## Extends:
## Class "OPMA_DB", directly
## Class "OPM_DB", by class "OPMA_DB", distance 2
## Class "DBTABLES", by class "OPMA_DB", distance 3
## show all conversions with as()
showMethods("coerce", classes = c("OPM_DB", "OPMA_DB", "OPMD_DB"))
## Function: coerce (package methods)
## from="MOPMX", to="OPMA_DB"
## from="MOPMX", to="OPMD_DB"
## from="MOPMX", to="OPM_DB"
## from="OPM", to="OPM_DB"
## from="OPMA", to="OPMA_DB"
## from="OPMA_DB", to="OPMA"
## from="OPMA_DB", to="OPMS"
## from="OPMA_DB", to="list"
## from="OPMD", to="OPMD_DB"
## from="OPMD_DB", to="OPMA_DB"
## from="OPMD_DB", to="OPMD"
## from="OPMD_DB", to="OPMS"
## from="OPMD_DB", to="OPM_DB"
## from="OPMD_DB", to="list"
## from="OPMS", to="OPMA_DB"
## from="OPMS", to="OPMD_DB"
## from="OPMS", to="OPM_DB"
## from="OPM_DB", to="MOPMX"
## from="OPM_DB", to="OPM"
## from="OPM_DB", to="OPMS"
## from="OPM_DB", to="list"
## from="list", to="OPMA_DB"
## from="list", to="OPMD_DB"
## from="list", to="OPM_DB"
## conversions back and forth, OPMD as starting point
(x <- as(vaas_1, "OPMD_DB"))
## An object of class 'OPMD_DB'.
## Number of rows in first table: 1
## Defined cross-references between tables:
## plates.machine_id machines.id
## wells.plate_id plates.id
## measurements.well_id
## wells.id
## aggr_settings.plate_id
## plates.id
## aggregated.well_id wells.id
## aggregated.aggr_setting_id
## aggr_settings.id
## disc_settings.plate_id
## plates.id
## discretized.well_id wells.id
## discretized.disc_setting_id
## disc_settings.id
(y <- as(x, "OPMD"))
## Class OPMD
## From file ./E. coli DSM
## 30083T_vim10_7B__1_28_PMX_0_8#30#2010_F_
## 7B_5.csv
## Hours measured 95.75
## Number of wells 96
## Plate type Gen III
## Position 07-B
## Setup time 2010-08-30 13:53:08
## Metadata 5
## Aggregated TRUE
## Discretized TRUE
stopifnot(
dim(y) == dim(vaas_1),
# numeric data remain except for rounding errors:
all.equal(measurements(y), measurements(vaas_1)),
all.equal(aggregated(y), aggregated(vaas_1)),
all.equal(discretized(y), discretized(vaas_1)),
# file names get normalized, hence CSV dat may get unequal:
!isTRUE(all.equal(csv_data(y), csv_data(vaas_1)))
)
(y <- try(as(x, "OPMS"), silent = TRUE))
## [1] "Error in validObject(.Object) : \n invalid class \"OPMS\" object: less than two plates submitted\n"
## attr(,"class")
## [1] "try-error"
## attr(,"condition")
## <simpleError in validObject(.Object): invalid class "OPMS" object: less than two plates submitted>
stopifnot(inherits(y, "try-error")) # does not work because only 1 plate
## conversions back and forth, OPMS as starting point
(small <- vaas_4[, , 11:15])
## 1
## Class OPMD
## From file ./E. coli DSM
## 18039_vim10_12B__1_28_PMX_0_8#30#2010_E_12B_5.csv
## Hours measured 95.75
## Number of wells 5
## Plate type Gen III
## Position 12-B
## Setup time 8/30/2010 1:19:11 PM
## Metadata 5
## Aggregated TRUE
## Discretized TRUE
##
## 2
## Class OPMD
## From file ./E. coli DSM
## 30083T_vim10_7B__1_28_PMX_0_8#30#2010_F_
## 7B_5.csv
## Hours measured 95.75
## Number of wells 5
## Plate type Gen III
## Position 7-B
## Setup time 8/30/2010 1:53:08 PM
## Metadata 5
## Aggregated TRUE
## Discretized TRUE
##
## 3
## Class OPMD
## From file ./P. aeruginosa DSM
## 1707_vim10_17B__1_28_PMX_0_8#30#2010_D_17B_5.csv
## Hours measured 95.75
## Number of wells 5
## Plate type Gen III
## Position 17-B
## Setup time 8/30/2010 12:31:46 PM
## Metadata 5
## Aggregated TRUE
## Discretized TRUE
##
## 4
## Class OPMD
## From file ./P. aeruginosa St.
## 429_vim10_22B__1_28_PMX_0_8#30#2010_C_22B_5.csv
## Hours measured 95.75
## Number of wells 5
## Plate type Gen III
## Position 22-B
## Setup time 8/30/2010 11:28:54 AM
## Metadata 5
## Aggregated TRUE
## Discretized TRUE
##
## => OPMS object with 4 plates (4 aggregated, 4 discretized) of type 'Gen III', 5 well(s) and about 384 time point(s).
(x <- as(small, "OPMD_DB"))
## An object of class 'OPMD_DB'.
## Number of rows in first table: 4
## Defined cross-references between tables:
## plates.machine_id machines.id
## wells.plate_id plates.id
## measurements.well_id
## wells.id
## aggr_settings.plate_id
## plates.id
## aggregated.well_id wells.id
## aggregated.aggr_setting_id
## aggr_settings.id
## disc_settings.plate_id
## plates.id
## discretized.well_id wells.id
## discretized.disc_setting_id
## disc_settings.id
(y <- as(x, "OPMS"))
## 1
## Class OPMD
## From file ./E. coli DSM
## 18039_vim10_12B__1_28_PMX_0_8#30#2010_E_12B_5.csv
## Hours measured 95.75
## Number of wells 5
## Plate type Gen III
## Position 12-B
## Setup time 2010-08-30 13:19:11
## Metadata 5
## Aggregated TRUE
## Discretized TRUE
##
## 2
## Class OPMD
## From file ./E. coli DSM
## 30083T_vim10_7B__1_28_PMX_0_8#30#2010_F_
## 7B_5.csv
## Hours measured 95.75
## Number of wells 5
## Plate type Gen III
## Position 07-B
## Setup time 2010-08-30 13:53:08
## Metadata 5
## Aggregated TRUE
## Discretized TRUE
##
## 3
## Class OPMD
## From file ./P. aeruginosa DSM
## 1707_vim10_17B__1_28_PMX_0_8#30#2010_D_17B_5.csv
## Hours measured 95.75
## Number of wells 5
## Plate type Gen III
## Position 17-B
## Setup time 2010-08-30 12:31:46
## Metadata 5
## Aggregated TRUE
## Discretized TRUE
##
## 4
## Class OPMD
## From file ./P. aeruginosa St.
## 429_vim10_22B__1_28_PMX_0_8#30#2010_C_22B_5.csv
## Hours measured 95.75
## Number of wells 5
## Plate type Gen III
## Position 22-B
## Setup time 2010-08-30 11:28:54
## Metadata 5
## Aggregated TRUE
## Discretized TRUE
##
## => OPMS object with 4 plates (4 aggregated, 4 discretized) of type 'Gen III', 5 well(s) and about 384 time point(s).
stopifnot(sapply(1:length(y), # same values
function(i) dim(y[i]) == dim(small[i])))
(y <- try(as(x, "OPMD"), silent = TRUE)) # does not work because > 1 plate
## [1] "Error in backward_OPM_to_list(from) : \n object does not contain a single plate\n"
## attr(,"class")
## [1] "try-error"
## attr(,"condition")
## <simpleError in backward_OPM_to_list(from): object does not contain a single plate>
stopifnot(inherits(y, "try-error"))
(y <- as(x, "list")) # one can always go through a list
## [[1]]
## Class OPMD
## From file ./E. coli DSM
## 18039_vim10_12B__1_28_PMX_0_8#30#2010_E_12B_5.csv
## Hours measured 95.75
## Number of wells 5
## Plate type Gen III
## Position 12-B
## Setup time 2010-08-30 13:19:11
## Metadata 5
## Aggregated TRUE
## Discretized TRUE
##
## [[2]]
## Class OPMD
## From file ./E. coli DSM
## 30083T_vim10_7B__1_28_PMX_0_8#30#2010_F_
## 7B_5.csv
## Hours measured 95.75
## Number of wells 5
## Plate type Gen III
## Position 07-B
## Setup time 2010-08-30 13:53:08
## Metadata 5
## Aggregated TRUE
## Discretized TRUE
##
## [[3]]
## Class OPMD
## From file ./P. aeruginosa DSM
## 1707_vim10_17B__1_28_PMX_0_8#30#2010_D_17B_5.csv
## Hours measured 95.75
## Number of wells 5
## Plate type Gen III
## Position 17-B
## Setup time 2010-08-30 12:31:46
## Metadata 5
## Aggregated TRUE
## Discretized TRUE
##
## [[4]]
## Class OPMD
## From file ./P. aeruginosa St.
## 429_vim10_22B__1_28_PMX_0_8#30#2010_C_22B_5.csv
## Hours measured 95.75
## Number of wells 5
## Plate type Gen III
## Position 22-B
## Setup time 2010-08-30 11:28:54
## Metadata 5
## Aggregated TRUE
## Discretized TRUE
stopifnot(sapply(y, is, "OPMD")) # opms() could now be called
## one can create new objects without data
(y <- new("OPMD_DB"))
## An object of class 'OPMD_DB'.
## Number of rows in first table: 0
## Defined cross-references between tables:
## plates.machine_id machines.id
## wells.plate_id plates.id
## measurements.well_id
## wells.id
## aggr_settings.plate_id
## plates.id
## aggregated.well_id wells.id
## aggregated.aggr_setting_id
## aggr_settings.id
## disc_settings.plate_id
## plates.id
## discretized.well_id wells.id
## discretized.disc_setting_id
## disc_settings.id
stopifnot(fkeys_valid(y), fkeys(y) == fkeys(x), !length(y))
# such objects cannot be converted to OPMX but can be filled using by()