how to run the spatial-LDA on all cells
MagdalenaMat opened this issue · comments
I'd like to run the spatial-LDA on all the cells in my dataset. I tried to set all cells as index cells by setting is_anchor_col argument in the featurize_samples function to a column where all values are True, but that produces an error.
if os.path.exists(PATH_TO_TUMOR_MARKER_FEATURES_PKL):
with open(PATH_TO_TUMOR_MARKER_FEATURES_PKL, 'rb') as f:
tumor_marker_features = pickle.load(f)
else:
neighborhood_feature_fn = functools.partial(neighborhood_to_marker,
markers=markers)
tumor_marker_features = featurize_samples(patient_dfs, neighborhood_feature_fn, 100, 'is_index',
'x', 'y', n_processes=N_PARALLEL_PROCESSES)
with open(PATH_TO_TUMOR_MARKER_FEATURES_PKL, 'wb') as f:
pickle.dump(tumor_marker_features, f)
ERROR:
RemoteTraceback Traceback (most recent call last)
RemoteTraceback:
"""
Traceback (most recent call last):
File "/home/kidzik/miniconda3/envs/spatial-lda/lib/python3.7/multiprocessing/pool.py", line 121, in worker
result = (True, func(*args, **kwds))
File "/home/kidzik/miniconda3/envs/spatial-lda/lib/python3.7/site-packages/spatial_lda-0.0.3-py3.7.egg/spatial_lda/featurization.py", line 51, in _featurize_sample
is_anchor_col, x_col, y_col, z_col=z_col)
File "/home/kidzik/miniconda3/envs/spatial-lda/lib/python3.7/site-packages/spatial_lda-0.0.3-py3.7.egg/spatial_lda/featurization.py", line 38, in _featurize_cells
neighborhood_kdTree = KDTree(neighborhood_cells[coord_cols].values)
File "/home/kidzik/miniconda3/envs/spatial-lda/lib/python3.7/site-packages/scipy/spatial/kdtree.py", line 239, in init
self.maxes = np.amax(self.data,axis=0)
File "/home/kidzik/miniconda3/envs/spatial-lda/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 2505, in amax
initial=initial)
File "/home/kidzik/miniconda3/envs/spatial-lda/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 86, in _wrapreduction
return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
ValueError: zero-size array to reduction operation maximum which has no identity
"""
The above exception was the direct cause of the following exception:
ValueError Traceback (most recent call last)
in
7
8 tumor_marker_features = featurize_samples(patient_dfs, neighborhood_feature_fn, 100, 'is_index',
----> 9 'x', 'y', n_processes=N_PARALLEL_PROCESSES)
10 with open(PATH_TO_TUMOR_MARKER_FEATURES_PKL, 'wb') as f:
11 pickle.dump(tumor_marker_features, f)
~/miniconda3/envs/spatial-lda/lib/python3.7/site-packages/spatial_lda-0.0.3-py3.7.egg/spatial_lda/featurization.py in featurize_samples(sample_dfs, neighborhood_feature_fn, radius, is_anchor_col, x_col, y_col, z_col, n_processes)
87 all_sample_features = list(tqdm(pool.imap(featurize_sample_fn,
88 sample_dfs.items()),
---> 89 total=total))
90 else:
91 for i, sample_df in sample_dfs.items():
~/miniconda3/envs/spatial-lda/lib/python3.7/site-packages/tqdm/_tqdm_notebook.py in iter(self, *args, **kwargs)
221 def iter(self, *args, **kwargs):
222 try:
--> 223 for obj in super(tqdm_notebook, self).iter(*args, **kwargs):
224 # return super(tqdm...) will not catch exception
225 yield obj
~/miniconda3/envs/spatial-lda/lib/python3.7/site-packages/tqdm/_tqdm.py in iter(self)
1003 """), fp_write=getattr(self.fp, 'write', sys.stderr.write))
1004
-> 1005 for obj in iterable:
1006 yield obj
1007 # Update and possibly print the progressbar.
~/miniconda3/envs/spatial-lda/lib/python3.7/multiprocessing/pool.py in next(self, timeout)
746 if success:
747 return value
--> 748 raise value
749
750 next = next # XXX
ValueError: zero-size array to reduction operation maximum which has no identity
I think it's because the neighborhood_cells becomes an empty arrey if I set all cells as index cells.
Can you kindly advise on how to run the pipeline on all the cells, please?
Thanks a lot!
Magda