New Submit Agent Sample Services

Sample: Access Raw Service API created with Flask


In [1]:
# Test raw API

BASE = "http://localhost:3333/"

import requests
import json

def jprint(data):
    print(json.dumps(data, indent=4))

# Change this to  your Docker container's IP
HEADERS = {'Content-Type': 'application/json'}


# Click the link below to see the service list...
print(BASE)

query1 = {
    "ids": ["B7ZA85", "P12345"],
    "from": "ACC", # From Uniprot ACC
    "to": 'GENENAME' # To human readable gene symbol
}

query2 = {
    "ids": ["kras", "hras"], # Gene names as input
    "from": "GENENAME",
    "to": 'ACC' # To Uniprot ID
}

res1 = requests.post(BASE + 'idmapping', data=json.dumps(query1), headers=HEADERS)
res2 = requests.post(BASE + 'idmapping', data=json.dumps(query2), headers=HEADERS)

# display result
jprint(res1.json())
#jprint(res2.json())


http://localhost:3333/
{
    "P12345": [
        "GOT2"
    ],
    "B7ZA85": [
        "BRCA1"
    ]
}

Sample 2: Use Agent


In [2]:
# Use Agent instead of raw API
SERVICE_NAME = "id-mapping-service"
PROXY = "http://localhost:8080/" + SERVICE_NAME + "/v1"

# Use GET method to check service is actually working...
res0 = requests.get(PROXY + "/idmapping", headers=HEADERS)
jprint(res0.json())


{
    "serviceName": "uniprot-id-mapper",
    "description": "Simple ID mapper using Uniprot API."
}

In [3]:
res1 = requests.post(PROXY + "/idmapping", data=json.dumps(query1), headers=HEADERS)
# res1 = requests.post(PROXY + "/idmapping", data=json.dumps(query2), headers=HEADERS)

# Print result
jprint(res1.json())


{
    "P12345": [
        "GOT2"
    ],
    "B7ZA85": [
        "BRCA1"
    ]
}