-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMasterApp.py
More file actions
executable file
·103 lines (81 loc) · 3.11 KB
/
MasterApp.py
File metadata and controls
executable file
·103 lines (81 loc) · 3.11 KB
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
100
101
102
103
#!/usr/bin/env python
"""
Flask App for MasterServer
see README.md for instructions on how to get this running
author: Tim Tregubov, 12/2014
"""
from flask import Flask, jsonify, request, render_template
from flask import redirect, url_for, send_from_directory
from flask import Response
import json
import time
from MasterSearch import *
import base64
import re
import shlex
import Util
# set up the flask app
app = Flask(__name__)
app.debug = True
app.config.from_object('Settings.Default')
masterSearch = MasterSearch(app)
import Checks
Checks.app = app
# routes #
@app.after_request
def after(response):
return response
# default web route just returns an intro page
@app.route("/", methods=['GET', 'OPTIONS'])
def hello():
return render_template('index.html')
# api route for submitting a search
@app.route("/api/search", methods=['POST', 'OPTIONS'])
def search():
# start processing the query and give us some progress
handle, error = masterSearch.process(request)
if error:
return jsonify({'error': error}), 201
return Response(masterSearch.progress(), mimetype='application/json')
# url to fetch results
@app.route("/api/search/<filename>", methods=['GET'])
def processed_file(filename):
return send_from_directory(app.config['PROCESSING_PATH'],
filename+".tar.gz")
@app.route("/api/logo", methods=['POST', 'OPTIONS'])
def logo_gen():
# check args
(is_allowed, not_allowed_list) = Checks.allowed_args(request.form)
if not is_allowed:
return jsonify({'error': 'bad parameters: ' + ', '.join(not_allowed_list)})
sanitized = Checks.sanitize_args(request.form)
search_id = str(sanitized['query'])
flag = int(sanitized['flag'])
ext = str(sanitized['ext'])
tempdir = os.path.join(app.config['PROCESSING_PATH'], search_id)
if ext == "gif":
image_filepath = os.path.join(tempdir, 'logo.png')
else:
image_filepath = os.path.join(tempdir, 'logo.' + ext)
print image_filepath
seq_filepath = os.path.join(tempdir, 'seq')
if flag == 1:
arg_string = "perl -w /home/grigoryanlab/library/MaDCaT/scripts/seqAnal.pl -s " + str(seq_filepath) + " -c 999 -o " + str(image_filepath) + " -t -1"
elif flag == 2:
arg_string = "perl -w /home/grigoryanlab/library/MaDCaT/scripts/seqAnal.pl -s " + str(seq_filepath) + " -c 999 -o " + str(image_filepath) + " -t -1 -F"
args = shlex.split(arg_string)
subprocess.call(args, stdout=subprocess.PIPE)
if ext == "gif":
gif_filepath = os.path.join(tempdir, 'logo.gif')
convert_string = "convert " + image_filepath + " " + gif_filepath
args2 = shlex.split(convert_string)
subprocess.call(args2)
str_file = str(open(gif_filepath).read())
else:
str_file = str(open(image_filepath).read())
encoded_file = base64.standard_b64encode(str_file)
return Response(json.dumps({'results' : "yes",
'logo' : encoded_file,
'message' : 'will be available for 24 hours'}), mimetype='application/json')
if __name__ == "__main__":
app.run(debug=True, threaded=True)