Skip to content
Snippets Groups Projects
Commit 4c44b00c authored by Alex Rubinsteyn's avatar Alex Rubinsteyn
Browse files

add get URL for alleles

parent 3f44e0b9
No related merge requests found
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
......@@ -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
......
......@@ -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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment