Skip to content
Snippets Groups Projects
Commit 7ddc3228 authored by Constantin Pape's avatar Constantin Pape
Browse files

Simplify cell property calculation for gene attributes

parent 66c67a78
No related branches found
No related tags found
1 merge request!2Merge versioning and scripts into master
...@@ -11,44 +11,27 @@ from vigra.sampling import resize ...@@ -11,44 +11,27 @@ from vigra.sampling import resize
# make test to check against original table # make test to check against original table
def get_bbs(data): def get_sizes_and_bbs(data):
num_cells = (np.max(data)).astype('int') + 1 # compute the relevant vigra region features
cells_bbs = [[] for i in range(num_cells)] features = extractRegionFeatures(data.astype('float32'), data.astype('uint32'),
mins_and_maxs = extractRegionFeatures(data.astype('float32'), data.astype('uint32'), features=['Coord<Maximum >', 'Coord<Minimum >', 'Count'])
features=['Coord<Maximum >', 'Coord<Minimum >'])
mins = mins_and_maxs['Coord<Minimum >'].astype('uint32')
maxs = mins_and_maxs['Coord<Maximum >'].astype('uint32') + 1
for cell in range(num_cells):
cell_bb = []
cell_min = mins[cell]
cell_max = maxs[cell]
for axis in range(3):
cell_bb.append(slice(cell_min[axis], cell_max[axis]))
cells_bbs[cell] = tuple(cell_bb)
return cells_bbs
# extract sizes from features
cell_sizes = features['Count'].squeeze().astype('uint64')
# TODO very inefficient, can use "Count" feature of vigra features instead # compute bounding boxes from features
# and then just do this in `get_bbs` as well mins = features['Coord<Minimum >'].astype('uint32')
def get_cell_sizes(data): maxs = features['Coord<Maximum >'].astype('uint32') + 1
max_label = (np.max(data)).astype('uint32') cell_bbs = [tuple(slice(mi, ma) for mi, ma in zip(min_, max_))
cell_sizes = [0] * (max_label + 1) for min_, max_ in zip(mins, maxs)]
Z, X, Y = data.shape return cell_sizes, cell_bbs
for z in range(Z):
for x in range(X):
for y in range(Y):
label = data[z, x, y]
cell_sizes[label] += 1
cell_sizes = np.array(cell_sizes)
return cell_sizes
def get_cell_expression(segm_data, all_genes): def get_cell_expression(segm_data, all_genes):
num_genes = all_genes.shape[0] num_genes = all_genes.shape[0]
labels = list(np.unique(segm_data)) labels = list(np.unique(segm_data))
cells_expression = np.zeros((len(labels), num_genes), dtype='float32') cells_expression = np.zeros((len(labels), num_genes), dtype='float32')
cell_sizes = get_cell_sizes(segm_data) cell_sizes, cell_bbs = get_sizes_and_bbs(segm_data)
cell_bbs = get_bbs(segm_data)
for cell_idx in range(len(labels)): for cell_idx in range(len(labels)):
cell_label = labels[cell_idx] cell_label = labels[cell_idx]
if cell_label == 0: if cell_label == 0:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment