def test_fetch_adjacencies(client): bodies = [ 294792184, 329566174, 329599710, 417199910, 420274150, 424379864, 425790257, 451982486, 480927537, 481268653 ] neuron_df, roi_conn_df = fetch_adjacencies(SC(bodyId=bodies), SC(bodyId=bodies)) # Should not include non-primary ROIs (except 'NotPrimary') assert not ({*roi_conn_df['roi'].unique()} - {*fetch_primary_rois()} - {'NotPrimary'}) # # For backwards compatibility with the previous API, # You can also pass a list of bodyIds to this function (instead of SegmentCriteria). # bodies = [ 294792184, 329566174, 329599710, 417199910, 420274150, 424379864, 425790257, 451982486, 480927537, 481268653 ] neuron_df2, roi_conn_df2 = fetch_adjacencies(bodies, bodies) # Should not include non-primary ROIs (except 'NotPrimary') assert not ({*roi_conn_df2['roi'].unique()} - {*fetch_primary_rois()} - {'NotPrimary'}) assert (neuron_df.fillna('') == neuron_df2.fillna('')).all().all() assert (roi_conn_df == roi_conn_df2).all().all()
def test_fetch_adjacencies(client): bodies = [ 294792184, 329566174, 329599710, 417199910, 420274150, 424379864, 425790257, 451982486, 480927537, 481268653 ] neuron_df, roi_conn_df = fetch_adjacencies(NC(bodyId=bodies), NC(bodyId=bodies)) # Should not include non-primary ROIs (except 'NotPrimary') assert not ({*roi_conn_df['roi'].unique()} - {*fetch_primary_rois()} - {'NotPrimary'}) # # For backwards compatibility with the previous API, # You can also pass a list of bodyIds to this function (instead of NeuronCriteria). # bodies = [ 294792184, 329566174, 329599710, 417199910, 420274150, 424379864, 425790257, 451982486, 480927537, 481268653 ] neuron_df2, roi_conn_df2 = fetch_adjacencies(bodies, bodies) # Should not include non-primary ROIs (except 'NotPrimary') assert not ({*roi_conn_df2['roi'].unique()} - {*fetch_primary_rois()} - {'NotPrimary'}) assert (neuron_df.fillna('') == neuron_df2.fillna('')).all().all() assert (roi_conn_df == roi_conn_df2).all().all() # What happens if results are empty neuron_df, roi_conn_df = fetch_adjacencies(879442155, 5813027103) assert len(neuron_df) == 0 assert len(roi_conn_df) == 0 assert neuron_df.columns.tolist() == ['bodyId', 'instance', 'type']
def pn_kc_connections(properties=None, sum_across_rois=False, checks=True, **kwargs): """ Returns `neuron_df`, `connection_df` as `neuprint.fetch_adjacencies`, but only for PN->KC connections. See also keyword arguments added by the `@fetch_function` decorator. Keywords not covered above are passed to `neuprint.fetch_adjacencies`. """ if properties is None: # TODO TODO TODO replace hardcoded properties w/ something enumerated # using a cypher query properties = nc # TODO TODO TODO the docs make this sound like it might only return weights # for connections shared by ALL neurons matched. is this true? see also the # two kwargs dealing with minimum weights # TODO consider using rois=[<appropriate str for calyx>] to just match # those. compare results to those from manually filtering output not # specifying those rois. neuron_df, conn_df = nu.fetch_adjacencies( # TODO if i end up factoring some of this fn into something to be shared # across fns that get connections from one type to another, maybe just # test whether input strs have asterisk in them, and set regex=True if # so? first check if * is in any of the types that exist in the db!!! NC(type='.*PN.*', regex=True), NC(type='.*KC.*', regex=True), # Default is just ['type','instance'] properties=properties, **kwargs) # TODO test the number of things returned above is the same as when doing # the equivalent CONTAINS query in the web interface # (also check just .* as suffix, not also prefix) if checks: # There CAN be (pre ID, post ID) duplicates, because weights are # reported per ROI, so need to sum across ROIs if we just want # the total weight between two neurons, ignoring where the synapses are. assert not conn_df.duplicated( [c for c in conn_df.columns if c != 'weight']).any() # TODO TODO technically only do this check if include_nonprimary=False # (so check kwargs) (if it's True, would need to do another check) assert (set(conn_df.roi.unique()) - set(nu.fetch_primary_rois()) == {'NotPrimary'}) if sum_across_rois: conn_df = conn_df.groupby(['bodyId_pre', 'bodyId_post']).weight.sum().reset_index() # No need to call filter_nontraced_or_cropped, at least as of 2020-05-31, # where it had no effect. return neuron_df, conn_df
def test_fetch_primary_rois(client): primary_rois = fetch_primary_rois() assert isinstance(primary_rois, list)