From 2656ba54508c7ec9b1963257ebf566b0b309ac59 Mon Sep 17 00:00:00 2001 From: Kent Johnson Date: Mon, 17 Jun 2019 10:00:46 -0400 Subject: [PATCH] Restrict available phenotypes to those for which we have all requisite columns, rather than giving an error for missing columns. --- inst/spatial_map_viewer_app/global.R | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/inst/spatial_map_viewer_app/global.R b/inst/spatial_map_viewer_app/global.R index 093eae7..7ba2ac8 100644 --- a/inst/spatial_map_viewer_app/global.R +++ b/inst/spatial_map_viewer_app/global.R @@ -10,16 +10,20 @@ source(file.path(base_dir, 'phenotype_color_module.R')) # .export_path = 'C:\\Research\\phenoptrExamplesData\\DemoSlides\\export' csd = readr::read_csv(.nn_path, na='#N/A', col_types=readr::cols()) + +# The available phenotypes are ones for which we have both +# phenotype and Cell ID columns. +# We don't use the Distance to columns and we don't support +# multiple phenotypes. available_phenotypes = names(csd) %>% stringr::str_subset('Phenotype ') %>% stringr::str_remove('Phenotype ') -# Check that we have distance and Cell ID columns for all phenotypes -required_columns = c(paste0('Distance to ', available_phenotypes, '+'), - paste0('Cell ID ', available_phenotypes, '+')) -missing_columns = setdiff(required_columns, names(csd)) -if (length(missing_columns) > 0) - stop('Some required columns are not available: ', - paste(missing_columns, collapse=', ')) +distance_to_phenotypes = names(csd) %>% + stringr::str_subset('Distance to ') %>% + stringr::str_remove('Distance to ') %>% + stringr::str_remove('\\+$') + +available_phenotypes = intersect(available_phenotypes, distance_to_phenotypes) available_fields = sort(unique(csd[[phenoptr::field_column(csd)]]))