#! /usr/bin/python # Thomas Trolle, July 2014 # trolle@cbs.dtu.dk # Tested on Python 2.7.2 import cgi import subprocess # Define the path to the program that the server should run. # Alternatively, you can define the path in the subprocess.check_output # function below. PROGRAM = '/path/to/your/method' def main(): # Parse the input data sent in the URL. Note that # the following request format is assumed: # '?peptide=&allele=' arguments = cgi.FieldStorage() try: peptide = arguments['peptide'].value allele = arguments['allele'].value except: print "Please supply some data in the following format: '?peptide=PEPTIDE&allele=ALLELE'" return # Check that the input data makes sense. allowed_chars = "ACDEFGHIKLMNPQRSTUVWY," for char in peptide: if char not in allowed_chars: print "Invalid peptide input" return supported_alleles = ["DRB1*01:01", "DRB5*01:01", "DQA1*06:02/DQB1*03:01", "DQA1*01:02/DQB1*03:01"] if allele not in supported_alleles: print "Invalid allele input" return # 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 print result if __name__ == '__main__': main()