From c853a8cf6db7026aa80ede385b974faaa9628deb Mon Sep 17 00:00:00 2001 From: Gregory Jefferis Date: Sun, 10 Nov 2024 15:54:47 +0000 Subject: [PATCH 1/7] support malecns superclass/class/subclass change --- DESCRIPTION | 2 +- R/meta.R | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index b376e05..061d394 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -47,7 +47,7 @@ Suggests: tidyr, reticulate Enhances: - malecns (>= 0.3.1) + malecns (>= 0.3.2) Remotes: flyconnectome/malevnc, flyconnectome/fancr, diff --git a/R/meta.R b/R/meta.R index 51fd9e3..1824862 100644 --- a/R/meta.R +++ b/R/meta.R @@ -143,6 +143,9 @@ malecns_meta <- function(ids, ...) { T ~ type )) %>% rename(id=bodyid) %>% + # + rename(class1=superclass, class2=class, subsubclass=subclass) %>% + rename(class=class1, subclass=class2, subsubclass=subclass) %>% rename(lineage=hemilineage) tres } From 675977c070d9c007b71f8ccdd9929795def3977f Mon Sep 17 00:00:00 2001 From: Gregory Jefferis Date: Sun, 10 Nov 2024 17:45:51 +0000 Subject: [PATCH 2/7] support for flywire subclass * needs 0.15.2 for this --- DESCRIPTION | 2 +- R/meta.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 061d394..5eec1c5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,7 +19,7 @@ Depends: R (>= 2.10), nat (>= 1.10.2.9000) Imports: - fafbseg (>= 0.15.0), + fafbseg (>= 0.15.2), nat.templatebrains (>= 1.0), pbapply, neuprintr (>= 1.3.2), diff --git a/R/meta.R b/R/meta.R index 1824862..e8176d8 100644 --- a/R/meta.R +++ b/R/meta.R @@ -109,7 +109,7 @@ flywire_meta <- function(ids, type=c("cell_type","hemibrain_type"), ...) { mutate(id=fafbseg::flywire_ids(id, integer64=T)) %>% mutate(side=toupper(substr(side,1,1))) %>% rename_with(~ sub(".+_", "", .x), .cols=any_of(type)) %>% - rename(class=super_class) %>% + rename(class=super_class, subclass=cell_class, subsubclass=cell_subclass) %>% rename(lineage=ito_lee_hemilineage) } From dd1d29525cbee5cded281380e51afe965ad0c431 Mon Sep 17 00:00:00 2001 From: Gregory Jefferis Date: Mon, 11 Nov 2024 17:37:47 +0000 Subject: [PATCH 3/7] fix subclass column names for malecns/flywire --- R/meta.R | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/R/meta.R b/R/meta.R index e8176d8..603afdc 100644 --- a/R/meta.R +++ b/R/meta.R @@ -109,7 +109,7 @@ flywire_meta <- function(ids, type=c("cell_type","hemibrain_type"), ...) { mutate(id=fafbseg::flywire_ids(id, integer64=T)) %>% mutate(side=toupper(substr(side,1,1))) %>% rename_with(~ sub(".+_", "", .x), .cols=any_of(type)) %>% - rename(class=super_class, subclass=cell_class, subsubclass=cell_subclass) %>% + rename(class=super_class, subclass=cell_class, subsubclass=cell_sub_class) %>% rename(lineage=ito_lee_hemilineage) } @@ -143,9 +143,8 @@ malecns_meta <- function(ids, ...) { T ~ type )) %>% rename(id=bodyid) %>% - # rename(class1=superclass, class2=class, subsubclass=subclass) %>% - rename(class=class1, subclass=class2, subsubclass=subclass) %>% + rename(class=class1, subclass=class2) %>% rename(lineage=hemilineage) tres } From fa34b2b8ddbf3e86b59c2e79879c4c3ec9ff3c5e Mon Sep 17 00:00:00 2001 From: Gregory Jefferis Date: Wed, 13 Nov 2024 12:42:39 +0000 Subject: [PATCH 4/7] support subsubclass across datasets --- R/meta.R | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/R/meta.R b/R/meta.R index 603afdc..5c1ed68 100644 --- a/R/meta.R +++ b/R/meta.R @@ -72,7 +72,7 @@ cf_meta <- function(ids, bind.rows=TRUE, integer64=FALSE, keep.all=FALSE, if(inherits(tres, 'try-error') || is.null(tres) || !isTRUE(nrow(tres)>0)) next tres$id=flywire_ids(tres$id, integer64=integer64, na_ok=TRUE) - cols_we_want=c("id", "class", "type", 'side', 'group', "instance") + cols_we_want=c("id", "class", "subclass", "type", 'side', 'group', "instance") missing_cols=setdiff(cols_we_want, colnames(tres)) if('class' %in% missing_cols) tres$class=NA_character_ @@ -118,6 +118,7 @@ hemibrain_meta <- function(ids, ...) { tres <- tres %>% rename(id=bodyid) %>% mutate(side=stringr::str_match(tres$name, "_([LR])")[,2]) %>% + mutate(class=NA_character_, subclass=NA_character_, subsubclass=NA_character_) %>% rename(lineage=cellBodyFiber) tres } @@ -126,7 +127,8 @@ opticlobe_meta <- function(ids, ...) { tres=malevnc::manc_neuprint_meta(ids, conn = npconn('opticlobe'), ...) tres <- tres %>% rename(id=bodyid) %>% - mutate(side=stringr::str_match(tres$name, "_([LR])$")[,2]) + mutate(side=stringr::str_match(tres$name, "_([LR])$")[,2]) %>% + mutate(class=NA_character_, subclass=NA_character_, subsubclass=NA_character_) tres } @@ -156,7 +158,8 @@ manc_meta <- function(ids, ...) { !is.na(rootSide) ~ toupper(substr(rootSide, 1, 1)), T ~ NA_character_ )) %>% - rename(id=bodyid, lineage=hemilineage) + rename(id=bodyid, lineage=hemilineage) %>% + mutate(subsubclass=NA_character_) tres } From 130aed29c443840ba14a9e425c1eaa852aec740a Mon Sep 17 00:00:00 2001 From: Gregory Jefferis Date: Wed, 13 Nov 2024 12:43:05 +0000 Subject: [PATCH 5/7] use %>% not |> for now --- R/meta.R | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/R/meta.R b/R/meta.R index 5c1ed68..c576c65 100644 --- a/R/meta.R +++ b/R/meta.R @@ -200,15 +200,15 @@ fancorbanc_meta <- function(table, ids=NULL, ...) { mutate( tag=sub("\n\n\n*banc-bot*","", fixed = T, tag), pt_root_id=as.character(pt_root_id)) - cell_infos3 <- cell_infos2 |> + cell_infos3 <- cell_infos2 %>% mutate( tag2=case_when( tag2 %in% ol_classes ~ 'neuron identity', T ~ tag2) - ) |> - arrange(pt_root_id, tag) |> - distinct(pt_root_id, tag2, tag, .keep_all = T) |> - group_by(pt_root_id, tag2) |> + ) %>% + arrange(pt_root_id, tag) %>% + distinct(pt_root_id, tag2, tag, .keep_all = T) %>% + group_by(pt_root_id, tag2) %>% # summarise(tag=paste0(tag, collapse=";"), .groups = 'drop') summarise(tag={ if(length(tag)>1 && any(grepl("?", tag, fixed = T))) { @@ -221,9 +221,9 @@ fancorbanc_meta <- function(table, ids=NULL, ...) { paste0(tag, collapse=";") }, .groups = 'drop') - cell_infos2.ol=cell_infos2 |> filter(tag2 %in% ol_classes) + cell_infos2.ol=cell_infos2 %>% filter(tag2 %in% ol_classes) - cell_infos4 <- cell_infos3 |> + cell_infos4 <- cell_infos3 %>% tidyr::pivot_wider(id_cols = pt_root_id, names_from = tag2, values_from = tag, @@ -241,7 +241,7 @@ fancorbanc_meta <- function(table, ids=NULL, ...) { T ~ paste(class, apc) )) %>% mutate(class=sub(" neuron", '', class)) %>% - mutate(side=sub('soma on ', '', side)) |> + mutate(side=sub('soma on ', '', side)) %>% mutate(side=case_when( is.na(side) ~ side, T ~ toupper(substr(side,1,1)) From fab39d31b1d2972f42f75a0373c8809f3d2efa30 Mon Sep 17 00:00:00 2001 From: Gregory Jefferis Date: Wed, 13 Nov 2024 12:47:21 +0000 Subject: [PATCH 6/7] empty subclass in banc/fanc for now --- R/meta.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/meta.R b/R/meta.R index c576c65..77e2987 100644 --- a/R/meta.R +++ b/R/meta.R @@ -247,6 +247,7 @@ fancorbanc_meta <- function(table, ids=NULL, ...) { T ~ toupper(substr(side,1,1)) )) %>% select(id, class, type, side) %>% + mutate(subclass=NA_character_) %>% mutate(id=as.character(id)) } if(length(ids)) From cc695ccb9e96de889f3e9ad0820a60eb357d555c Mon Sep 17 00:00:00 2001 From: Gregory Jefferis Date: Thu, 14 Nov 2024 08:28:45 +0000 Subject: [PATCH 7/7] add tests for opticlobe and malecns (if present) --- tests/testthat/test-partners.R | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/testthat/test-partners.R b/tests/testthat/test-partners.R index 67bf4d7..d16ec2b 100644 --- a/tests/testthat/test-partners.R +++ b/tests/testthat/test-partners.R @@ -12,3 +12,28 @@ test_that("cf_partner_summary works", { ) expect_true(any(grepl("w-cHIN", dnao$type.post))) }) + +test_that("cf_partner_summary works", { + skip_if_not_installed('malecns') + expect_s3_class( + dnao <- cf_partner_summary(cf_ids(malecns="/DNa02",), threshold = 10, partners = 'o'), + 'data.frame' + ) + expect_true(any(grepl("w-cHIN", dnao$type.post))) +}) + +test_that("cf_partner_summary works", { + + expect_s3_class( + dnao <- cf_partner_summary(cf_ids(opticlobe = 'LLPC1'), threshold = 10, partners = 'o'), + 'data.frame' + ) + expect_true(any(grepl("HSS", dnao$type.post))) + + skip_if_not_installed('malecns') + expect_s3_class( + dnao <- cf_partner_summary(cf_ids(malecns="/DNa02"), threshold = 10, partners = 'o'), + 'data.frame' + ) + expect_true(any(grepl("w-cHIN", dnao$type.post))) +})