Skip to content

Commit

Permalink
helper function to update IDs in seatable: banctable_updateids
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbates committed Sep 5, 2024
1 parent 34798bf commit 74c0b7a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
21 changes: 15 additions & 6 deletions R/banc-table.R
Original file line number Diff line number Diff line change
Expand Up @@ -376,18 +376,26 @@ banctable_updateids <- function(){

# Get cell info table
cat('reading cell info cave table...')
info <- banc_cell_info() %>%
info <- banc_cell_info(rawcoords = TRUE) %>%
dplyr::mutate(pt_position = xyzmatrix2str(pt_position)) %>%
dplyr::select(pt_root_id, pt_supervoxel_id,pt_position) %>%
rbind(banc_backbone_proofread() %>%
dplyr::select(pt_root_id, pt_supervoxel_id,pt_position)) %>%
dplyr::select(pt_root_id, pt_supervoxel_id,pt_position) %>%
dplyr::mutate(pt_position = xyzmatrix2str(pt_position))) %>%
rbind(banc_neck_connective_neurons() %>%
dplyr::select(pt_root_id, pt_supervoxel_id,pt_position) %>%
dplyr::mutate(pt_position = xyzmatrix2str(pt_position))) %>%
dplyr::mutate(pt_root_id=as.character(pt_root_id),
pt_supervoxel_id=as.character(pt_supervoxel_id)) %>%
dplyr::distinct(pt_supervoxel_id, .keep_all = TRUE)
dplyr::distinct(pt_supervoxel_id, .keep_all = TRUE) %>%
dplyr::rowwise()

# Get current table
cat('reading banc meta table...')
bc <- banctable_query(sql = 'select _id, root_id, supervoxel_id, position from banc_meta') %>%
dplyr::select(root_id, supervoxel_id, position, `_id`)
bc[bc=="0"] <- NA
bc[bc==""] <- NA

# Update
bc.new <- bc %>%
Expand All @@ -398,8 +406,8 @@ banctable_updateids <- function(){
dplyr::select(-pt_root_id,-pt_position)

# Update root IDs directly where needed
bc.new.rup <- banc_updateids(bc.new)
bc.new.rup.joined <- bc.new.rup %>%
bc.new <- banc_updateids(bc.new)
bc.new <- bc.new %>%
dplyr::left_join(info %>% dplyr::distinct(pt_root_id, .keep_all = TRUE),
by = c("root_id"="pt_root_id")) %>%
dplyr::mutate(supervoxel_id = ifelse(is.na(supervoxel_id),pt_supervoxel_id,supervoxel_id)) %>%
Expand All @@ -408,6 +416,8 @@ banctable_updateids <- function(){

# Update
cat('updating banc meta table...')
bc.new[is.na(bc.new)] <- ''
bc.new[bc.new=="0"] <- ''
banctable_update_rows(df = bc.new,
base = "banc_meta",
table = "banc_meta",
Expand All @@ -417,7 +427,6 @@ banctable_updateids <- function(){

# Return
invisible()

}


Expand Down
22 changes: 11 additions & 11 deletions R/ids.R
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,17 @@ banc_updateids <- function(x, ...){
old[!bad] <- FALSE
}

# update based on position
if(any(c("position","pt_position")%in%colnames(x)) && sum(old)){
cat('updating root_ids with a position ...')
pos.col <- intersect(c("position","pt_position"),colnames(x))[1]
update <- unname(pbapply::pbsapply(x[old,][[pos.col]], banc_xyz2id, rawcoords = TRUE, ...))
bad <- is.na(update)|update=="0"
update <- update[!bad]
x[old,][[root.col]][!bad] <- update
old[!bad] <- FALSE
}
old[is.na(old)] <- TRUE
# # update based on position
# if(any(c("position","pt_position")%in%colnames(x)) && sum(old)){
# cat('updating root_ids with a position ...')
# pos.col <- intersect(c("position","pt_position"),colnames(x))[1]
# update <- unname(pbapply::pbsapply(x[old,][[pos.col]], banc_xyz2id, rawcoords = TRUE, ...))
# bad <- is.na(update)|update=="0"
# update <- update[!bad]
# x[old,][[root.col]][!bad] <- update
# old[!bad] <- FALSE
# }
# old[is.na(old)] <- TRUE

}else{
cat('updating root_ids directly')
Expand Down

0 comments on commit 74c0b7a

Please sign in to comment.