From 4c44b00cfb574b37733b0aa14eaf29c68e8a9b69 Mon Sep 17 00:00:00 2001 From: Alex Rubinsteyn <alex.rubinsteyn@gmail.com> Date: Mon, 13 Jul 2015 15:18:17 -0400 Subject: [PATCH] add get URL for alleles --- mhcflurry/class1.py | 13 +++++++++++++ .../class1_allele_specific_hyperparameters.py | 2 +- scripts/mhcflurry-class1-web-server.py | 17 +++++++++++++---- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/mhcflurry/class1.py b/mhcflurry/class1.py index f90e79ec..aa099d62 100644 --- a/mhcflurry/class1.py +++ b/mhcflurry/class1.py @@ -1,5 +1,7 @@ import pandas as pd +import os +from .paths import CLASS1_MODEL_DIRECTORY from .mhc1_binding_predictor import Mhc1BindingPredictor def predict(alleles, peptides): @@ -9,3 +11,14 @@ def predict(alleles, peptides): df = model.predict_peptides(peptides) allele_dataframes.append(df) return pd.concat(allele_dataframes) + +def supported_alleles(): + alleles = [] + for filename in os.listdir(CLASS1_MODEL_DIRECTORY): + allele = filename.replace(".hdf", "") + if len(allele) < 5: + # skipping serotype names like A2 or B7 + continue + allele = "HLA-%s*%s:%s" % (allele[0], allele[1:3], allele[3:]) + alleles.append(allele) + return alleles diff --git a/mhcflurry/class1_allele_specific_hyperparameters.py b/mhcflurry/class1_allele_specific_hyperparameters.py index 68368f8c..aaf1ae3a 100644 --- a/mhcflurry/class1_allele_specific_hyperparameters.py +++ b/mhcflurry/class1_allele_specific_hyperparameters.py @@ -13,7 +13,7 @@ # limitations under the License. N_PRETRAIN_EPOCHS = 10 -N_EPOCHS = 100 +N_EPOCHS = 125 ACTIVATION = "relu" INITIALIZATION_METHOD = "lecun_uniform" EMBEDDING_DIM = 64 diff --git a/scripts/mhcflurry-class1-web-server.py b/scripts/mhcflurry-class1-web-server.py index 3806eed5..0f6dca94 100755 --- a/scripts/mhcflurry-class1-web-server.py +++ b/scripts/mhcflurry-class1-web-server.py @@ -21,13 +21,13 @@ from __future__ import ( ) import argparse -from bottle import post, request, run +from bottle import post, request, run, get from mhcflurry.common import ( split_uppercase_sequences, split_allele_names, ) -from mhcflurry.class1 import predict +from mhcflurry.class1 import predict, supported_alleles parser = argparse.ArgumentParser() @@ -47,8 +47,17 @@ def get_binding_value(): return "ERROR: no allele given" alleles_list = split_allele_names(alleles_string) result_df = predict(alleles=alleles_list, peptides=peptides_list) - return result_df.to_csv(sep="\t", index=False) + return result_df.to_csv(sep="\t", index=False, float_format="%0.4f") + +@get('/alleles') +def get_supported_alleles(): + peptide_lengths = "8,9,10,11,12" + strings = [ + "%s\t%s" % (allele, peptide_lengths) + for allele in supported_alleles() + ] + return "\n".join(strings) if __name__ == "__main__": args = parser.parse_args() - run(host=args.host, port=args.port, debug=args.debug) \ No newline at end of file + run(host=args.host, port=args.port, debug=args.debug) -- GitLab