location to load python code fro using CytoscapeRPC

126 views
Skip to first unread message

sanjan

unread,
Jun 19, 2012, 2:21:57 AM6/19/12
to cytoscape-discuss
Hi,

I just installed the cytoscapeRPC plug in so that i can write a python
code for automating the process of loading files into Cytoscape and
saving the generated output.I found the following code in one of the
earlier discussions:
https://trac.nbic.nl/brs2011p07/browser/trunk/brs2011p07/src/piqc/data2network.py?rev=20

I would like to know the path as to where the code should be saved for
compiling.I am using cytoscape2.8.3 version(installed on ubuntu12.04)
which is stored in my desktop.I tried by saving the code in cytoscape
dir as well as in documents dir.(pasted the code given in above link
in gedit and tried compiling using terminal)But none worked.

Thanks in advance.

Tim te Beek

unread,
Jun 20, 2012, 9:20:30 AM6/20/12
to cytoscap...@googlegroups.com
Hi Sanjan,

The latest version of that project is located here:
The link you ave points to a old revision, the tag above is more stable.

You can store the python code anywhere you want, preferably outside the Cytoscape install folder. It's not tied to Cytoscape in anyway: It merely talks to the XMLRPC server that you can enable from the CytoscapeRPC plugin. To run the code just type `python data2network.py` in your favorite terminal.

Does that help?

Best regards,
Tim

Sanjan Tp

unread,
Jun 20, 2012, 12:46:14 PM6/20/12
to cytoscap...@googlegroups.com
Hi Tim,

Actually i tried compiling the code and got the following error message:
Traceback (most recent call last):
  File "data2net.py", line 8, in <module>
    from __init__ import connect2cytoscape
ImportError: cannot import name connect2cytoscape

Actually I could not figure out as to where to mention the input file name(its gedit text file having two columns separated by tab-former being source and the latter being target).
In fact i have a directory of such files.So instead of filename can dir be mentioned and made to iterate over all the files?

Thanks for spending time.

Sanjan

Tim te Beek

unread,
Jun 20, 2012, 4:13:41 PM6/20/12
to cytoscap...@googlegroups.com
Hi Sanjan,

Could it be that you're getting this error because you've only compied the data2networkpy file, and not the accompanying __init__.py file? That would explain the error that you're getting.

Also, I'm somewhat confused as to what you are trying to achieve: Do you want to write your own code that connects to cytoscape using my code as an example, or do you merely want to use the python scripts I've created?

I could make my code run by executing the following statements in this order:
A    piqc/test
A    piqc/test/__init__.py
A    piqc/test/test_data2network.py
A    piqc/count_graphs.py
A    piqc/__init__.py
A    piqc/data2network.py
Checked out revision 436.

$ python data2network.py --help
Usage: Data2Network.py [options]

Convert a spreadsheet of data to a Cytoscape network.

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -f FILE, --file=FILE  Peptide identification and quantification data as .tsv
                        or .csv
  -s SOURCE, --source=SOURCE
                        Source node attribute
  -t TARGET, --target=TARGET
                        Target node attribute

$ python data2network.py -f ../../my_import_file.tsv -s Source_column -t Target_column
...


This script is however a very complicated way to import data: For single files it's probably better to use the Table Import Plugin already provided with Cytoscape. For the directory of files that you mention you would have to write the loop in bash, or alter the Python code yourself. This is currently not supported, and probably wont be in the future, as I've moved development to Java instead of Python.


If you want to use my scripts as an example on how to connect to Cytoscape & CytoscapeRPC from Python, have a look at, and maybe copy, the __init__.py file from the same folder: 
It contains a connect2cytoscape method that returns a handle that allows you to execute all the commands listed in the CytoscapeRPC documentation:
It's best to explore this from an interactive Python session, preferably an iPython session because you'll get tab-completion on the available methods.

Please let me know what it is you're trying to achieve, so I can target my suggestions accordingly.

Best,
Tim

Sanjan Tp

