def test_user_contributions(self): self.assertIsInstance(pymaid.get_user_contributions( config_test.test_skids, remote_instance=self.rm), pd.DataFrame)
def find_autoseg_fragments(x, autoseg_instance, min_node_overlap=3, min_nodes=1, verbose=True, raise_none_found=True): """Find autoseg tracings constituting a given neuron. This function works by querying the segmentation IDs along the neurites of your query neuron and then fetching the corresponding skeletons in ``autoseg_instance``. Parameters ---------- x : navis.Neuron/List Neuron to collect fragments for. autoseg_instance : pymaid.CatmaidInstance Catmaid instance which contains autoseg fragments. min_node_overlap : int, optional Minimal overlap between `x` and a segmentation [in nodes]. min_nodes : int, optional Minimum node count for returned neurons. verbose : bool, optional If True, will be print summary of who has contributed to the autoseg fragments by merging or tracing nodes. raise_none_found : bool, optional If True and none of the requested segments were found, will raise ValueError Return ------ pymaid.CatmaidNeuronList CatmaidNeurons of the overlapping fragments. Examples -------- Setup: >>> import pymaid >>> import fafbseg >>> manual = pymaid.CatmaidInstance('MANUAL_SERVER_URL', 'HTTP_USER', 'HTTP_PW', 'API_TOKEN') >>> auto = pymaid.CatmaidInstance('AUTO_SERVER_URL', 'HTTP_USER', 'HTTP_PW', 'API_TOKEN') >>> # Call one of the fafbseg.use_... to set a source for segmentation IDs >>> fafbseg.use_google_storage("https://storage.googleapis.com/fafb-ffn1-20190805/segmentation") Find autoseg fragments overlapping with a manually traced neuron: >>> x = pymaid.get_neuron(16, remote_instance=manual) >>> frags_of_x = fafbseg.find_autoseg_fragments(x, remote_instance=auto) See Also -------- fafbseg.find_fragments Generalization of this function that can find neurons independent of whether they have a reference to the segmentation ID in e.g. their name or annotations. Use this to find manual tracings overlapping with a given neuron e.g. from autoseg. """ if not isinstance(x, navis.TreeNeuron): raise TypeError( 'Expected navis.TreeNeuron or pymaid.CatmaidNeuron, got "{}"'. format(type(x))) if not isinstance(autoseg_instance, pymaid.CatmaidInstance): raise TypeError('Expected pymaid.CatmaidInstance, got "{}"'.format( type(autoseg_instance))) # First collect segments constituting this neuron overlap_matrix = neuron_to_segments(x) # If none found, return empty neuronlist if overlap_matrix.empty: return pymaid.CatmaidNeuronList([]) # Filter seg_ids = overlap_matrix.loc[ overlap_matrix[x.skeleton_id] >= min_node_overlap].index.tolist() # Now try finding the corresponding skeletons nl = segments_to_neuron(seg_ids, autoseg_instance=autoseg_instance, verbose=verbose, raise_none_found=raise_none_found) nl.sort_values('n_nodes') # Give contribution summary if verbose: # Get annotation details an_details = pymaid.get_annotation_details( nl, remote_instance=autoseg_instance) # Extract merge annotations merge_an = an_details[an_details.annotation.str.contains('Merged:')] # Group by user and count merge_count = merge_an.groupby('user')[['annotation']].count() # Get manual tracing contributions contr = pymaid.get_user_contributions(nl, remote_instance=autoseg_instance) contr.set_index('user', inplace=True) # Merge both summary = pd.merge(merge_count, contr[['nodes', 'nodes_reviewed']], left_index=True, right_index=True).fillna(0) summary.columns = ['merges', 'nodes_traced', 'nodes_reviewed'] if not summary.empty: print('Tracer have worked on these neurons:') print(summary) else: print('Nobody has worked on these neurons') return nl[nl.n_nodes >= min_nodes]