-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
99 lines (80 loc) · 2.94 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import flask
from flask import request, jsonify, current_app
import aws_controller
app = flask.Flask(__name__)
app.config["DEBUG"] = True
@app.route('/', methods=['GET'])
def home():
return current_app.send_static_file('homepage.html')
# V2 - Route to return information about all or one codon
@app.route('/codons', methods=['GET'])
def get_codons():
if 'seq' in request.args:
seq = request.args['seq'].upper()
return jsonify(aws_controller.codons(seq))
return jsonify(aws_controller.get_items())
# V2 - Route to return codons by essential or food
@app.route('/search', methods=['GET'])
def search_codons():
essential = ''
food = ''
# Read in and format params
if 'essential' in request.args:
essential = request.args['essential']
if (essential == 'essential' or essential == 'nonessential'):
essential = essential.capitalize()
elif essential == 'condessential':
essential = 'Conditionally Essential'
else:
return "Error. Invalid essential paramater. Valid values = \"essential\", \"nonessential\" or \"condessential\".", 400
if 'food' in request.args:
food = request.args['food']
food = food.capitalize()
return jsonify(aws_controller.search(essential, food))
# V2 - Route to return translated mRNA
@app.route('/translate', methods=["GET"])
def api_v2translate():
# Read in mRNA sequence
try:
mRNA = request.args['mRNA'].upper()
if any(c not in 'UAGC' for c in mRNA):
return "Error: mRNA strand must only contain U, A, G or C."
except KeyError:
return "Error: No mRNA sequence provided. Please specify an mRNA sequence.", 400
return jsonify(aws_controller.translate(mRNA))
@app.route('/food', methods=["POST"])
def api_v2food():
# Read in food
data = request.get_json()
try:
codon = data['aminoAcid']
food = data['food']
except KeyError:
return "Missing Body Parameter. 'aminoAcid' and 'food' paramters must be included in request body.", 400
response = aws_controller.addFood(codon.upper(), food.capitalize())
return response
# V2 - A transcription
@app.route('/transcribe', methods=["GET"])
def api_v2transcribe():
# Read in DNA sequence
try:
dna = request.args['dna'].upper()
except KeyError:
return "Error: No DNA sequence provided. Please specify a DNA sequence.", 400
# Create string to hold mRNA sequence
mRNA = ""
# Iterate through DNA strand to transcribe to mRNA
for nucleotide in dna:
if nucleotide == 'A':
mRNA += 'U'
elif nucleotide == 'T':
mRNA += 'A'
elif nucleotide == 'G':
mRNA += 'C'
elif nucleotide == 'C':
mRNA += 'G'
else:
return "Error. DNA sequence can only consist of 'A', 'T', 'C' and 'G'.", 400
return jsonify(mRNA)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)