while-loopcytoscape.jscytoscape

Call an app in a loop with different parameters in Cytoscape


I'm new in Cytoscape. I want to know how can I run an app (for example MCL clustering algorithm) multiple times with different parameters in Cytoscape. Is there any way to write an script to do that instead of running manually multiple times for different parameters? Thanks!


Solution

  • Thanks Scooter. I saw his answer. Still I have problem with MCODE. I figured it out by reading this paper "Cytoscape Automation: empowering workflow-based network analysis". I want to put the script here in the case that maybe somebody has question. From python you need to import

    import requests, json
    import numpy
    
    REST_ENDPOINT = 'http://localhost:1234'
    

    and then let's say we want to use affinity propagation clustering algorithm, then you can go to help->Automation->CyRest command API. Here you can find the app and all its parameters. You load the input network from cytoscape in the beginning.

    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
    

    above is a code to call AP clustering multiple times from python.

    For AP and MCL the code works for multiple parameters. However when I tried to call MCODE with different set of parameters, it stopped the connection and closed the cytoscape app. It can only run for on set of parameters. This is the error: " raise ConnectionError(err, request=request) ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))"

    here is the code for mcode algorithm:

    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
    

    If you have any solutions I really appreciate it if you could share it with me.

    Thanks. SaRa