-
Notifications
You must be signed in to change notification settings - Fork 26
/
grapetree.py
84 lines (71 loc) · 2.83 KB
/
grapetree.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
#!/usr/bin/env python
# Copyright Zhemin Zhou, Martin Sergeant, Nabil-Fareed Alikhan & Mark Achtman (2017)
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but without
# any warranty; without even the implied warranty of merchantability or fitness
# for a particular purpose. See the GNU General Public License for more details
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
"""
Web interface of GrapTree, which is a program for phylogenetic analysis.
GrapeTree is an integral part of EnteroBase and we advise that you use GrapeTree
through EnteroBase for the best results. However, many people have asked for a
stand-alone GrapeTree version that they could use offline or integrate into the
other applications.
The stand-alone version emulates the EnteroBase version through a lightweight
webserver running on your local computer. You will be interacting with the
program as you would in EnteroBase; through a web browser.
"""
from __future__ import print_function, absolute_import
try:
from .module import app
from .module.MSTrees import backend, add_args
except :
from module import app
from module.MSTrees import backend, add_args
import threading
import webbrowser
import traceback
import argparse
import os, sys, shutil
import multiprocessing
__licence__ = 'GPLv3'
__author__ = 'EnteroBase development team'
__author_email__ = '[email protected]'
epi = "Licence: " + __licence__ + " by " + __author__ + \
" <" + __author_email__ + ">"
def open_browser(PORT):
"""Start a browser after waiting for half a second."""
def _open_browser():
webbrowser.open('http://localhost:%s' % PORT)
thread = threading.Timer(0.5, _open_browser)
thread.start()
def main() :
if len(sys.argv) > 1 :
sys.stdout.write(backend(**add_args()))
else :
try:
desc = __doc__.split('\n\n')[1].strip()
parser = argparse.ArgumentParser(description=desc, epilog=epi)
args = parser.parse_args()
open_browser(app.config.get('PORT'))
app.run(port=app.config.get('PORT'))
sys.exit(0)
except KeyboardInterrupt as e: # Ctrl-C
raise e
except SystemExit as e: # sys.exit()
raise e
else :
sys.stdout.write( 'ERROR, UNEXPECTED EXCEPTION' )
traceback.print_exc()
os._exit(1)
if __name__ == "__main__":
#from module import views
#views.sendToMicroReact(debug='debug')
multiprocessing.freeze_support()
main()