#! /usr/bin/python # Thomas Trolle, July 2014 # trolle@cbs.dtu.dk # Tested on Python 2.7.2 using Bottle 0.12.7 import subprocess from bottle import get, post, run, request # Define the path to the program that the server should run. # Alternatively, you can define the path in the subprocess.check_output # function below. PROG = '/path/to/your/method' @get('/') def no_data(): return "Please supply some data in the following format: --data 'peptide=PEPTIDE&allele=ALLELE'\n" @post('/') def handle_data(): # Parse the input data sent using the POST request method. Note that # the following request format is assumed: # 'peptide=&allele=' peptide = request.forms.get('peptide') allele = request.forms.get('allele') if peptide and allele: # Check that the input data makes sense. allowed_chars = "ACDEFGHIKLMNPQRSTUVWY," for char in peptide: if char not in allowed_chars: return "Invalid peptide input\n" supported_alleles = ["HLA-A*02:01", "HLA-A*24:02", "HLA-B*07:02", "HLA-B*08:01"] if allele not in supported_alleles: return "Invalid allele input\n" # subprocess.check_output() calls your program. The path to your # program and any command line options or arguements should be # passed as a list of strings. Notice that options (such as -mode) # and arguements (such as peptide) that are separated by # whitespace in the shell go in separate list elements. result = subprocess.check_output([PROG, '-mode', 'peptide', allele, peptide]) # Parse the output from your program here if necessary. For the # IEDB benchmark, results for each peptide are expected in the # following format: # Allele\tPeptide\tPrediction\n return result else: return "Please supply some data in the following format: --data 'peptide=PEPTIDE&allele=ALLELE'\n" if __name__ == '__main__': # host defines the IP or URL address of the server. # port defines the port that the server should be accessed through. # Port 80 is standard for HTTP. # The server may be tested locally by running the bottle script and # then querying the server using the following command: # curl 0.0.0.0:8080 --data 'peptide=PEPTIDE&allele=ALLELE' run(host='0.0.0.0', port=8080)