''' Created on Jun 4, 2018 Updated on May 4, 2020 Script example to use with the disgenet automation module. Before run this script make sure that Cytoscape is running. @author: jsauch ''' import json import requests def disgenetRestUrl(netType,host="127.0.0.1",port=1234,version="v7"): """Creates a valid REST url for the REST call to the disGeNET automation module. @param netType A string containing the type of the network to be created. @param host The host of the url, by default 127.0.0.1 (localhost). To change the host do it manually. @param port The listening port, by default 1234. To change the port do it manually. @param version The version of the automation module, by default v7. """ url = "http://"+host+":"+str(port)+"/disgenet/"+version+"/"+netType return url def disgenetRestCall(netType,netParams): """Executes a REST call to the disGeNET automation module in Cytoscape and retrieves the operation result. This function builds the url for the rest call automatically with the default values. @param netType A string containing the type of the network to be created. @param params A list with the params for the network. Check the possible params in the Swagger UI of cytoscape. @return result A list with the results of the operation. @author jsauch """ url = disgenetRestUrl(netType) HEADERS = {'Content-Type': 'application/json'} restCall = requests.post(url,data=json.dumps(netParams),headers=HEADERS) result = restCall.json() return result def printHash(hashToPrint): """Prints all the key-values found in a python dictionary(hash) with a single line for entry and the format key - value. @param hashToPrint hash to be printed. @author jsauch """ for key, value in hashToPrint.items(): print(key+" - "+value) def printOperationResult(operationResult): """Prints the response of the REST call to the DisGeNET automation module. @param hashToPrint hash to be printed. @author jsauch """ message = operationResult["message"] print(message) if 'networkResult' in operationResult: netResult = operationResult["networkResult"] printHash(netResult) elif 'errors' in operationResult: errors = operationResult["errors"] printHash(errors) #Example of params for the gene-disease network. geneDisParams = { "source" : "UNIPROT", "assocType" : "Genetic Variation", "diseaseClass" : "Neoplasms", "diseaseSearch" : "", "geneSearch" : "", "initialScoreValue" : "0.0", "finalScoreValue" : "1.0" } #Example of params for the variant-disase network. variantDisParams = { "source" : "UNIPROT", "assocType" : "Genetic Variation", "diseaseClass" : "Neoplasms", "diseaseSearch" : " ", "geneSearch" : " ", "variantSearch" : " ", "initialScoreValue" : "0.0", "finalScoreValue" : "1.0", "showGenes" : "true" } #Generate the gene-disease network, and show the resuland show the results.ts. printOperationResult(disgenetRestCall("gene-disease-net", geneDisParams)) #Generate the variant-disease network, and show the results. printOperationResult(disgenetRestCall("variant-disease-net", variantDisParams))