theislab / graphcompass

GraphCompass: Graph Comparison Tools for Differential Analyses in Spatial Systems
MIT License
32 stars 0 forks source link

Iterate through list to make a graph per term #61

Closed spatts14 closed 1 month ago

spatts14 commented 2 months ago

It is possible to iterate through a list and save the plots individually?

e.g list = ["term1", "term2", "term3"]

for term in list: gc.pl.filtration_curves.compare_conditions( adata=adata, node_labels=term, # Set node_labels to the current term metric_key=metric_key, palette="Set2", save=f"figures/{term}_filtration_curves.pdf" )

Thanks!

merelkuijs commented 2 months ago

Yes, that is possible. The only change you need to make is to put "term" between square brackets:

gc.pl.filtration_curves.compare_conditions(
        adata=adata,
        node_labels=[term], # Set node_labels to the current term
        metric_key=metric_key,
        palette="Set2",
        save=f"figures/{term}_filtration_curves.pdf"
)
spatts14 commented 2 months ago

Ill try that thanks!

mayarali commented 2 months ago

@spatts14, can you please confirm that this solved your issue? If so, we'll close this issue.

spatts14 commented 2 months ago

Hi sorry!

I got this error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[13], [line 2](vscode-notebook-cell:?execution_count=13&line=2)
      [1](vscode-notebook-cell:?execution_count=13&line=1) for term in cell_type_names:
----> [2](vscode-notebook-cell:?execution_count=13&line=2)     gc.pl.filtration_curves.compare_conditions(
      [3](vscode-notebook-cell:?execution_count=13&line=3)         adata=adata,
      [4](vscode-notebook-cell:?execution_count=13&line=4)         node_labels=[term], # Set node_labels to the current term
      [5](vscode-notebook-cell:?execution_count=13&line=5)         metric_key=metric_key,
      [6](vscode-notebook-cell:?execution_count=13&line=6)         palette="Set2",
      [7](vscode-notebook-cell:?execution_count=13&line=7)         save=f"figures/{term}_filtration_curves.pdf"
      [8](vscode-notebook-cell:?execution_count=13&line=8) )

File [/opt/anaconda3/envs/graphcompass/lib/python3.11/site-packages/graphcompass/pl/_filtration_curves.py:91](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/graphcompass/lib/python3.11/site-packages/graphcompass/pl/_filtration_curves.py:91), in compare_conditions(adata, node_labels, metric_key, return_ax, figsize, dpi, palette, right, save, **kwargs)
     [89](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/graphcompass/lib/python3.11/site-packages/graphcompass/pl/_filtration_curves.py:89) for i, key in enumerate(node_labels):
     [90](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/graphcompass/lib/python3.11/site-packages/graphcompass/pl/_filtration_curves.py:90)     try:
---> [91](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/graphcompass/lib/python3.11/site-packages/graphcompass/pl/_filtration_curves.py:91)         axes[i].step(
     [92](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/graphcompass/lib/python3.11/site-packages/graphcompass/pl/_filtration_curves.py:92)             df.weight,
     [93](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/graphcompass/lib/python3.11/site-packages/graphcompass/pl/_filtration_curves.py:93)             df[key],
     [94](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/graphcompass/lib/python3.11/site-packages/graphcompass/pl/_filtration_curves.py:94)             where='pre',
     [95](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/graphcompass/lib/python3.11/site-packages/graphcompass/pl/_filtration_curves.py:95)             label=label[0],
     [96](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/graphcompass/lib/python3.11/site-packages/graphcompass/pl/_filtration_curves.py:96)             color=category_color_map[label[0]],
     [97](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/graphcompass/lib/python3.11/site-packages/graphcompass/pl/_filtration_curves.py:97)             alpha=0.15
     [98](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/graphcompass/lib/python3.11/site-packages/graphcompass/pl/_filtration_curves.py:98)         )
     [99](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/graphcompass/lib/python3.11/site-packages/graphcompass/pl/_filtration_curves.py:99)     except KeyError:
    [100](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/graphcompass/lib/python3.11/site-packages/graphcompass/pl/_filtration_curves.py:100)         continue

TypeError: 'Axes' object is not subscriptable
merelkuijs commented 1 month ago

Hi again!

I've pushed changes to resolve the bug you're seeing. We will include the updated code in the next release. If you want to make the plots immediately, you can install the updated code from the development branch:

git clone https://github.com/theislab/graphcompass.git
cd graphcompass
pip install -e .['development']
spatts14 commented 1 month ago

Thank you!

merelkuijs commented 1 month ago

GraphCompass 0.2.4 is now available on PyPi. You can get the updated version using pip install --upgrade graphcompass.