msaexplorer.cli
A script to provide minimal argument parsing for displaying the version or launching the MSAexplorer app. Not needed for usage as a python module.
This module defines functions to parse command-line arguments and either display the version information or start the MSAexplorer application. It primarily serves as an entry point for launching the application or retrieving its version.
1""" 2A script to provide minimal argument parsing for displaying the version or 3launching the MSAexplorer app. Not needed for usage as a python module. 4 5This module defines functions to parse command-line arguments and either display 6the version information or start the MSAexplorer application. It primarily serves 7as an entry point for launching the application or retrieving its version. 8""" 9 10import sys 11import argparse 12from msaexplorer import __version__ 13 14 15def parse_args(sysargs): 16 """ 17 Minimal argument parser for displaying the version or launching the app. 18 """ 19 parser = argparse.ArgumentParser( 20 description='The MSAexplorer app is an interactive visualization tool designed for exploring multiple sequence alignments (MSAs).', 21 usage='''\tmsaexplorer --run --port (optional) --host (optional)''' 22 ) 23 24 parser.add_argument( 25 '--run', 26 action='store_true', 27 help='Start the MSAexplorer app' 28 ) 29 30 parser.add_argument( 31 '--host', 32 type=str, 33 default='127.0.0.1', 34 metavar='ip', 35 help='The address that the app should listen on. Defaults to 127.0.0.1' 36 ) 37 38 parser.add_argument( 39 '--port', 40 type=int, 41 default=8080, 42 metavar='port', 43 help='The port that the app should listen on. Set to 0 to use a random port. Defaults to 8080.' 44 ) 45 46 parser.add_argument( 47 '--version', 48 action='version', 49 version=f'MSAexplorer {__version__}' 50 ) 51 52 if not sysargs: 53 parser.print_help() 54 sys.exit(0) 55 56 return parser.parse_args(sysargs) 57 58 59def main(sysargs=sys.argv[1:]): 60 args = parse_args(sysargs) 61 62 if args.run: 63 try: 64 from shiny import run_app 65 from shiny import App 66 from app_src.shiny_user_interface import shiny_ui 67 from app_src.shiny_server import server 68 from importlib.resources import files 69 except ImportError: 70 sys.exit( 71 "Please install the MSAexplorer front end app via 'pip install msaexplorer[app]' or 'pip install msaexplorer[app-plus]'." 72 ) 73 74 css_path = files("app_src").joinpath("www/css/styles.css") 75 js_path = files("app_src").joinpath("www/js/helper_functions.js") 76 img_path = files("app_src").joinpath("www/img") 77 # same code as in root/app.py 78 run_app( 79 app=App( 80 shiny_ui( 81 css_file=css_path, 82 js_file=js_path 83 ), 84 server, 85 static_assets={'/img': str(img_path)} 86 ), 87 port=args.port, 88 host=args.host 89 ) 90 91 92if __name__ == "__main__": 93 main()
def
parse_args(sysargs):
16def parse_args(sysargs): 17 """ 18 Minimal argument parser for displaying the version or launching the app. 19 """ 20 parser = argparse.ArgumentParser( 21 description='The MSAexplorer app is an interactive visualization tool designed for exploring multiple sequence alignments (MSAs).', 22 usage='''\tmsaexplorer --run --port (optional) --host (optional)''' 23 ) 24 25 parser.add_argument( 26 '--run', 27 action='store_true', 28 help='Start the MSAexplorer app' 29 ) 30 31 parser.add_argument( 32 '--host', 33 type=str, 34 default='127.0.0.1', 35 metavar='ip', 36 help='The address that the app should listen on. Defaults to 127.0.0.1' 37 ) 38 39 parser.add_argument( 40 '--port', 41 type=int, 42 default=8080, 43 metavar='port', 44 help='The port that the app should listen on. Set to 0 to use a random port. Defaults to 8080.' 45 ) 46 47 parser.add_argument( 48 '--version', 49 action='version', 50 version=f'MSAexplorer {__version__}' 51 ) 52 53 if not sysargs: 54 parser.print_help() 55 sys.exit(0) 56 57 return parser.parse_args(sysargs)
Minimal argument parser for displaying the version or launching the app.
def
main(sysargs=['./msaexplorer', '--logo', '../logo.svg', '-o', 'docs/']):
60def main(sysargs=sys.argv[1:]): 61 args = parse_args(sysargs) 62 63 if args.run: 64 try: 65 from shiny import run_app 66 from shiny import App 67 from app_src.shiny_user_interface import shiny_ui 68 from app_src.shiny_server import server 69 from importlib.resources import files 70 except ImportError: 71 sys.exit( 72 "Please install the MSAexplorer front end app via 'pip install msaexplorer[app]' or 'pip install msaexplorer[app-plus]'." 73 ) 74 75 css_path = files("app_src").joinpath("www/css/styles.css") 76 js_path = files("app_src").joinpath("www/js/helper_functions.js") 77 img_path = files("app_src").joinpath("www/img") 78 # same code as in root/app.py 79 run_app( 80 app=App( 81 shiny_ui( 82 css_file=css_path, 83 js_file=js_path 84 ), 85 server, 86 static_assets={'/img': str(img_path)} 87 ), 88 port=args.port, 89 host=args.host 90 )