unread,
Jun 21, 2012, 3:34:23 AM6/21/12
to cytoscap...@googlegroups.com
Hi TIm,

I converted one of the text files to csv file(in libre calc) and tried compiling _init_.py first but still getting the same error as follows:

sanjan@ubuntu:~/Documents/programs/cytoRPC$ python _init_.py
sanjan@ubuntu:~/Documents/programs/cytoRPC$ python data2net.py -f test.csv -s source -t target

Traceback (most recent call last):
  File "data2net.py", line 8, in <module>
    from __init__ import connect2cytoscape
ImportError: cannot import name connect2cytoscape

Let me clearly state what i am trying to do:

I have a large number of text files having two columns separated by tab(source and target).All of them are stored in one directory.Instead of manually importing  the files into cytoscape,generate graph ,use network anlyser plug-in and finally save the statistics generated(deg distribution,clustering coeff. etc), I thought of automating it through RPC plug in.But since I am fairly new to python couldn't code it and thought of using ur code as it too serves similar purpose.

I would be glad if there's a custom made code or if u can give some pointers as to how to code in python or bash.

I am familiar with basics of python but dont know how to load files to cytoscape , generate graphs...

thanks,

Sanjan

Tim te Beek

unread,
Jun 21, 2012, 4:04:56 AM6/21/12
to cytoscap...@googlegroups.com
Not sure why that would be failing.. Could you instead copy the contents of __init__.py to the start of data2net.py, and remove the following line:

from __init__ import connect2cytoscape

You should then be able to remove the __init__.py as a separate file, and running data2net.py should work, provided you have Cytoscape open, and the CytoscapeRPC plugin server is running.

Best,
Tim


--
You received this message because you are subscribed to the Google Groups "cytoscape-discuss" group.
To post to this group, send email to cytoscap...@googlegroups.com.
To unsubscribe from this group, send email to cytoscape-disc...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cytoscape-discuss?hl=en.

Sanjan Tp

unread,
Jun 21, 2012, 8:36:04 AM6/21/12
to cytoscap...@googlegroups.com
Hey it worked.Thanks for the info.

But the  fact is i need to convert the file to csv everytime(the text files i hav are .dat/.sif)

So i was thinking of using the following code:
https://trac.nbic.nl/cytoscaperpc/browser/CytoscapeRPC/scripts 

the file loadnetwork.py

I modified the code a little bit as i dont have any edge and node attribute files(attached code).The code ran and created only one node and terminated giving the following error:

sanjan@ubuntu:~/Documents/programs/cytoRPC$ python myload.py 9000 ip test_216
Working on sif-file: eco_links156_long.sif

Traceback (most recent call last):
  File "myload.py", line 139, in <module>
    run()
  File "myload.py", line 109, in run
    edge_ids = server.Cytoscape.createEdges(netid, nodes_from, nodes_to,[True]*len(nodes_to), True)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1224, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1578, in __request
    verbose=self.__verbose
  File "/usr/lib/python2.7/xmlrpclib.py", line 1264, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1297, in single_request
    return self.parse_response(response)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1473, in parse_response
    return u.close()
  File "/usr/lib/python2.7/xmlrpclib.py", line 793, in close
    raise Fault(**self._stack[0])
xmlrpclib.Fault: <Fault 0: 'No method matching arguments: java.lang.String, [Ljava.lang.Object;, [Ljava.lang.Object;, [Ljava.lang.Object;, java.lang.Boolean'>

Also can the network analyser(the preinstalled one on cytoscape2.8.3) plug-in be used through RPC?
 
-
Sanjan
myload.py

Tim te Beek

unread,
Jun 21, 2012, 9:40:11 AM6/21/12
to cytoscap...@googlegroups.com
Hi Sanjan,

Sorry to say I can't help you with that: I have no experience with that script, or calling plugins through CytoscapeRPC, but maybe Jan Bot can help you (it's his script).

Best,
Tim


 
-
Sanjan

--
Reply all
Reply to author
Forward
0 new messages