|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# MIT License |
| 3 | +# |
| 4 | +# Copyright 2025 Broad Institute |
| 5 | +# |
| 6 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | +# of this software and associated documentation files (the "Software"), to deal |
| 8 | +# in the Software without restriction, including without limitation the rights |
| 9 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | +# copies of the Software, and to permit persons to whom the Software is |
| 11 | +# furnished to do so, subject to the following conditions: |
| 12 | +# |
| 13 | +# The above copyright notice and this permission notice shall be included in all |
| 14 | +# copies or substantial portions of the Software. |
| 15 | +# |
| 16 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | +# SOFTWARE. |
| 23 | +""" |
| 24 | +Simple python tools for interacting with workflows in Terra.bio. |
| 25 | +""" |
| 26 | +import argparse |
| 27 | +import logging |
| 28 | +import sys |
| 29 | +from pathlib import Path |
| 30 | + |
| 31 | +try: |
| 32 | + from . import email_outputs |
| 33 | +except ImportError: |
| 34 | + import email_outputs |
| 35 | + |
| 36 | +# I cannot believe I need to do this to cause logger to write to stderr. |
| 37 | +logging.basicConfig( |
| 38 | + level=logging.INFO, # Set the logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
| 39 | + format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', |
| 40 | + handlers=[logging.StreamHandler()] # StreamHandler writes to sys.stderr by default |
| 41 | +) |
| 42 | +logger = logging.getLogger(Path(__file__).stem) |
| 43 | + |
| 44 | +dctLogLevel = { |
| 45 | + "DEBUG": logging.DEBUG, |
| 46 | + "INFO": logging.INFO, |
| 47 | + "WARNING": logging.WARNING, |
| 48 | + "ERROR": logging.ERROR, |
| 49 | + "CRITICAL": logging.CRITICAL |
| 50 | +} |
| 51 | + |
| 52 | + |
| 53 | +def main(args=None): |
| 54 | + parser = argparse.ArgumentParser(prog="dropseq_terra_utils", description=__doc__) |
| 55 | + parser.add_argument("--log-level", "-l", default="INFO", choices=dctLogLevel.keys(), |
| 56 | + help="Set the logging level. (default: %(default)s)") |
| 57 | + subparsers = parser.add_subparsers( |
| 58 | + title="sub-commands", |
| 59 | + description="valid commands", |
| 60 | + dest="tool") |
| 61 | + email_outputs.add_subparser(subparsers) |
| 62 | + |
| 63 | + if args is None: |
| 64 | + args = sys.argv[1:] |
| 65 | + if len(args) == 0: |
| 66 | + parser.print_help() |
| 67 | + return 1 |
| 68 | + else: |
| 69 | + options = parser.parse_args(args) |
| 70 | + logger.setLevel(dctLogLevel[options.log_level]) |
| 71 | + if options.tool == "email_outputs": |
| 72 | + return email_outputs.main(options) |
| 73 | + else: |
| 74 | + # should be unpossible because parse_args will complain |
| 75 | + raise ValueError(f"Unrecognized tool: {options.tool}") |
| 76 | + |
| 77 | + |
| 78 | +if __name__ == "__main__": |
| 79 | + sys.exit(main()) |
0 commit comments