cytoscape / py2cytoscape

Python utilities for Cytoscape and Cytoscape.js
https://py2cytoscape.readthedocs.io
MIT License
178 stars 45 forks source link

Cyrest not loading style from file #87

Closed mwang87 closed 5 years ago

mwang87 commented 5 years ago

I attempt to execute this code:

from py2cytoscape import cyrest

cytoscape=cyrest.cyclient() cytoscape.version() cytoscape.network.list() cytoscape.vizmap.load_file(afile="./styles.xml", verbose=True)

where styles.xml is exported as an xml style from Cytoscape UI

Cytoscape: 3.7.1

CyRest: 1

Java:

Code:

error:

apiVersion v1 cytoscapeVersion 3.7.1

UnboundLocalError Traceback (most recent call last)

in () 5 cytoscape.network.list() 6 #cytoscape.vizmap.apply(styles="Sample1") ----> 7 cytoscape.vizmap.load_file(afile="./styles.xml", verbose=True) /usr/local/lib/python3.6/dist-packages/py2cytoscape/cyrest/vizmap.py in load_file(self, afile, verbose) 81 """ 82 ---> 83 network=check_network(self,network,verbose=verbose) 84 PARAMS=set_param(["afile"],[afile]) 85 response=api(url=self.__url+"/load file", PARAMS=PARAMS, method="POST", verbose=verbose) UnboundLocalError: local variable 'network' referenced before assignment
zachary822 commented 5 years ago

You have to pass the contents of the XML, not the file path.

with open('styles.xml') as f:
    cytoscape.vizmap.load_file(f.read(), verbose=True)

(Needless to say the pull request needs to be merged first before this actually works.)

mwang87 commented 5 years ago

Thanks! I still have the same issue when passing in the xml string.

zachary822 commented 5 years ago

I know. There is a problem with the code and your usage. #89 needs to be merged before this will actually work.

zachary822 commented 5 years ago

If you want to try it right now. You can uninstall the original version and do pip3 install git+https://github.com/zachary822/py2cytoscape.git@5712ea6fc131ad0e11f565c0377c428961cd1d40

mwang87 commented 5 years ago

LOL, maybe I should actually read the full context of the message next time. Thanks for the help. I'll wait for it to get merged into master and try again.