def getImageProbMapCutoutFromFile(channelname, sliceInd, startX, startY, deltaX, deltaY, filepath): """ Load cutout of a slice of a tiff image Parameters ----------- channelname : str sliceInd : ind startX : ind startY : ind deltaX : ind deltaY : ind filepath : str Returns ----------- cutout: 2D numpy array """ folderpath = os.path.join(filepath, channelname) img = da.imreadtiffSingleSlice(folderpath, sliceInd) img.astype(np.float64) probimg = syn.getProbMap(img) cutout = probimg[startY:(startY + deltaY), startX:(startX + deltaX)] return cutout
def measure_yfp(vol, thresh): """ measure the number of yfp voxels in a volume Parameters ------------ vol - 3d numpy array thresh - float threshold Return ----------- result - int """ probvol = syn.getProbMap(vol) probvol = probvol > thresh result = np.sum(probvol) return result
def segment_dendrites(vol, thresh, num_of_dendrites, output_dir): """ segment dendrites Parameters ------------ vol - 3d numpy array thresh - float threshold Return ----------- result - int """ probvol = syn.getProbMap(vol) bw_vol = probvol > thresh SE = morph.ball(5) bw_vol = morph.closing(bw_vol, SE) label_vol = measure.label(bw_vol, connectivity=2) stats = measure.regionprops(label_vol) # sort by size size_list = [] for stat in stats: size_list.append(stat.area) ind_list = np.flip(np.argsort(size_list), 0) for n in range(0, num_of_dendrites): dendrite = stats[ind_list[n]] list_of_coords = dendrite.coords list_of_coords = np.array(list_of_coords) filename = 'dendrite' + str(n) + '.off' output_filename = os.path.join(output_dir, filename) write_off_file(list_of_coords, output_filename) stl_filename = os.path.join(output_dir, 'dendrite' + str(n) + '.stl') print('number of points: ', str(len(list_of_coords))) # if len(list_of_coords) < 40000: # print('starting meshlab', output_filename) # subprocess.call(["meshlabserver", "-i", output_filename, # "-o", stl_filename, "-s", "ballpivot.mlx"]) # else: # print('starting meshlab subsampling', output_filename) # subprocess.call(["meshlabserver", "-i", output_filename, # "-o", stl_filename, "-s", "ballpivot2.mlx"]) print('stl created', stl_filename) return stl_filename
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