4141# ' # Plot exposure data
4242# ' plot(geoTox, type = "exposure", ncol = 5)
4343# ' # Plot response data
44- # ' plot(geoTox)
4544# ' plot(geoTox, assays = "TOX21_H2AX_HTRF_CHO_Agonist_ratio")
4645# ' # Plot sensitivity data
47- # ' plot(geoTox, type = "sensitivity")
48- # ' plot(geoTox, type = "sensitivity", assay = "TOX21_H2AX_HTRF_CHO_Agonist_ratio")
46+ # ' plot(geoTox,
47+ # ' type = "sensitivity",
48+ # ' assay = "TOX21_H2AX_HTRF_CHO_Agonist_ratio")
4949GeoTox <- function () {
5050 structure(
5151 list (
@@ -70,78 +70,104 @@ GeoTox <- function() {
7070# ' @export
7171print.GeoTox <- function (x , ... ) {
7272
73- names_simulated <- c(" age" , " IR" , " obesity" , " C_ext" , " C_ss" )
74- names_computed <- c(" D_int" , " C_invitro" , " resp" , " sensitivity" )
75- names_other <- setdiff(names(x ),
76- c(names_simulated , names_computed ))
77-
78- get_info <- function (names ) {
79- info <- lapply(names , \(name ) {
80- class <- dim <- " "
81- if (is.null(x [[name ]])) {
82- return (data.frame (Name = name , Class = " " , Dim = " " ))
83- }
84- is_list <- inherits(x [[name ]], " list" )
85- if (is_list && length(x [[name ]]) > 0 ) {
86- item <- x [[name ]][[1 ]]
87- } else if (! is_list ) {
88- item <- x [[name ]]
89- } else {
90- item <- NULL
91- }
92- class <- class(item )
93- if (any(c(" matrix" , " data.frame" ) %in% class )) {
94- dim <- paste(dim(item ), collapse = " x " )
95- } else {
96- dim <- length(item )
97- }
98- if (is_list ) {
99- dim <- paste0(length(x [[name ]]), " x (" , dim , " )" )
100- class <- paste0(" list(" , class [[1 ]], " )" )
101- } else {
102- class <- paste(class , collapse = " , " )
103- }
104- data.frame (Name = name , Class = class , Dim = dim )
105- })
106- do.call(rbind , info )
107- }
108-
109- info_simulated <- get_info(names_simulated )
110- info_simulated <- info_simulated [info_simulated $ Class != " " , , drop = FALSE ]
111- info_computed <- get_info(names_computed )
112- info_computed <- info_computed [info_computed $ Class != " " , , drop = FALSE ]
113-
114- cat(" GeoTox object\n " )
73+ # Get n_assay and n_chem from GeoTox()$hill_params
11574 if (is.null(x $ hill_params )) {
116- n_assays <- 0
117- n_chems <- 0
75+ n_assay <- 0
76+ n_chem <- 0
11877 } else {
11978 if (" assay" %in% names(x $ hill_params )) {
120- n_assays <- length(unique(x $ hill_params $ assay ))
79+ n_assay <- length(unique(x $ hill_params $ assay ))
12180 } else {
122- n_assays <- 1
81+ n_assay <- 1
12382 }
12483 if (" chem" %in% names(x $ hill_params )) {
125- n_chems <- length(unique(x $ hill_params $ chem ))
84+ n_chem <- length(unique(x $ hill_params $ chem ))
12685 } else {
127- n_chems <- 1
86+ n_chem <- 1
87+ }
88+ }
89+
90+ # Categorize different GeoTox() fields
91+ names_data_vec <- c(" age" , " IR" , " obesity" )
92+ names_data_mat <- c(" C_ext" , " C_ss" )
93+ names_computed_mat <- c(" D_int" , " C_invitro" )
94+ names_computed_df <- c(" resp" )
95+ names_computed_list <- c(" sensitivity" )
96+ names_other <- setdiff(names(x ),
97+ c(names_data_vec , names_data_mat ,
98+ names_computed_mat , names_computed_df ,
99+ names_computed_list ))
100+
101+ # Functions to get size info for each type of field
102+ # m = number of regions
103+ # n = population size
104+ get_info_vec <- function (name ) {
105+ size <- ifelse(is.null(x [[name ]]), " " , " m * (n)" )
106+ data.frame (Name = name , Size = size )
107+ }
108+ get_info_mat <- function (name ) {
109+ size <- " "
110+ if (! is.null(x [[name ]])) {
111+ dim <- dim(x [[name ]][[1 ]])
112+ size <- paste0(" m * (n x " , dim [2 ], " )" )
113+ }
114+ data.frame (Name = name , Size = size )
115+ }
116+ get_info_df <- function (name ) {
117+ size <- " "
118+ if (! is.null(x [[name ]])) {
119+ dim <- dim(x [[name ]][[1 ]])
120+ size <- paste0(" m * (" , n_assay , " * n x " , dim [2 ], " )" )
128121 }
122+ data.frame (Name = name , Size = size )
129123 }
130- cat(" Assays: " , n_assays , " \n " , sep = " " )
131- cat(" Chemicals: " , n_chems , " \n " , sep = " " )
132- if (nrow(info_simulated ) > 0 ) {
133- n_regions <- length(x [[info_simulated $ Name [1 ]]])
134- } else if (nrow(info_computed ) > 0 ) {
135- n_regions <- length(x [[info_computed $ Name [1 ]]])
124+ get_info_list <- function (name ) {
125+ size <- " "
126+ if (! is.null(x [[name ]])) {
127+ n_list <- length(x [[name ]])
128+ dim <- dim(x [[name ]][[1 ]][[1 ]])
129+ size <- paste0(n_list , " * (m * (" , n_assay , " * n x " , dim [2 ], " ))" )
130+ }
131+ data.frame (Name = name , Size = size )
132+ }
133+
134+ # Get size info for each type of field
135+ info_data <- dplyr :: bind_rows(
136+ purrr :: map(names_data_vec , \(name ) get_info_vec(name )),
137+ purrr :: map(names_data_mat , \(name ) get_info_mat(name ))) | >
138+ dplyr :: filter(.data $ Size != " " )
139+
140+ info_computed <- dplyr :: bind_rows(
141+ purrr :: map(names_computed_mat , \(name ) get_info_mat(name )),
142+ purrr :: map(names_computed_df , \(name ) get_info_df(name )),
143+ purrr :: map(names_computed_list , \(name ) get_info_list(name ))) | >
144+ dplyr :: filter(.data $ Size != " " )
145+
146+ # Get population size from GeoTox()$par$n
147+ if (is.null(x $ par $ n )) {
148+ n_pop <- 0
149+ } else if (length(unique(x $ par $ n )) == 1 ) {
150+ n_pop <- x $ par $ n [[1 ]]
136151 } else {
137- n_regions <- 0
152+ n_pop <- paste0( " [ " , paste(range( x $ par $ n ), collapse = " , " ), " ] " )
138153 }
139- cat(" Regions: " , n_regions , " \n " , sep = " " )
140- cat(" Population: " , x $ par $ n , " \n " , sep = " " )
154+
155+ # Get number of regions from potential data fields
156+ n_region <- purrr :: map_int(c(names_data_vec , names_data_mat ,
157+ names_computed_mat , names_computed_df ),
158+ \(name ) length(x [[name ]])) | >
159+ max()
160+
161+ # Output info
162+ cat(" GeoTox object\n " )
163+ cat(" Assays: " , n_assay , " \n " , sep = " " )
164+ cat(" Chemicals: " , n_chem , " \n " , sep = " " )
165+ cat(" Regions: m = " , n_region , " \n " , sep = " " )
166+ cat(" Population: n = " , n_pop , " \n " , sep = " " )
141167 cat(" Data Fields:" )
142- if (nrow(info_simulated ) > 0 ) {
168+ if (nrow(info_data ) > 0 ) {
143169 cat(" \n " )
144- print(info_simulated , row.names = FALSE , print.gap = 2 )
170+ print(info_data , row.names = FALSE , print.gap = 2 )
145171 } else {
146172 cat(" None\n " )
147173 }
0 commit comments