def getSynapseDetectionSSA(synapticVolumes, query, kernelLength=2, edge_win = 3,
                         search_win = 2):
    """
    This function calls the functions needed to run probabilistic synapse detection 

    Parameters
    ----------
    synapticVolumes : dict
        has two keys (presynaptic,postsynaptic) which contain lists of 3D numpy arrays 
    query : dict
        contains the minumum slice information for each channel 
    kernelLength : int
        Minimum 2D Blob Size (default 2)
    edge_win: int
        Edge window (default 8)
    search_win: int
        Search windows (default 2)

    Returns
    ----------
    resultVol : 3D numpy array - final probability map 
    """

    # Data
    presynapticVolumes = synapticVolumes['presynaptic']
    postsynapticVolumes = synapticVolumes['postsynaptic']

    # Number of slices each blob should span 
    preIF_z = query['preIF_z']
    postIF_z = query['postIF_z']

    for n in range(0, len(presynapticVolumes)):

        #presynapticVolumes[n] = getProbMap(presynapticVolumes[n]) # Step 1
        presynapticVolumes[n] = syn.convolveVolume(presynapticVolumes[n], kernelLength) # Step 2

        if preIF_z[n] > 1: 
            factorVol = syn.computeFactor(presynapticVolumes[n], int(preIF_z[n])) # Step 3
            presynapticVolumes[n] = presynapticVolumes[n] * factorVol

    for n in range(0, len(postsynapticVolumes)):
        
        #postsynapticVolumes[n] = getProbMap(postsynapticVolumes[n]) # Step 1
        postsynapticVolumes[n] = syn.convolveVolume(postsynapticVolumes[n], kernelLength) # Step 2

        if postIF_z[n] > 1:
            factorVol = syn.computeFactor(postsynapticVolumes[n], int(postIF_z[n])) # Step 3
            postsynapticVolumes[n] = postsynapticVolumes[n] * factorVol

    # combinePrePostVolumes(base, adjacent)
    # Step 4 

    #print(len(presynapticVolumes))
    #print(len(postsynapticVolumes))
    if len(postsynapticVolumes) == 0: 
        resultVol = syn.combinePrePostVolumes(presynapticVolumes, postsynapticVolumes, edge_win, search_win)
    else: 
        resultVol = syn.combinePrePostVolumes(postsynapticVolumes, presynapticVolumes, edge_win, search_win)

    return resultVol; 
예제 #2
0
def run_ab_analysis_rayleigh(synaptic_volumes, query, thresh, resolution,
                             target_antibody_name):
    """
    Run AB Analysis - special case 

    MEASURES
    - Puncta Density
    - Average punctum size
    - Standard deviation of the size
    - Synapse density
    - Target Specificity Ratio (tsr)

    Parameters
    -----------
    synaptic_volumes : dict
    query : dict
    thresh : float
    resolution : dict

    Returns
    -----------
    antibody_measure : AntibodyAnalysis()
    """

    antibody_measure = AntibodyAnalysis(query)

    # Get data volume
    antibody_measure.volume_um3 = getdatavolume(synaptic_volumes, resolution)
    print('data volume: ', antibody_measure.volume_um3)

    # Check to see if user supplied blobsize
    if 'punctumSize' in query.keys():
        blobsize = query['punctumSize']
        edge_win = int(np.ceil(blobsize * 1.5))

    # Data
    presynaptic_volumes = synaptic_volumes['presynaptic']
    postsynaptic_volumes = synaptic_volumes['postsynaptic']

    # Number of slices each blob should span
    preIF_z = query['preIF_z']
    postIF_z = query['postIF_z']

    for n in range(0, len(presynaptic_volumes)):
        presynaptic_volumes[n] = syn.getProbMap_rayleigh(
            presynaptic_volumes[n])  # Step 1
        presynaptic_volumes[n] = syn.convolveVolume(presynaptic_volumes[n],
                                                    blobsize)  # Step 2
        if preIF_z[n] > 1:
            factor_vol = syn.computeFactor(presynaptic_volumes[n],
                                           int(preIF_z[n]))  # Step 3
            presynaptic_volumes[n] = presynaptic_volumes[n] * factor_vol

    # Compute single channel measurements
    antibody_measure = compute_single_channel_measurements(
        presynaptic_volumes, antibody_measure, thresh, 'presynaptic')
    print('Computed presynaptic single channel measurements')

    for n in range(0, len(postsynaptic_volumes)):
        postsynaptic_volumes[n] = syn.getProbMap_rayleigh(
            postsynaptic_volumes[n])  # Step 1
        postsynaptic_volumes[n] = syn.convolveVolume(postsynaptic_volumes[n],
                                                     blobsize)  # Step 2
        if postIF_z[n] > 1:
            factor_vol = syn.computeFactor(postsynaptic_volumes[n],
                                           int(postIF_z[n]))  # Step 3
            postsynaptic_volumes[n] = postsynaptic_volumes[n] * factor_vol

    # Compute single channel measurements
    antibody_measure = compute_single_channel_measurements(
        postsynaptic_volumes, antibody_measure, thresh, 'postsynaptic')
    print('Computed postsynaptic single channel measurements')

    if len(postsynaptic_volumes) == 0:
        resultVol = syn.combinePrePostVolumes(presynaptic_volumes,
                                              postsynaptic_volumes, edge_win,
                                              blobsize)
    else:
        resultVol = syn.combinePrePostVolumes(postsynaptic_volumes,
                                              presynaptic_volumes, edge_win,
                                              blobsize)

    # Compute whole statistics
    label_vol = measure.label(resultVol > thresh)
    stats = measure.regionprops(label_vol)
    antibody_measure.synapse_density = len(stats) / antibody_measure.volume_um3
    antibody_measure.synapse_count = len(stats)

    antibody_measure = calculuate_target_ratio(antibody_measure,
                                               target_antibody_name)

    return antibody_measure
예제 #3
0
def run_SACT(synaptic_volumes, query, thresh, resolution,
             target_antibody_name):
    """
    Run SACT. 

    MEASURES
    - Puncta Density
    - Average punctum size
    - Standard deviation of the size
    - Synapse density
    - Target Specificity Ratio (tsr)
    - Raw data mean/std

    Parameters
    -----------
    synaptic_volumes : dict - has two keys, 'postsynaptic' and 'presynaptic.' Each key contains a list of volumes. 
    query : dict
    thresh : float
    resolution : dict

    Returns
    -----------
    antibody_measure : AntibodyAnalysis()
    """

    antibody_measure = AntibodyAnalysis(query)

    # Get data volume
    antibody_measure.volume_um3 = getdatavolume(synaptic_volumes, resolution)
    print('data volume: ', antibody_measure.volume_um3, 'um3')

    # Check to see if user supplied blobsize
    if 'punctumSize' in query.keys():
        blobsize = query['punctumSize']
        edge_win = int(np.ceil(blobsize * 1.5))

    # Data
    presynaptic_volumes = synaptic_volumes['presynaptic']
    postsynaptic_volumes = synaptic_volumes['postsynaptic']

    # Number of slices each blob should span
    preIF_z = query['preIF_z']
    postIF_z = query['postIF_z']

    # Compute raw mean and standard deviation
    antibody_measure = compute_raw_measures(presynaptic_volumes,
                                            antibody_measure, 'presynaptic')

    # SNR test
    raw_presynaptic_volumes = []
    for vol in presynaptic_volumes:
        raw_presynaptic_volumes.append(np.copy(vol))

    for n in range(0, len(presynaptic_volumes)):
        presynaptic_volumes[n] = syn.getProbMap(
            presynaptic_volumes[n])  # Step 1
        presynaptic_volumes[n] = syn.convolveVolume(presynaptic_volumes[n],
                                                    blobsize)  # Step 2
        if preIF_z[n] > 1:
            factor_vol = syn.computeFactor(presynaptic_volumes[n],
                                           int(preIF_z[n]))  # Step 3
            presynaptic_volumes[n] = presynaptic_volumes[n] * factor_vol

    # Compute single channel measurements
    antibody_measure = compute_single_channel_measurements(
        presynaptic_volumes, antibody_measure, thresh, 'presynaptic')

    # SNR test
    antibody_measure = compute_SNR_synapticside(raw_presynaptic_volumes,
                                                presynaptic_volumes, thresh,
                                                antibody_measure,
                                                'presynaptic')

    print('Computed presynaptic single channel measurements')

    # Compute raw mean and standard deviation
    antibody_measure = compute_raw_measures(postsynaptic_volumes,
                                            antibody_measure, 'postsynaptic')

    # SNR test
    raw_postsynaptic_volumes = []
    for vol in postsynaptic_volumes:
        raw_postsynaptic_volumes.append(np.copy(vol))

    for n in range(0, len(postsynaptic_volumes)):
        postsynaptic_volumes[n] = syn.getProbMap(
            postsynaptic_volumes[n])  # Step 1
        postsynaptic_volumes[n] = syn.convolveVolume(postsynaptic_volumes[n],
                                                     blobsize)  # Step 2
        if postIF_z[n] > 1:
            factor_vol = syn.computeFactor(postsynaptic_volumes[n],
                                           int(postIF_z[n]))  # Step 3
            postsynaptic_volumes[n] = postsynaptic_volumes[n] * factor_vol

    # Compute single channel measurements
    antibody_measure = compute_single_channel_measurements(
        postsynaptic_volumes, antibody_measure, thresh, 'postsynaptic')

    # SNR test
    antibody_measure = compute_SNR_synapticside(raw_postsynaptic_volumes,
                                                postsynaptic_volumes, thresh,
                                                antibody_measure,
                                                'postsynaptic')
    print('Computed postsynaptic single channel measurements')

    #"""
    if len(postsynaptic_volumes) == 0:
        resultVol = syn.combinePrePostVolumes(presynaptic_volumes,
                                              postsynaptic_volumes, edge_win,
                                              blobsize)
    else:
        resultVol = syn.combinePrePostVolumes(postsynaptic_volumes,
                                              presynaptic_volumes, edge_win,
                                              blobsize)

    # Compute whole statistics
    label_vol = measure.label(resultVol > thresh)
    stats = measure.regionprops(label_vol)
    antibody_measure.synapse_density = len(stats) / antibody_measure.volume_um3
    antibody_measure.synapse_count = len(stats)

    antibody_measure = calculuate_target_ratio(antibody_measure,
                                               target_antibody_name)
    #"""
    return antibody_measure