Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError: (19, 11)" AND AttributeError: module 'flowsig.plotting' has no attribute 'plot_differentially_flowing_signals'" #11

Open
YuNong-Qiu opened this issue Sep 13, 2024 · 4 comments

Comments

@YuNong-Qiu
Copy link

YuNong-Qiu commented Sep 13, 2024

Dear Author,
I encountered some issues while executing the code.

When I used the function 'fs.tl.construct_intercellular_flow_network(adata_dis, flowsig_network_key='flowsig_network', adjacency_key='adjacency_validated_filtered')', I encountered a KeyError. And I have checked the data 'adata_dis.uns['flowsig_network']['network']['adjacency_validated_filtered']', but it seemed no problem.

And I am unable to generate the plot using 'fs.pl.plot_differentially_flowing_signals'. The code and the error message are below.

I am eagerly awaiting your guidance on this matter. Thank you in advance for your assistance!

--1--
CODE:
flow_network = fs.tl.construct_intercellular_flow_network(adata_dis,
flowsig_network_key = 'flowsig_network',
adjacency_key = 'adjacency_validated_filtered')

{
"name": "KeyError",
"message": "(19, 11)",
"stack": "---------------------------------------------------------------------------

OUTPUT:
KeyError Traceback (most recent call last)
Cell In[51], line 1
----> 1 flow_network = fs.tl.construct_intercellular_flow_network(adata_dis,
2 flowsig_network_key = 'flowsig_network',
3 adjacency_key = 'adjacency_validated_filtered')

File c:\Users\Q\.conda\envs\COMMOT\Lib\site-packages\flowsig\tools\_validate_network.py:380, in construct_intercellular_flow_network(adata, flowsig_network_key, adjacency_key)
376 total_edge_weight = total_edge_weights[undirected_edge]
378 else:
--> 380 total_edge_weight = total_edge_weights[(undirected_edge[1], undirected_edge[0])]
382 flow_network.add_edge(*undirected_edge)
383 flow_network.edges[undirected_edge[0], undirected_edge[1]]['weight'] = min(total_edge_weight, 1.0)

KeyError: (19, 11)"
}

--2--
CODE:
fs.pl.plot_differentially_flowing_signals(
adata = adata_dis,
condition_key = 'Condition',
pert_key = 'GAS6',
var_type = 'inflow',
flowsig_expr_key = 'X_flow',
flowsig_network_key = 'flowsig_network_orig',
qval_threshold = 0.05,
logfc_threshold = 0.5,
label_lowqval = True
)

OUTPUT:
{
"name": "AttributeError",
"message": "module 'flowsig.plotting' has no attribute 'plot_differentially_flowing_signals'",
"stack": "---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[80], line 1
----> 1 fs.pl.plot_differentially_flowing_signals(
2 adata = adata_dis,
3 condition_key = 'Condition',
4 pert_key = 'GAS6',
5 var_type = 'inflow',
6 flowsig_expr_key = 'X_flow',
7 flowsig_network_key = 'flowsig_network_orig',
8 qval_threshold = 0.05,
9 logfc_threshold = 0.5,
10 label_lowqval = True
11 )

AttributeError: module 'flowsig.plotting' has no attribute 'plot_differentially_flowing_signals'"
}

@yang-lin-pp
Copy link

Hello! Have you solved it? I also got this when flowsig running. Can I ask for the solution?

@YuNong-Qiu
Copy link
Author

@yang-lin-pp
For the first question about a "keyError" , I tried to add a new conditional check so that if it's not in the key, it can be set to a default value in the 'construct_intercellular_flow_network' function.
For more details, you can refer to the function in flowsig/tools/_validate_network.py. On line 373, I have added a 'else' like:

if add_edge:
# Get the total edge weight
total_edge_weight = 0.0
edge_key = undirected_edge
reversed_edge_key = (undirected_edge[1], undirected_edge[0])

    if edge_key in total_edge_weights:
        total_edge_weight = total_edge_weights[edge_key]
    elif reversed_edge_key in total_edge_weights:
        total_edge_weight = total_edge_weights[reversed_edge_key]
    else:
        # Handle the case where the edge is not found in total_edge_weights
        # You can set a default value or handle the error as needed
        total_edge_weight = 1.0  # Example default value

However, I am uncertain whether this approach is reasonable. This may potentially affect some outcomes。

For the second question,I haven't figured out it yet.

@axelalmet
Copy link
Owner

Hi @YuNong-Qiu,

First up, sorry about the late response! You did nothing wrong, but I hadn't fully implemented pl.plot_differentially_flowing_signals yet. But with the latest version (0.1.2,), I finally added the plotting functions.

So now, if you want to plot the differentially inflowing variables, try calling something like:

fig, ax = plt.subplots(figsize=(6, 4))
fs.pl.plot_differentially_flowing_signals(adata = adata_dis,
                                                                condition_key = 'Condition',
                                                                pert_key = 'GAS6',
                                                                var_type = 'inflow',
                                                                flowsig_expr_key = 'X_flow_orig',
                                                                flowsig_network_key = 'flowsig_network_orig',
                                                                qval_threshold = 0.05,
                                                                logfc_threshold = 0.5,
                                                                label_lowqval = True,
                                                                ax=ax
                                                                )
plt.show()

Note that you have to set flowsig_expr_key = X_flow_orig to show the non-significantly flowing variable.s

I'll update the README.md to include an example and add a notebook example to show how you can use it by the end of this week. Thank you for your patience!

@YuNong-Qiu
Copy link
Author

Dear @axelalmet ,
Thank you for your answer. I will try it later. I am very interested in your research and look forward to your update!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants