emreg00 / guild

GUILD - Genes Underlying Inheritance Linked Disorders - Network-based disease-gene prioritization algorithms
5 stars 2 forks source link

Problems to execute python script create_random_networks_for_netzcore.py #1

Open Jordi-Valls opened 2 years ago

Jordi-Valls commented 2 years ago

Dear all,

My name is Jordi Valls, and I'm trying to execute the python script create_random_networks_for_netzcore.py from NetZcore module of GUILD.

I try to execute GUILD following the tutorial of README:

python3 src/create_random_networks_for_netzcore.py data/test_interactions.txt 100

Unfortunately it breaks giving me the following error:

File "src/create_random_networks_for_netzcore.py", line 32 g_sampled = randomize_graph(graph=g, randomization_type="preserve_topology_and_node_degree") ^ TabError: inconsistent use of tabs and spaces in indentation

Could you help me to fix this error?? In addition, when I execute Guild with -s z, without -x value it works....

So could you tell me the importance of X parameter??

Thanks for your help!

Jordi

emreg00 commented 2 years ago

Hi Jordi,

Unfortunately, this script is in Python2 and has not been ported to Python3. Though it would be relatively straightforward to adapt using 2to3 tool, you might need to adjust some functions in relation to NetworkX in addition.

If you dont provide -x, GUILD will use the default value for the number of random graphs, which is 0 (see nSampled in main.cpp) and thus, the results wont make much sense.

Let me know if you need further help with the code. Also if you happen to port this code into Python3, let me know and I can include it in the repo.

Best wishes,

Emre

Jordi-Valls commented 2 years ago

Hi Emre,

Is true I solved it when I executed the script with python version 2.7. But now I find a new problem... with the same script: create_random_networks_for_netzcore.py

When I execute it I obtain this error:

python src/create_random_networks_for_netzcore.py data/test_interactions.txt 100

Traceback (most recent call last): File "src/create_random_networks_for_netzcore.py", line 406, in main() File "src/create_random_networks_for_netzcore.py", line 25, in main sample_network_preserving_topology(network_file, n_sample, network_file + ".") File "src/create_random_networks_for_netzcore.py", line 30, in sample_network_preserving_topology g = create_network_from_sif_file(network_file_in_sif = network_sif_file, use_edge_data = True) File "src/create_random_networks_for_netzcore.py", line 48, in create_network_from_sif_file g.add_edge(u,v,{"w":w}) TypeError: add_edge() takes exactly 3 arguments (4 given)

I dont know where is this fourth argument.... I tried to modify the script but the error persist...

Thanks for your help and time

emreg00 commented 2 years ago

Hi Jordi,

This is because the add_edge function definition had been updated a while ago in NetworkX. A quick work around could be replacing g.add_edge(u,v,{"w":w}) with g.add_edge(u,v,**{"w":w}) and trying again.

Hope it helps,

Emre

Jordi-Valls commented 2 years ago

Hi Emre, it seems that we are close to get it. Now the script breaks with this error...

Traceback (most recent call last): File "src/create_random_networks_for_netzcore.py", line 403, in main() File "src/create_random_networks_for_netzcore.py", line 25, in main sample_network_preserving_topology(network_file, n_sample, network_file + ".") File "src/create_random_networks_for_netzcore.py", line 32, in sample_network_preserving_topology g_sampled = randomize_graph(graph=g, randomization_type="preserve_topology_and_node_degree") File "src/create_random_networks_for_netzcore.py", line 233, in randomize_graph nodes_by_degree = dict( (degree,[]) for degree in graph.degree().values() ) AttributeError: 'DegreeView' object has no attribute 'values'

Thanks for your help

Jordi-Valls commented 2 years ago

Hi Emre,

Following your advice, I installed an old version of Networx version (1.10) and the script works!

Thanks for your help! But let me ask you a question... This script "src/create_random_networks_for_netzcore.py" repeated the same scores of edges every time? Because I obtained the same results every time, without any modification. This script do the same as if I copy the file 100 times?

Thanks!

emreg00 commented 2 years ago

Hi Emre, it seems that we are close to get it. Now the script breaks with this error...

Traceback (most recent call last): File "src/create_random_networks_for_netzcore.py", line 403, in main() File "src/create_random_networks_for_netzcore.py", line 25, in main sample_network_preserving_topology(network_file, n_sample, network_file + ".") File "src/create_random_networks_for_netzcore.py", line 32, in sample_network_preserving_topology g_sampled = randomize_graph(graph=g, randomization_type="preserve_topology_and_node_degree") File "src/create_random_networks_for_netzcore.py", line 233, in randomize_graph nodes_by_degree = dict( (degree,[]) for degree in graph.degree().values() ) AttributeError: 'DegreeView' object has no attribute 'values'

Thanks for your help

You can modify the code nodes_by_degree = dict( (degree,[]) for degree in graph.degree().values() ) graph_degree = graph.degree() with following to avoid this error that is originating from the inconsistency of the NetworkX version: graph_degree = graph.degree() nodes_by_degree = dict( (degree,[]) for u, degree in graph_degree)

emreg00 commented 2 years ago

Hi Emre,

Following your advice, I installed an old version of Networx version (1.10) and the script works!

Thanks for your help! But let me ask you a question... This script "src/create_random_networks_for_netzcore.py" repeated the same scores of edges every time? Because I obtained the same results every time, without any modification. This script do the same as if I copy the file 100 times?

Thanks!

Hi Jordi,

Glad that you made it work.

The script preserves the edge scores that were given in the input file. It simply shuffles nodes with the same (or similar / equivalent) degrees to create new networks with exactly the same topology. Accordingly, the networks will be different from each other as different nodes will be connected with each other in each of them (and thus it is not the same as copying the same file 100 times).

Hope this helps,

Emre