brainlit
brainlit copied to clipboard
Neuron Trace class features
Issue #166 suggests converting swc.py into a Neuron Trace class with getter methods utilizing functions in swc.py. What sorts of features would be ideal for this class?
Here are a few notes:
- Each "trace" object should be a single class, and this class should be able to read data from either a swc or an s3 skeleton.
- Many of the existing methods are conversion methods like swc2skeleton, or graph_to_paths. However, when you make this a class, you will just initialize the object from a swc or something, then its various functions will give you its data in different forms (e.g. graph form etc).
- I think there are better ways to store trace data than in a pandas dataframe, but it might be too hard to change things without breaking a ton of stuff. However I do want to see a function that converts the df into a networkx graph.
- Let's have the object store its data in spatial coordinates but I'd like to see a function that converts coordinates to voxel integers if you give it offset/resolution information. i.e. if i have an image subvolume located at a particular offset and with a particular resolution, this function will give me the coordinates of the trace's points within that image.
- can you check the package to see if read_swc_dir and append_df are ever used? If not, I think we can get rid of them.
@JacopoTeneggi any additional suggestions?
Hi! I think @tathey1 cover all of my ideas too.
My only note is about converting DataFrame
s to Graph
s: there is this method https://github.com/neurodata/brainlit/blob/695c303d480dc3971ab1edcf64009311827cc5a1/brainlit/utils/swc.py#L349-L394 which relies on:
-
methods such as https://networkx.org/documentation/networkx-2.2/reference/classes/generated/networkx.DiGraph.predecessors.html which can only be found in networkx
DiGraph
class. -
bounding box coordinates which are in voxel coordinates
These two assumptions are not always satisfied (e.g. GeometricGraph
instances do not satisfy any). So, I would suggest being very clear with the scope of the function that converts df's to graph's: when to use it, and when not to use it, and when one should expect it to break other things down the line if not used correctly.
Another way to approach the problem is to privatize that function and use it only within public "feature function". For example, one could make the feature "get the portion of a skeleton that is in a specific voxel", which should:
- Initialize the class from a S3 skeleton or from a local .swc file, see: https://github.com/neurodata/brainlit/blob/695c303d480dc3971ab1edcf64009311827cc5a1/brainlit/utils/swc.py#L177-L222 https://github.com/neurodata/brainlit/blob/695c303d480dc3971ab1edcf64009311827cc5a1/brainlit/utils/swc.py#L10-L69
- Convert the spatial coordinates into voxel coordinates, see: https://github.com/neurodata/brainlit/blob/695c303d480dc3971ab1edcf64009311827cc5a1/brainlit/utils/swc.py#L253-L310
- Convert the DataFrame into a DiGraph, see: https://github.com/neurodata/brainlit/blob/695c303d480dc3971ab1edcf64009311827cc5a1/brainlit/utils/swc.py#L313-L346
- Get subgraph