diff --git a/.gitignore b/.gitignore index 003c2bf0..cad83ea0 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ samples inst/doc flywire_skeletons/ .DS_Store +*cache/ diff --git a/DESCRIPTION b/DESCRIPTION index e5250457..5ffa7ff7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -94,4 +94,4 @@ Remotes: Encoding: UTF-8 Language: en-GB LazyData: true -RoxygenNote: 7.2.2 +RoxygenNote: 7.2.3 diff --git a/NAMESPACE b/NAMESPACE index d2ac175f..d470bf65 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -58,6 +58,7 @@ export(flytable_columns) export(flytable_list_rows) export(flytable_list_selected) export(flytable_login) +export(flytable_meta) export(flytable_nrow) export(flytable_query) export(flytable_set_token) @@ -143,6 +144,7 @@ importFrom(checkmate,assert_number) importFrom(curl,curl_download) importFrom(dplyr,.data) importFrom(dplyr,across) +importFrom(dplyr,all_of) importFrom(dplyr,arrange) importFrom(dplyr,collect) importFrom(dplyr,desc) diff --git a/R/autosyn.R b/R/autosyn.R index 78808f6d..c6cf4c51 100644 --- a/R/autosyn.R +++ b/R/autosyn.R @@ -631,7 +631,7 @@ flywire_ntpred <- function(x, x = ntpredictions %>% dplyr::inner_join(x, copy = TRUE, by=c("id"="offset")) %>% - dplyr::rename(offset=.data$id) + dplyr::rename(offset="id") } if(!all(extracols %in% colnames(x))) { @@ -874,6 +874,7 @@ flywire_neurons_add_synapses <- function(x, #' @export #' @rdname flywire_neurons_add_synapses +#' @importFrom dplyr all_of flywire_neurons_add_synapses.neuron <- function(x, connectors = NULL, cloudvolume.url=NULL, @@ -919,7 +920,7 @@ flywire_neurons_add_synapses.neuron <- function(x, dplyr::mutate(y = ifelse(.data$prepost, .data$post_y, .data$pre_y)) %>% dplyr::mutate(z = ifelse(.data$prepost, .data$post_z, .data$pre_z)) %>% dplyr::arrange(.data$offset) %>% - dplyr::select(wanted) %>% + dplyr::select(all_of(wanted)) %>% as.data.frame() -> synapses.xyz rownames(synapses.xyz) = synapses.xyz$offset diff --git a/R/flytable.R b/R/flytable.R index 688b1870..94100215 100644 --- a/R/flytable.R +++ b/R/flytable.R @@ -863,12 +863,15 @@ flytable_list_selected <- function(ids=NULL, table='info', fields="*", idfield=" } else fq } -cell_types_memo <- memoise::memoise(function(query="_%", timestamp=NULL, +cell_types_memo <- memoise::memoise(function(query=NULL, timestamp=NULL, target='type', - fields=c("root_id", "supervoxel_id", "side", "cell_class", "cell_type", "ito_lee_hemilineage", "hemibrain_type", "hemibrain_match", "vfb_id")) { + fields=c("root_id", "supervoxel_id", "side", "flow", "super_class", "cell_class", "cell_type", "ito_lee_hemilineage", "hemibrain_type", "hemibrain_match", "vfb_id")) { + if(is.null(query)) + query="_%" + likeline=switch (target, type = sprintf('((cell_type LIKE "%s") OR (hemibrain_type LIKE "%s"))',query,query), - all = sprintf('((cell_type LIKE "%s") OR (hemibrain_type LIKE "%s") OR (cell_class LIKE "%s"))',query, query, query), + all = sprintf('((cell_type LIKE "%s") OR (hemibrain_type LIKE "%s") OR (cell_class LIKE "%s") OR (super_class LIKE "%s"))',query, query, query, query), sprintf('(%s LIKE "%s")',target, query) ) fields=paste(fields, collapse = ',') @@ -945,7 +948,7 @@ cell_types_memo <- memoise::memoise(function(query="_%", timestamp=NULL, #' pncands=flytable_cell_types('%PN%', target = 'all') #' } flytable_cell_types <- function(pattern=NULL, version=NULL, timestamp=NULL, - target=c("type", "cell_type", 'hemibrain_type', 'cell_class', 'all'), + target=c("type", "cell_type", 'hemibrain_type', 'cell_class', 'super_class', 'all'), transfer_hemibrain_type=c("extra", "none", "all"), cache=TRUE) { @@ -969,7 +972,16 @@ flytable_cell_types <- function(pattern=NULL, version=NULL, timestamp=NULL, pattern=mres[,2] side=switch(mres[,3], L='left', R="right", stop("side problem in flytable_cell_types!")) } - + if(isTRUE(substr(pattern,1,1)=="/")) { + smres=stringr::str_match(pattern, '/([^:]*):(.+)') + if(is.na(smres[,1])) + stop("Malformed regex query:`", pattern,"`! Should look like `/:% group_by(across(c(partner_col, "neuropil"))) %>% + syn2 %>% group_by(across(all_of(c(partner_col, "neuropil")))) %>% summarise(weight = sum(weight), n=n_distinct(.data[[query_col]])) } else if(!by.roi && summarise) { # collapse query and neuropil info - syn2 %>% group_by(across(partner_col)) %>% + syn2 %>% group_by(across(all_of(partner_col))) %>% summarise(weight = sum(weight), n=n_distinct(.data[[query_col]]), top_np = neuropil[1]) } else if(!by.roi && !summarise) { diff --git a/R/flywire-urls.R b/R/flywire-urls.R index f6fbe083..52f11afa 100644 --- a/R/flywire-urls.R +++ b/R/flywire-urls.R @@ -215,8 +215,13 @@ flywire_scene <- function(ids=NULL, annotations=NULL, open=FALSE, shorten=FALSE, #' # using SQL wild cards #' flywire_ids("DA[12]_%PN_L") #' +#' # all sensory neurons +#' flywire_ids("super:sensory", integer64=TRUE) +#' #' # note that side is defined by soma position (not arbour side) #' flywire_ids("class:MBON_R", integer64=TRUE) +#' # superclass can also have a side specified +#' flywire_ids("super:motor_R", integer64=TRUE) flywire_ids <- function(x, integer64=FALSE, check_latest=FALSE, must_work=FALSE, na_ok=FALSE, unique=FALSE, version=NULL, ...) { if(is.data.frame(x)) { @@ -234,8 +239,8 @@ flywire_ids <- function(x, integer64=FALSE, check_latest=FALSE, must_work=FALSE, } else if(is.character(x) && length(x)==1 && !valid_id(x, na.ok = T) && !grepl("http", x)) { # looks like a query target='type' - if(grepl("^[a-z]+:", x)) { - okfields=c('cell_type', 'cell_class', 'hemibrain_type', 'class') + if(grepl("^[a-z_]+:", x)) { + okfields=c('type', 'cell_type', 'cell_class', 'hemibrain_type', 'class', "super_class", "super") ul=unlist(strsplit(x, ":", fixed=T)) if(length(ul)!=2) stop("Unable to parse flywire id specification!") @@ -244,6 +249,8 @@ flywire_ids <- function(x, integer64=FALSE, check_latest=FALSE, must_work=FALSE, stop("Unknown field in flywire id specification!") if(target=='class') target='cell_class' + if(target=='super') + target='super_class' x=ul[2] } res=flytable_cell_types(pattern=x, target = target, version=version, ...) diff --git a/man/add_celltype_info.Rd b/man/add_celltype_info.Rd index f1089ba3..faf54ca5 100644 --- a/man/add_celltype_info.Rd +++ b/man/add_celltype_info.Rd @@ -2,9 +2,12 @@ % Please edit documentation in R/flytable.R \name{add_celltype_info} \alias{add_celltype_info} -\title{Add flytable cell type information to a dataframe with flywire ids} +\alias{flytable_meta} +\title{Fetch flytable cell type information to a dataframe with flywire ids} \usage{ add_celltype_info(x, idcol = NULL, version = NULL, ...) + +flytable_meta(ids, version = NULL, ...) } \arguments{ \item{x}{a data.frame containing root ids} @@ -17,12 +20,19 @@ The special signalling value of \code{TRUE} uses the current default data dump as returned by \code{\link{flywire_connectome_data_version}}.} \item{...}{additional arguments passed to \code{flytable_cell_types}} + +\item{ids}{Flywire identifiers/query in any form understood by +\code{\link{flywire_ids}}} } \value{ a data.frame with extra columns } \description{ -Add flytable cell type information to a dataframe with flywire ids +\code{add_celltype_info} will add information to an existing + dataframe. + +\code{flytable_meta} will fetch a data.frame of metadata from + flytable for a given set of identifiers. } \details{ the root ids must be in a column called one of \code{"pre_id", @@ -45,6 +55,12 @@ kcin2 \%>\% kcin2 \%>\% count(cell_class, wt = weight) } +\donttest{ +flytable_meta("class:MBON") +flytable_meta("type:MBON2\%") +# the / introduces a regex query (small performance penalty, more flexible) +flytable_meta("/type:MBON2[0-5]") +} } \seealso{ \code{\link{flytable_cell_types}} diff --git a/man/flytable_cell_types.Rd b/man/flytable_cell_types.Rd index f5d0299e..10854935 100644 --- a/man/flytable_cell_types.Rd +++ b/man/flytable_cell_types.Rd @@ -8,7 +8,7 @@ flytable_cell_types( pattern = NULL, version = NULL, timestamp = NULL, - target = c("type", "cell_type", "hemibrain_type", "cell_class", "all"), + target = c("type", "cell_type", "hemibrain_type", "cell_class", "super_class", "all"), transfer_hemibrain_type = c("extra", "none", "all"), cache = TRUE ) diff --git a/man/flywire_ids.Rd b/man/flywire_ids.Rd index 7b5fdb03..34181ba3 100644 --- a/man/flywire_ids.Rd +++ b/man/flywire_ids.Rd @@ -61,8 +61,13 @@ flywire_ids("DL1_adPN_R", version=400) # using SQL wild cards flywire_ids("DA[12]_\%PN_L") +# all sensory neurons +flywire_ids("super:sensory", integer64=TRUE) + # note that side is defined by soma position (not arbour side) flywire_ids("class:MBON_R", integer64=TRUE) +# superclass can also have a side specified +flywire_ids("super:motor_R", integer64=TRUE) } \seealso{ \code{\link{flytable_cell_types}}. diff --git a/man/xform.ngscene.Rd b/man/xform.ngscene.Rd index 94d8cb66..f4e520d0 100644 --- a/man/xform.ngscene.Rd +++ b/man/xform.ngscene.Rd @@ -11,7 +11,7 @@ \item{reg}{A registration either as a \code{\link{reglist}} containing multiple registrations or a single registration in any form handled by -\code{xform}.} +\code{\link{xform}}.} \item{layers}{A character vector specifying the layers in the scene to transform. If the elements are named, they names specify the \emph{new} @@ -27,7 +27,11 @@ A new \code{ngscene} object Add a transformation to one or more layers in a neuroglancer scene } \details{ -Neuroglancer only implements homogeneous affine transforms for layers. However these can still be quite useful when a non-rigid transform cannot be applied to a layer e.g. because the underlying neurons are undergoing rapid editing and it is not practical to generate a static set of transformed meshes. +Neuroglancer only implements homogeneous affine transforms for + layers. However these can still be quite useful when a non-rigid transform + cannot be applied to a layer e.g. because the underlying neurons are + undergoing rapid editing and it is not practical to generate a static set + of transformed meshes. } \examples{ \donttest{ diff --git a/tests/testthat/test-flytable.R b/tests/testthat/test-flytable.R index 2c2e0081..b6cd0d62 100644 --- a/tests/testthat/test-flytable.R +++ b/tests/testthat/test-flytable.R @@ -11,6 +11,15 @@ test_that("query works", { # queries fly table for cell types expect_equal(flywire_ids('DL4_adPN_R', version=401), "720575940627708688") + expect_equal(flywire_ids('DL4_adPN_R', version=401), "720575940627708688") + expect_true(length(flywire_ids('class:MBON', integer64 = T))>90) + + expect_equal(mbon0x <- flytable_cell_types('MBON0%'), + flytable_cell_types('/type:MBON0[1-9]')) + expect_equal(flytable_meta(mbon0x), mbon0x) + expect_true(length(flywire_ids('super:sensory', integer64 = T))>1000) + expect_error(flywire_ids('pudding:sensory')) + expect_s3_class(df <- flytable_query("select fruit_name, person, _ctime, date_wminute FROM testfruit WHERE nid<=3", limit=3L), 'data.frame')