# Path: abtools/log.py
# def setup_logging(logfile, print_log_location=True, debug=False):
# def get_logger(name=None):
# def add_stream_handler(logger):
# def make_dir(d):
# 
# Path: abtools/mongodb.py
# def get_connection(ip='localhost', port=27017, user=None, password=None):
# def get_db(db, ip='localhost', port=27017, user=None, password=None):
# def get_collections(db, collection=None, prefix=None, suffix=None):
# def rename_collection(db, collection, new_name):
# def update(field, value, db, collection, match=None):
# def unset(db, collection, field, match=None):
# def mongoimport(json, database,
#                 ip='localhost', port=27017,
#                 user=None, password=None,
#                 delim='_', delim1=None, delim2=None,
#                 delim_occurance=1, delim1_occurance=1, delim2_occurance=1):
# def index(db, collection, fields, directions=None, desc=False, background=False):
# def remove_padding(db, collection, field='padding'):
# def _get_import_collections(jsons, delim, delim_occurance,
#                             delim1, delim1_occurance,
#                             delim2, delim2_occurance):
# def _print_mongoimport_info(logger):
# def _print_remove_padding():


import os
import sys
import uuid
import time
import shelve
import urllib
import sqlite3
import tempfile
import argparse
import subprocess as sp
import multiprocessing as mp
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
from StringIO import StringIO
from collections import Counter
from pymongo import MongoClient
from abtools import log, mongodb
from abstar.core.germline import get_germlines

from __future__ import print_function









def parse_args():
    parser = argparse.ArgumentParser("Computes and plots basic repertoire information from one or more antibody NGS datasets.")
    parser.add_argument('-o', '--output', dest='output', required=True,
                        help="Output directory for figure and data files. Required.")
    parser.add_argument('-t', '--temp', dest='temp_dir', required=True,
                        help="Directory for temporary files. Required.")
    parser.add_argument('-l', '--log', dest='log',
                        help="Location for the AbStats log file. \
                        If not provided, will be written to <output>/abstats.log.")
    parser.add_argument('-d', '--database', dest='db', required=True,
                        help="Name of the MongoDB database to query. Required.")
    parser.add_argument('-c', '--collection', dest='collection', default=None,
                        help="Name of the MongoDB collection to query. \
                        If not provided, all collections in the given database will be processed iteratively.")
    parser.add_argument('-i', '--ip', dest='ip', default='localhost',
                        help="IP address for the MongoDB server.  Defaults to 'localhost'.")
    parser.add_argument('--port', dest='port', default=27017, type=int,
                        help="Port for the MongoDB server.  Defaults to 27017.")
    parser.add_argument('-u', '--user', dest='user', default=None,

# Path: abtools/log.py
# def setup_logging(logfile, print_log_location=True, debug=False):
# def get_logger(name=None):
# def add_stream_handler(logger):
# def make_dir(d):
# 
# Path: abtools/mongodb.py
# def get_connection(ip='localhost', port=27017, user=None, password=None):
# def get_db(db, ip='localhost', port=27017, user=None, password=None):
# def get_collections(db, collection=None, prefix=None, suffix=None):
# def rename_collection(db, collection, new_name):
# def update(field, value, db, collection, match=None):
# def unset(db, collection, field, match=None):
# def mongoimport(json, database,
#                 ip='localhost', port=27017,
#                 user=None, password=None,
#                 delim='_', delim1=None, delim2=None,
#                 delim_occurance=1, delim1_occurance=1, delim2_occurance=1):
# def index(db, collection, fields, directions=None, desc=False, background=False):
# def remove_padding(db, collection, field='padding'):
# def _get_import_collections(jsons, delim, delim_occurance,
#                             delim1, delim1_occurance,
#                             delim2, delim2_occurance):
# def _print_mongoimport_info(logger):
# def _print_remove_padding():


# Path: abtools/_stats.py
import os
import sys
import uuid
import time
import shelve
import urllib
import sqlite3
import tempfile
import argparse
import subprocess as sp
import multiprocessing as mp
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
from StringIO import StringIO
from collections import Counter
from pymongo import MongoClient
from abtools import log, mongodb
from abstar.core.germline import get_germlines


from __future__ import print_function









def parse_args():
    parser = argparse.ArgumentParser("Computes and plots basic repertoire information from one or more antibody NGS datasets.")
    parser.add_argument('-o', '--output', dest='output', required=True,
                        help="Output directory for figure and data files. Required.")
    parser.add_argument('-t', '--temp', dest='temp_dir', required=True,
                        help="Directory for temporary files. Required.")
    parser.add_argument('-l', '--log', dest='log',
                        help="Location for the AbStats log file. \
                        If not provided, will be written to <output>/abstats.log.")
    parser.add_argument('-d', '--database', dest='db', required=True,
                        help="Name of the MongoDB database to query. Required.")
    parser.add_argument('-c', '--collection', dest='collection', default=None,
                        help="Name of the MongoDB collection to query. \
                        If not provided, all collections in the given database will be processed iteratively.")
    parser.add_argument('-i', '--ip', dest='ip', default='localhost',
                        help="IP address for the MongoDB server.  Defaults to 'localhost'.")
    parser.add_argument('--port', dest='port', default=27017, type=int,
                        help="Port for the MongoDB server.  Defaults to 27017.")
    parser.add_argument('-u', '--user', dest='user', default=None,

                        help="Username for the MongoDB server. Not used if not provided.")