How to extract features from fMOST data with neuron_morphology

To obtain the package, please see https://neuron-morphology.readthedocs.io/en/readthedocs/.

This step-by-step guide will walk you through the process of extracting features from fMOST data.

Pick your neuron (.swc/.csv)

Here select one SWC file as an example.

Ensure one SWC with only one soma point

This is developed for current registered fMOST SWC file. It will adjusted and added as a module into neuron_morphology later.

Load SWC file as morphology data

We can load the SWC file into our morphology data object and then calculate features on it.

Define interested features set

First, we instantiate a FeatureExtractor Second, we will use register the default_features

Then, let's add a custom feature. We will use a feature included in the neurom_morphology package which calculates the number of stems exiting from the soma, by neurite type.

For reference, here is the entire function:

@marked(RequiresSoma)  
@marked(RequiresRoot) 
def calculate_number_of_stems(data: Data, node_types: Optional[List[int]]):

    """
        Calculate the number of soma stems.
        This is defined as the total number of non-soma child nodes on soma nodes.

        Parameters
        ----------
        data: Data Object containing a morphology

        node_types: list (AXON, BASAL_DENDRITE, APICAL_DENDRITE)
        Type to restrict search to

        Returns
        -------

        Scalar value

    """

    soma = data.morphology.get_soma()
    return len(data.morphology.children_of(soma))

This function has been marked to indicate that it needs a soma in order to be valid, and is also specializable based on node types. We will use the specialize() function and the NEURITE_SPECIALIZATION to tell the feature extractor to calculate this feature for each neurite_type (AXON, DENDRITE, BASAL_DENDRITE, APICAL_DENDRITE, ALL_NEURITES)

Extracting features

Now that we have registered the features that we are interested in, we can call feature extractor on our swc. This will create a dictionary of results, which we can unnest and print below.

Calling fe.extract() on another test_data will calculate the same feature set, so it can be used to process many swcs.

Save the features as h5 or csv file

We can also write these features to a file using the FeatureWriter. The FeatureWriter can write the features as a nested json or as a flat csv. If a feature returns a large amount of data, it can be output to a h5 file instead.