Last active
July 2, 2018 11:21
-
-
Save Tabea-K/34ec5759b3db87f73536349e36c2de2e to your computer and use it in GitHub Desktop.
This script is an example for using argparse and logging module in one script!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# File created by Tabea Kischka at Mon Aug 1 2016 | |
import sys | |
import os | |
import argparse | |
import logging | |
script_description = """This is an example for using logging and argparse module. | |
""" | |
# MAIN | |
if __name__ == "__main__": | |
# parse arguments | |
parser = argparse.ArgumentParser(description=script_description) | |
parser.add_argument('infile', | |
help="input vcf file with SnpEff annotation", | |
nargs='?', | |
type=argparse.FileType('r'), | |
default=sys.stdin) | |
parser.add_argument("-d", | |
help="run in debug mode, print lots of information", | |
action="store_const", | |
dest="loglevel", | |
const=logging.DEBUG, | |
default=logging.WARNING) | |
parser.add_argument("-v", | |
help="run in verbose mode, print some more information", | |
action="store_const", | |
dest="loglevel", | |
const=logging.INFO, | |
default=logging.WARNING) | |
args = parser.parse_args() | |
# set up logging module | |
logging.basicConfig(format='[%(asctime)s - %(levelname)s] %(message)s', | |
datefmt='%Y-%m-%d %H:%M:%S', | |
level=args.loglevel) | |
logger = logging.getLogger(__name__) | |
logger.debug("logging set up!") | |
logger.debug("All arguments: %s" % args) | |
logger.info("Script starts!") | |
convert_vcf(args.infile) | |
def convert_vcf(infile): | |
""" | |
Runs the conversion | |
""" | |
logger.debug("Will use file %s" % infile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment