ben-j-barlow / clustree

In development: Visualize clusterings at different resolutions
GNU General Public License v3.0
2 stars 1 forks source link

KeyError: 'res' #14

Open Sawyerxu opened 2 months ago

Sawyerxu commented 2 months ago
Thanks for your amazing tools. Here is my errors, my input dataframe data_frame like this: Sample resolution_1 resolution_2 resolution_3 resolution_4 resolution_5 resolution_6 resolution_7 resolution_8 resolution_9 resolution_10 resolution_11
GSM5573477_GC12AAACCTGCAAGAAAGG 6 8 6 4 4 4 4 1 1 37 37
GSM5573477_GC12AAACGGGGTCCAGTGC 0 2 1 7 5 5 5 19 22 13 10
GSM5573477_GC12AAACGGGTCGCGTTTC 11 13 13 14 12 12 11 9 6 3 1
GSM5573477_GC12AAAGATGGTTGTCTTT 11 13 13 14 12 12 11 9 6 3 82
GSM5573477_GC12AAAGCAAGTGGTCCGT 0 1 3 2 2 1 1 0 0 1 0
... ... ... ... ... ... ... ... ... ... ... ...
GSM5573501_GC36TTTGGTTGTCGTGTTA 9 11 11 12 20 20 20 20 23 18 15
GSM5573501_GC36TTTGTTGGTATATGGA 1 5 5 5 6 3 3 3 52 57 53
GSM5573501_GC36TTTGTTGGTGACTCGC 7 1 15 11 10 13 13 13 13 14 11
GSM5573501_GC36TTTGTTGGTTCTGAGT 6 8 6 4 4 4 4 1 1 2 5
GSM5573501_GC36TTTGTTGGTTGCTTGA 0 2 1 7 5 5 5 19 22 13 10

And i run this command clustree(data=data_frame, prefix='resolution_',images='/home/data') and raise this error:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[50], line 2
      1 from clustree import clustree
----> 2 clustree(data=data_frame, prefix='resolution_',images=save_dir)

File [~/miniforge3/envs/singlecell2/lib/python3.10/site-packages/clustree/_graph.py:157](http://10.102.34.21:9872/home/vv/miniforge3/envs/singlecell2/lib/python3.10/site-packages/clustree/_graph.py#line=156), in clustree(data, prefix, images, output_path, draw, node_color, node_color_aggr, node_cmap, edge_color, edge_cmap, orientation, layout_reingold_tilford, min_cluster_number, border_size, figsize, arrows, node_size, node_size_edge, dpi, kk)
    154     if kk < 13:
    155         layout_reingold_tilford = True
--> 157 config = ClustreeConfig(
    158     prefix=prefix,
    159     kk=kk,
    160     data=_data,
    161     node_color=node_color,
    162     node_color_aggr=node_color_aggr,
    163     node_cmap=node_cmap,
    164     edge_color=edge_color,
    165     edge_cmap=edge_cmap,
    166     start_at_1=start_at_1,
    167 )
    169 dg = construct_clustree(cf=config)
    170 if draw or output_path:

File [~/miniforge3/envs/singlecell2/lib/python3.10/site-packages/clustree/_config.py:73](http://10.102.34.21:9872/home/vv/miniforge3/envs/singlecell2/lib/python3.10/site-packages/clustree/_config.py#line=72), in ClustreeConfig.__init__(self, kk, data, prefix, node_color, node_color_aggr, node_cmap, edge_color, edge_cmap, start_at_1, _setup_cf)
     71     self.set_sample_information(data=cluster_membership)
     72 if _setup_cf["node_color"]:
---> 73     self.set_node_color(
     74         node_color=node_color,
     75         aggr=node_color_aggr,
     76         cmap=node_cmap,
     77         prefix=prefix,
     78         data=data,
     79     )
     80 if _setup_cf["edge_color"]:
     81     self.set_edge_color(edge_color=edge_color, cmap=edge_cmap, prefix=prefix)

File [~/miniforge3/envs/singlecell2/lib/python3.10/site-packages/clustree/_config.py:151](http://10.102.34.21:9872/home/vv/miniforge3/envs/singlecell2/lib/python3.10/site-packages/clustree/_config.py#line=150), in ClustreeConfig.set_node_color(self, node_color, cmap, aggr, data, prefix)
    148 if node_color == prefix:
    149     for node_id, attr in self.node_cf.items():
    150         self.node_cf[node_id]["node_color"] = mpl.colors.to_rgba(
--> 151             f"C{attr['res']}"
    152         )
    153 elif (use_samples := node_color == "samples") or (node_color in data.columns):
    154     # create to_parse = {node_id: value}
    155     if use_samples:

KeyError: 'res'

Is my datafram format wrong? Thanks.