Exemplo n.º 1
0
def remap(ids, source='Allen', dest='Beryl', output='acronym'):
    br = BrainRegions()
    _, inds = ismember(ids, br.id[br.mappings[source]])
    ids = br.id[br.mappings[dest][inds]]
    if output == 'id':
        return br.id[br.mappings[dest][inds]]
    elif output == 'acronym':
        return br.get(br.id[br.mappings[dest][inds]])['acronym']
            # Check if data is available for this probe
            if probe not in clusters.keys():
                continue

            # Check if histology is available for this probe
            if not hasattr(clusters[probe], 'acronym'):
                continue

            # Check if cluster metrics are available
            if 'metrics' not in clusters[probe]:
                continue

            # Get list of brain regions
            if ATLAS == 'beryl-atlas':
                mapped_br = br.get(ids=remap(clusters[probe]['atlas_id']))
                clusters_regions = mapped_br['acronym']

            elif ATLAS == 'allen-atlas':
                clusters_regions = combine_layers_cortex(
                    clusters[probe]['acronym'])

            # Get list of neurons that pass QC
            if INCL_NEURONS == 'pass-QC':
                clusters_pass = np.where(
                    clusters[probe]['metrics']['label'] == 1)[0]
            elif INCL_NEURONS == 'all':
                clusters_pass = np.arange(clusters[probe]['metrics'].shape[0])

            # Decode per brain region
            for r, region in enumerate(np.unique(clusters_regions)):
            'x': np.array([ch['x'] for ch in channels]) / 1e6,
            'y': np.array([ch['y'] for ch in channels]) / 1e6,
            'z': np.array([ch['z'] for ch in channels]) / 1e6,
            'axial_um': np.array([ch['axial'] for ch in channels]),
            'lateral_um': np.array([ch['lateral'] for ch in channels])
        }

    else:
        print(
            f'No histology or ephys aligned trajectory for session: {eid} and '
            f'probe: {probe_label}, no channels available')
        chans = None

if chans is not None:
    r = BrainRegions()
    chans['acronym'] = r.get(ids=chans['atlas_id']).acronym
    chans['rgb'] = r.get(ids=chans['atlas_id']).rgb
    cluster_brain_region = chans['acronym'][cluster_chans]
    cluster_colour = chans['rgb'][cluster_chans]
    cluster_xyz = np.c_[chans['x'], chans['y'], chans['z']][cluster_chans]
    regions, idx, n_clust = np.unique(cluster_brain_region,
                                      return_counts=True,
                                      return_index=True)

    region_cols = cluster_colour[idx, :]
    fig, ax = plt.subplots()
    ax.bar(x=np.arange(len(regions)),
           height=n_clust,
           tick_label=regions,
           color=region_cols / 255)
    ax.set_xlabel('Brain region acronym')