Skip to content

Commit 776a5a6

Browse files
authored
Merge pull request #32 from fmlove/dev
New function to get URLs of tagged nodes on a neuron. Closes issue #30.
2 parents ecc2b89 + cab00a3 commit 776a5a6

File tree

4 files changed

+85
-1
lines changed

4 files changed

+85
-1
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: tracerutils
22
Type: Package
33
Title: Utilities for EM Neuron Tracers
4-
Version: 0.5.0
4+
Version: 0.6.0
55
Authors@R: person("Fiona", "Love", email = "fl299@cam.ac.uk", role = c("aut", "cre"))
66
Description: Helpful functions for handling neurons traced from EM volumes.
77
Interacts with CATMAID and NBLAST.

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export(sample_connections)
99
export(simple_catmaid_url)
1010
export(split_neuron_local)
1111
export(synapses_per_neuropil)
12+
export(tagged_nodes)
1213
importFrom(catmaid,catmaid_get_connectors_between)
1314
importFrom(catmaid,catmaid_skids)
1415
importFrom(catmaid,connectors)

R/utils.R

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,54 @@ check_duplicate_synapses <- function(neuron = NULL, skid = NULL, xy_threshold =
204204

205205
return(potential_duplicates)
206206
}
207+
208+
209+
210+
211+
212+
#' Generate URLs for specifically tagged nodes on a neuron
213+
#'
214+
#' Given a neuron and a particular tag, this will return a data frame (optionally written to a CSV) with the node IDs, coordinates, and CATMAID URLs.
215+
#'
216+
#' Requires the \code{catmaid.server} option to be set in .Rprofile
217+
#'
218+
#' @param neuron Required; a A CATMAID \code{neuron} object or skeleton ID.
219+
#' @param tag Required; a string specifying a tag.
220+
#' @param node.id Optional; the ID of a node at which to cut the neuron, if only a portion of the neuron should be considered.
221+
#' @param node.direction If a cut node is provided, which portion of the cut neuron to retain. Options are \code{downstream} (default) or \code{upstream}.
222+
#' @param volume Optional; a string specifying a FAFB neuropil to filter the tagged nodes.
223+
#' @param fileout Optional; the path to a CSV file where the result should be written.
224+
#'
225+
#' @return A subset of the neuron's treenode data frame (\code{d}) including only tagges nodes, with a CATMAID URL for each.
226+
#'
227+
#' @export
228+
#'
229+
#' @importFrom catmaid read.neuron.catmaid
230+
#' @importFrom nat pointsinside xyzmatrix
231+
#' @importFrom utils write.csv
232+
tagged_nodes <- function(neuron = NULL, tag, node.id = NULL, node.direction = c("downstream", "upstream"), volume = NULL, fileout = NULL){
233+
234+
if(missing(neuron)){ stop("A skeleton ID or neuron must be provided.") }
235+
if(is.numeric(neuron)){ neuron = read.neuron.catmaid(neuron) }#skid provided instead of neuron object
236+
237+
#filter by cut node
238+
if(!is.null(node.id)){
239+
node.direction = match.arg(node.direction)
240+
neuron = split_neuron_local(neuron = neuron, node = node.id, return = node.direction)
241+
}
242+
243+
tag.i = neuron$tags[[tag]]
244+
tag.nodes = neuron$d[neuron$d$PointNo %in% tag.i,]
245+
246+
#filter by volume
247+
if(!is.null(volume)){
248+
tag.nodes = tag.nodes[pointsinside(xyzmatrix(tag.nodes), subset(elmr::FAFBNP.surf, volume)),]
249+
}
250+
251+
tag.nodes$URL = sapply(seq_len(nrow(tag.nodes)), function(i){ simple_catmaid_url(dfrow = tag.nodes[i,], skid = neuron$skid, xyz_columns = c("X", "Y", "Z"), treenode_id = tag.nodes[i,"PointNo"]) })
252+
253+
if(!missing(fileout)){ write.csv(tag.nodes, file = fileout) }
254+
if(nrow(tag.nodes) == 0){ message("There are no nodes matching your criteria.") }
255+
256+
return(tag.nodes)
257+
}

man/tagged_nodes.Rd

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)