在 Cytoscape 中使用不同参数循环调用应用程序

Call an app in a loop with different parameters in Cytoscape

我是 Cytoscape 的新手。我想知道如何在 Cytoscape 中使用不同的参数多次 运行 一个应用程序(例如 MCL 聚类算法)。有什么方法可以编写脚本来执行此操作,而不是 运行 手动多次针对不同的参数? 谢谢!

我认为 Ruth 在 cytoscape-helpdesk 中非常清楚地回答了这个问题:

You can do all of the above. Whatever is easiest for you. There is a library py2cytoscape that you can use to issue commands to cytoscape from > python. Info can be found here: https://py2cytoscape.readthedocs.io/en/latest/ for more info on automation in cytoscape check out: http://manual.cytoscape.org/en/stable/Programmatic_Access_to_Cytoscape_Features_Scripting.html

But you can also run it through automation. You can create a text file with each of > your commands (for example a list of commands like: cluster mcl attribute="correlation" network=1234") and then go to Tools --> execute batch file to > execute the whole file. I am not sure if support loops. If you want to loop through anything I would recommend using python.

Thanks, Ruth

我只是补充一点,目前批处理文件不支持循环。

-- 滑板车

谢谢滑板车。 我看到了他的回答。 我仍然对 MCODE 有疑问。 我通过阅读这篇论文 "Cytoscape Automation: empowering workflow-based network analysis" 弄明白了。 我想把脚本放在这里,以防有人有疑问。 从 python 您需要导入

import requests, json
import numpy

REST_ENDPOINT = 'http://localhost:1234'

然后假设我们要使用亲和力传播聚类算法,那么你可以去帮助->自动化->CyRest命令API。在这里您可以找到应用程序及其所有参数。您一开始从 cytoscape 加载输入网络。

counter = 0
ap_clusters = dict()
for i in numpy.arange(-1.0, 1.1, 0.1):
    message_body = {
        "preference": str(round(i,1))
        }
    response = requests.post(REST_ENDPOINT + '/v1/commands/cluster/ap', data = 
    json.dumps(message_body), headers = {'Content-Type': 'application/json'})
    response_data = response.json()['data']
    ap_clusters[counter] = response_data['clusters']
    counter += 1

以上是python多次调用AP聚类的代码。

对于 AP 和 MCL,代码适用于多个参数。但是,当我尝试使用不同的参数集调用 MCODE 时,它停止了连接并关闭了 cytoscape 应用程序。它只能 运行 一组参数。 这是错误: " 引发 ConnectionError(err, request=request) ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))"

这里是mcode算法的代码:

counter = 0
mcode_clusters = dict()
for i in numpy.arange(3,6,1):
    for j in numpy.arange(0.1,0.56,0.05): #----vertex weight percentage
        for h in ["on","off"]:
            for f in ["on","off"]:
                if f=="on":
                    for p in [0,0.1,0.2]: #---fluffing percentage

                        message_body = {
                                "fluff" : f,
                                "fluffNodeDensityCutoff" : str(round(p,1)),
                                "haircut" : h,
                                "maxDepthFromStart" : str(i),
                                "nodeScoreCutoff": str(round(j,1))
                                }
                        response = requests.post(REST_ENDPOINT + '/v1/commands/cluster/mcode', data = json.dumps(message_body), headers = {'Content-Type': 'application/json'})
                        response_data = response.json()['data']
                        mcode_clusters[counter] = response_data['clusters']
                        counter += 1

如果您有任何解决方案,请与我分享,我将不胜感激。

谢谢。 萨拉

关于我的问题,我不得不说:

cytoscape中有两个mcode。一个在 clusterMaker 中,另一个属于 cytoscape。当我尝试调用 mcode 时,我使用了命令“'/v1/commands/cluster/mcode'”,我调用了 clusterMaker 中的那个,但是参数的名称是基于 cytoscape 中的那个。我将命令更改为“'/v1/commands/mcode/cluster'”,现在问题已解决。 非常感谢。 萨拉