General function for interacting with Cytoscape API.
    
    :param namespace: namespace where the request should be executed. eg. "string"
    :param commnand: command to execute. eg. "protein query"
    :param PARAMs: a dictionary with the parameters. Check your swagger normaly running on
    http://localhost:1234/v1/swaggerUI/swagger-ui/index.html?url=http://localhost:1234/v1/commands/swagger.json
    :param host: cytoscape host address, default=cytoscape_host
    :param port: cytoscape port, default=1234
    :param method: type of http call, ie. "POST" or "GET" or "HELP".
    :param verbose: print more information
    
    :returns: For "POST" the data in the content's response. For "GET" None. 
    
    eg.

    cytoscape("string","pubmed query",{"pubmed":"p53 p21","limit":"50"})

def cytoscape(namespace,command="",PARAMS={},host=cytoscape_host,port=cytoscape_port,method="POST",verbose=False):
    """
    General function for interacting with Cytoscape API.
    
    :param namespace: namespace where the request should be executed. eg. "string"
    :param commnand: command to execute. eg. "protein query"
    :param PARAMs: a dictionary with the parameters. Check your swagger normaly running on
    http://localhost:1234/v1/swaggerUI/swagger-ui/index.html?url=http://localhost:1234/v1/commands/swagger.json
    :param host: cytoscape host address, default=cytoscape_host
    :param port: cytoscape port, default=1234
    :param method: type of http call, ie. "POST" or "GET" or "HELP".
    :param verbose: print more information
    
    :returns: For "POST" the data in the content's response. For "GET" None. 
    
    eg.

    cytoscape("string","pubmed query",{"pubmed":"p53 p21","limit":"50"})


    """     

    if (method == "GET") or (method == "G"):
        P=[]
        for p in PARAMS.keys():
            v=str(PARAMS[p])
            v=v.replace(" ","%20")  
            P.append(str(p)+"="+str(PARAMS[p]))
        P="&".join(P)
        URL="http://"+str(host)+":"+str(port)+"/v1/commands/"+str(namespace)+"/"+str(command)+"?"+P
        if verbose:
            print("'"+URL+"'")
            sys.stdout.flush()
        r = requests.get(url = URL)
        CheckResponse(r)
        res=None
    
    elif (method == "POST") or (method == "P"):
        URL="http://"+str(host)+":"+str(port)+"/v1/commands/"+str(namespace)+"/"+str(command)
        r = requests.post(url = URL, json = PARAMS)
        CheckResponse(r)
        res=r.content
        if verbose:
            print(res)
        res=json.loads(res)
        res=res["data"]
        
    elif (method=="HTML") or (method == "H") or (method=="HELP"):
        P=[]
        for p in PARAMS.keys():
            v=str(PARAMS[p])
            v=v.replace(" ","%20")  
            P.append(str(p)+"="+str(PARAMS[p]))
        P="&".join(P)
        URL="http://"+str(host)+":"+str(port)+"/v1/commands/"+str(namespace)+"/"+str(command)+"?"+P
        if verbose:
            print("'"+URL+"'")
            sys.stdout.flush()
        response = urllib2.urlopen(URL)
        #print response
        res = response.read()
        print(res)
        sys.stdout.flush()
    
    return res