Closed degrainger closed 6 months ago
Describe the bug Unable to run dimensionality reduction (run_umap() or run_tsne() on my cistopic object.
To Reproduce
# Load cisTopic object import pickle infile = open(outDir + 'cistopic_obj_filtered.pkl', 'rb') cistopic_obj = pickle.load(infile) infile.close()
from pycisTopic.clust_vis import ( find_clusters, run_umap, run_tsne, plot_metadata, plot_topic, cell_topic_heatmap )
run_umap( cistopic_obj, target = 'cell', scale=True)
Error output
2024-05-17 10:10:36,400 cisTopic INFO Running UMAP KeyError Traceback (most recent call last) Cell In[7], line 1 ----> 1 run_umap( 2 cistopic_obj, 3 target = 'cell', scale=True) File ~/pycisTopic/src/pycisTopic/clust_vis.py:249, in run_umap(cistopic_obj, target, scale, reduction_name, random_state, selected_topics, selected_features, harmony, rna_components, rna_weight, **kwargs) 247 dr = pd.DataFrame(embedding, index=data_names, columns=["UMAP_1", "UMAP_2"]) 248 if target == "cell": --> 249 cistopic_obj.projections["cell"][reduction_name] = dr 250 if target == "region": 251 cistopic_obj.projections["region"][reduction_name] = dr KeyError: 'cell'
KeyError Traceback (most recent call last) Cell In[7], line 1 ----> 1 run_umap( 2 cistopic_obj, 3 target = 'cell', scale=True)
File ~/pycisTopic/src/pycisTopic/clust_vis.py:249, in run_umap(cistopic_obj, target, scale, reduction_name, random_state, selected_topics, selected_features, harmony, rna_components, rna_weight, **kwargs) 247 dr = pd.DataFrame(embedding, index=data_names, columns=["UMAP_1", "UMAP_2"]) 248 if target == "cell": --> 249 cistopic_obj.projections["cell"][reduction_name] = dr 250 if target == "region": 251 cistopic_obj.projections["region"][reduction_name] = dr
KeyError: 'cell'
Expected behavior UMAP to be calculated for my object
Version (please complete the following information):
Hi @degrainger
Does
cistopic_obj.projections["cell"] = {}
Before running the function fix your issue?
Best,
Seppe
Thanks very much @SeppeDeWinter, that worked a treat! Best wishes, Dave
Describe the bug Unable to run dimensionality reduction (run_umap() or run_tsne() on my cistopic object.
To Reproduce
Error output
Expected behavior UMAP to be calculated for my object
Version (please complete the following information):