Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catmaidserver #131

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export(catmaid_connection)
export(catmaid_connection_getenv)
export(catmaid_connection_setenv)
export(catmaid_connection_unsetenv)
export(catmaid_connector_nodes)
export(catmaid_entities_from_models)
export(catmaid_fetch)
export(catmaid_get_all_labels)
Expand All @@ -38,9 +39,11 @@ export(catmaid_get_contributor_stats)
export(catmaid_get_label_stats)
export(catmaid_get_labels)
export(catmaid_get_meta_annotations)
export(catmaid_get_neuronid)
export(catmaid_get_neuronnames)
export(catmaid_get_node_count)
export(catmaid_get_review_status)
export(catmaid_get_server)
export(catmaid_get_time_invested)
export(catmaid_get_treenode_table)
export(catmaid_get_treenodes_detail)
Expand All @@ -49,6 +52,7 @@ export(catmaid_get_volume)
export(catmaid_get_volumelist)
export(catmaid_lock_neurons)
export(catmaid_login)
export(catmaid_node_time)
export(catmaid_parse_url)
export(catmaid_query_by_annotation)
export(catmaid_query_by_name)
Expand All @@ -61,6 +65,7 @@ export(catmaid_rename_neuron)
export(catmaid_set_annotations_for_skeletons)
export(catmaid_set_labels)
export(catmaid_set_meta_annotations)
export(catmaid_skeletons_in_bbx)
export(catmaid_skids)
export(catmaid_unlock_neurons)
export(catmaid_user_history)
Expand Down
15 changes: 15 additions & 0 deletions R/catmaid_connection.R
Original file line number Diff line number Diff line change
Expand Up @@ -557,3 +557,18 @@ catmaid_envstr <- function(){
else stop(paste("\ncatmaid error: Only found the environment variable -- ", matchvalues))
}


#' Get the CATMAID server in use
#'
#' @description shows the URL for a connection object in use (see \code{catmaid_login})
#' @param conn CATMAID connection object, see ?catmaid::catmaid_login for details
#' @param ... methods passed to catmaid::catmaid_login
#' @seealso \code{\link{catmaid_login}}
#' @export
#' @rdname catmaid_get_server
catmaid_get_server<-function(conn=NULL,...){
if(is.null(conn)){
conn = catmaid::catmaid_login()
}
conn$server
}
53 changes: 53 additions & 0 deletions R/catmaid_search.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Searching for CATMAID neurons

#' Search for CATMAID skeletons within a volume
#'
#' @description Programmatically search for skeleton IDs pertaining to neurons within a search volume defined by a bounding box.
#' @param bbx the bounding box (a matrix of 2 rows and 3 columns) describing a search volume
#' @param min_nodes the minimum number of nodes a neuron in the search area must have (includes nodes outside search area)
#' @param pid project id. Defaults to 1
#' @param conn CATMAID connection object, see ?catmaid::catmaid_login for details
#' @param ... methods passed to catmaid::catmaid_fetch
#' @export
#' @rdname catmaid_skeletons_in_bbx
catmaid_skeletons_in_bbx <- function(bbx, min_nodes = 2, pid = 1, conn = NULL, ...){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jefferis it would be nice if for all these functions there could be examples, even if they are configured as not run.

post_data = list()
post_data["minx"] = bbx[1,1]
post_data["miny"] = bbx[1,2]
post_data["minz"] = bbx[1,3]
post_data["maxx"] = bbx[2,1]
post_data["maxy"] = bbx[2,2]
post_data["maxz"] = bbx[2,3]
post_data["min_nodes"] = min_nodes
path = sprintf("/%d/skeletons/in-bounding-box", pid)
res = catmaid::catmaid_fetch(path, body = post_data, include_headers = F,
simplifyVector = T, conn = conn, ...)
res
}


#' Get the CATMAID neuron ID that corresponds to the skeleton ID
#'
#' @description Retrieve the neuron IDs for given skeleton IDs. This is typically the skeleton ID + 1, and is often, but not always accurately, kept by CATMAID tracers in the name of a neuron.
#' @param skids a vector of skeleton IDs or argument applicable to \code{catmaid_get_neuronid}
#' @param pid project id. Defaults to 1
#' @param conn CATMAID connection object, see \code{catmaid::catmaid_login} for details
#' @param ... methods passed to \code{catmaid_fetch}
#' @export
#' @rdname catmaid_get_neuronid
catmaid_get_neuronid <- function(skids, pid = 1, conn = NULL, ...){
skids = catmaid_skids(skids, conn = conn, pid = pid, ...)
if (any(duplicated(skids))) {
uskids = unique(skids)
unids = catmaid_get_neuronid(uskids, pid = pid, conn = conn,...)
res = unids[match(skids, uskids)]
return(res)
}
skids[is.na(skids)] = -1L
res = lapply(skids,function(skid)
catmaid::catmaid_fetch(sprintf("/%d/skeleton/%s/neuronname", pid, skid), body = NULL, include_headers = F,
conn = conn, ...)$neuronid)
res = sapply(res,function(r) ifelse(is.null(r),NA,r))
names(res) = skids
res
}
66 changes: 66 additions & 0 deletions R/catmaid_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -598,3 +598,69 @@ process_one_user_history <- function(x) {
df$date=rep(dates, sapply(x, function(x) length(x)>0))
df
}



#' Get meta information on nodes connected to a CATMAID connector node
#'
#' @description Get information on a CATMAID connector node
#' @param connector_id the ID for a connector of interest
#' @param node whether the connector is pre- or post-synaptic to the node of interest
#' @param pid project id. Defaults to 1
#' @param conn CATMAID connection object, see ?catmaid_login for details
#' @param ... methods passed to \code{catmaid_fetch} and \code{catmaid_get_treenode_detail}
#' @export
#' @rdname catmaid_connector_nodes
catmaid_connector_nodes <- function(connector_id, node = c("presynaptic","postsynaptic"),
pid=1, conn = conn, ...){
node = match.arg(node)
connector_id = as.numeric(connector_id)
if(length(connector_id)!=1){
stop("connector_id must be a single connector_id")
}
post_data = list()
post_data["connector_ids[0]"] = connector_id
path = sprintf("/%d/connector/skeletons", pid)
res = catmaid_fetch(path, body = post_data, include_headers = F,
simplifyVector = T, conn = conn,...)
tnids = res[[1]][[2]][[paste0(node,"_to_node")]]
detail = catmaid_get_treenodes_detail (tnids=tnids, pid = pid, conn = conn, ...)
detail$connector_id = connector_id
detail
}


### Added to rcatmaid ###
#' Get the UTC creation / edit time for a CATMAID node
#'
#' @description Get the UTC creation / edit time for a CATMAID treenode or connector.
#' Useful for making 'state' arguments to be passed to other functions that edit data on a CATMAID server.
#' @param id a treenode or connector ID
#' @param time whether to return the creation_time or edition_time
#' @param pid project id. Defaults to 1
#' @param conn CATMAID connection object, see ?catmaid_login for details
#' @param ... methods passed to catmaid_set_labels
#' @export
#' @rdname catmaid_node_time
catmaid_node_time <- function(id, time = c("creation_time", "edition_time"), pid = 1, conn = NULL, ...){
time = match.arg(time)
id = as.numeric(id)
post_data = list()
post_data["node_ids"] = id
path = sprintf("/%d/node/user-info", pid)
res = catmaid_fetch(path, body = post_data, include_headers = F,
simplifyVector = T, conn = conn, ...)
if(!is.null(res$error)){
stop(res$error)
}else{
res[[1]][[time]]
}
}

# A helper function, not exported
catmaid_convert_time <- function(utc){
t = format(as.POSIXlt(utc,tz="GMT",origin="1970-01-01"), "%Y-%m-%d %H:%M:%OS3")
s = unlist(strsplit(t," "))
t = paste0(s[1],"T",s[2],"Z")
}

28 changes: 28 additions & 0 deletions man/catmaid_connector_nodes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions man/catmaid_get_neuronid.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions man/catmaid_get_server.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions man/catmaid_node_time.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions man/catmaid_skeletons_in_bbx.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.