# Path: riboSeed/shared_methods.py
# def set_up_logging(verbosity, outfile, name):
#     """
#     Set up logging a la pyani, with
#     a little help from:
#     https://aykutakin.wordpress.com/2013/08/06/
#         logging-to-console-and-file-in-python/
#     requires logging, os, sys, time
#     and some coloring
#     logs debug level to file, and [verbosity] level to stderr
#     return a logger object
#     """
#     logger = logging.getLogger('root')
#     if (verbosity * 10) not in range(10, 60, 10):
#         raise ValueError('Invalid log level: %s' % verbosity)
#     # logging.basicConfig(level=logging.DEBUG)
#     logger.setLevel(logging.DEBUG)
#     logging.addLevelName(logging.DEBUG, "DBUG")
#     # create console handler and set level to given verbosity
#     console_err = logging.StreamHandler(sys.stderr)
#     console_err.setLevel(level=(verbosity * 10))
#     # console_err_format = logging.Formatter(
#     #     str("%(asctime)s " + name + " %(levelname).4s " +"%(message)s "),
#     #     "%H:%M:%S")
#     console_err_format = logging.Formatter(
#         str("%(asctime)s " + "%(levelname).4s" +" %(message)s"),
#         "%H:%M:%S")
#     console_err.setFormatter(console_err_format)
#     # set some pretty colors, shorten names of loggers to keep lines aligned
#     # sadly, this doesn't jive with log files (casue they cant display the col
#     # logging.addLevelName(logging.DEBUG, "\u001b[30m%s\033[1;0m" % "..")
#     # logging.addLevelName(logging.INFO,  "\u001b[32m%s\033[1;0m" % "--")
#     # logging.addLevelName(logging.WARNING, "\u001b[33m%s\033[1;0m" % "!!")
#     # logging.addLevelName(logging.ERROR, "\u001b[31m%s\033[1;0m" % "xx")
#     # logging.addLevelName(logging.CRITICAL, "\u001b[31m%s\033[1;0m" % "XX")
#     logger.addHandler(console_err)
#     # create debug file handler and set level to debug
#     try:
#         logfile_handler = logging.FileHandler(outfile, "w")
#         logfile_handler.setLevel(logging.DEBUG)
#         logfile_handler_formatter = \
#             logging.Formatter("%(asctime)s - %(levelname).4s - %(message)s")
#         logfile_handler.setFormatter(logfile_handler_formatter)
#         logger.addHandler(logfile_handler)
#     except Exception as e:
#         logger.error(e)
#         logger.error("Could not open %s for logging", outfile)
#         sys.exit(1)
#     logger.debug("Initializing logger")
#     logger.debug("logging at level %s", verbosity)
#     return logger
# 
# def combine_contigs(contigs_dir, pattern="*",
#                     contigs_name="riboSeedContigs_aggregated",
#                     ext=".fasta", verbose=False, logger=None):
#     """changed over to biopython
#     combine all *ext files in dir, return path to concatenated file
#     requires Bio.SeqIO, glob, os
#     """
#     # make sure it ends in a path sep
#     if contigs_dir[-1] != os.path.sep:
#         contigs_dir = str(contigs_dir + os.path.sep)
#     output = os.path.join(contigs_dir, str(contigs_name + ext))
#     fastas = glob.glob(str(contigs_dir + pattern + ext))
#     fastas.sort()
#     if verbose:
#         print(str("combining the following files matching pattern " +
#                   "{0}:{1}".format(pattern, " ".join(fastas))))
#     if logger:
#         logger.debug(str("combining the following files matching pattern " +
#                          "{0}:{1}".format(pattern, " ".join(fastas))))
#     if len(fastas) == 0:
#         if logger:
#             logger.error("No matching files to combine found" +
#                          " in {0}!".format(contigs_dir))
#         sys.exit(1)
#     with open(output, 'w') as w_file:
#         for filen in fastas:
#             with open(filen, 'r') as o_file:
#                 seq_records = SeqIO.parse(o_file, 'fasta')
#                 SeqIO.write(seq_records, w_file, 'fasta')
# 
#     return output


import os
import sys
import subprocess
import argparse
import multiprocessing
import glob
import pandas as pd
from Bio import SeqIO
from Bio.Blast.Applications import NcbiblastnCommandline
from .shared_methods import set_up_logging, combine_contigs
                contigs_name="combinedSnags",
                logger=logger)
            commands, paths_to_outputs, paths_to_recip_outputs = \
                make_nuc_nuc_recip_blast_cmds(
                    query_list=ref_snags,
                    subject_file=combined_full_snags,
                    output=full_blast_results,
                    logger=logger)
        else:
            commands = []

        contig_snags = sorted(glob.glob(
            os.path.join(snagdir2, "") +
            "*_riboSnag.fasta"))
        contig_snags_flanking = sorted(glob.glob(
            os.path.join(snagdir2, "flanking_regions_output", "") +
            "*_riboSnag_flanking_regions.fasta"))
        logger.debug(contig_snags)
        logger.debug(contig_snags_flanking)
        # combine the assembly contigs
        if len(contig_snags) == 0:
            report_list.append("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\n".format(
                os.path.abspath(os.path.expanduser(args.indir)),  # 0
                os.path.basename(fasta),  # 1
                len(ref_snags),  # 2
                0,  # 3
                0,  # 4
                0  # 5
            ))
            continue

# Path: riboSeed/shared_methods.py
# def set_up_logging(verbosity, outfile, name):
#     """
#     Set up logging a la pyani, with
#     a little help from:
#     https://aykutakin.wordpress.com/2013/08/06/
#         logging-to-console-and-file-in-python/
#     requires logging, os, sys, time
#     and some coloring
#     logs debug level to file, and [verbosity] level to stderr
#     return a logger object
#     """
#     logger = logging.getLogger('root')
#     if (verbosity * 10) not in range(10, 60, 10):
#         raise ValueError('Invalid log level: %s' % verbosity)
#     # logging.basicConfig(level=logging.DEBUG)
#     logger.setLevel(logging.DEBUG)
#     logging.addLevelName(logging.DEBUG, "DBUG")
#     # create console handler and set level to given verbosity
#     console_err = logging.StreamHandler(sys.stderr)
#     console_err.setLevel(level=(verbosity * 10))
#     # console_err_format = logging.Formatter(
#     #     str("%(asctime)s " + name + " %(levelname).4s " +"%(message)s "),
#     #     "%H:%M:%S")
#     console_err_format = logging.Formatter(
#         str("%(asctime)s " + "%(levelname).4s" +" %(message)s"),
#         "%H:%M:%S")
#     console_err.setFormatter(console_err_format)
#     # set some pretty colors, shorten names of loggers to keep lines aligned
#     # sadly, this doesn't jive with log files (casue they cant display the col
#     # logging.addLevelName(logging.DEBUG, "\u001b[30m%s\033[1;0m" % "..")
#     # logging.addLevelName(logging.INFO,  "\u001b[32m%s\033[1;0m" % "--")
#     # logging.addLevelName(logging.WARNING, "\u001b[33m%s\033[1;0m" % "!!")
#     # logging.addLevelName(logging.ERROR, "\u001b[31m%s\033[1;0m" % "xx")
#     # logging.addLevelName(logging.CRITICAL, "\u001b[31m%s\033[1;0m" % "XX")
#     logger.addHandler(console_err)
#     # create debug file handler and set level to debug
#     try:
#         logfile_handler = logging.FileHandler(outfile, "w")
#         logfile_handler.setLevel(logging.DEBUG)
#         logfile_handler_formatter = \
#             logging.Formatter("%(asctime)s - %(levelname).4s - %(message)s")
#         logfile_handler.setFormatter(logfile_handler_formatter)
#         logger.addHandler(logfile_handler)
#     except Exception as e:
#         logger.error(e)
#         logger.error("Could not open %s for logging", outfile)
#         sys.exit(1)
#     logger.debug("Initializing logger")
#     logger.debug("logging at level %s", verbosity)
#     return logger
# 
# def combine_contigs(contigs_dir, pattern="*",
#                     contigs_name="riboSeedContigs_aggregated",
#                     ext=".fasta", verbose=False, logger=None):
#     """changed over to biopython
#     combine all *ext files in dir, return path to concatenated file
#     requires Bio.SeqIO, glob, os
#     """
#     # make sure it ends in a path sep
#     if contigs_dir[-1] != os.path.sep:
#         contigs_dir = str(contigs_dir + os.path.sep)
#     output = os.path.join(contigs_dir, str(contigs_name + ext))
#     fastas = glob.glob(str(contigs_dir + pattern + ext))
#     fastas.sort()
#     if verbose:
#         print(str("combining the following files matching pattern " +
#                   "{0}:{1}".format(pattern, " ".join(fastas))))
#     if logger:
#         logger.debug(str("combining the following files matching pattern " +
#                          "{0}:{1}".format(pattern, " ".join(fastas))))
#     if len(fastas) == 0:
#         if logger:
#             logger.error("No matching files to combine found" +
#                          " in {0}!".format(contigs_dir))
#         sys.exit(1)
#     with open(output, 'w') as w_file:
#         for filen in fastas:
#             with open(filen, 'r') as o_file:
#                 seq_records = SeqIO.parse(o_file, 'fasta')
#                 SeqIO.write(seq_records, w_file, 'fasta')
# 
#     return output


# Path: riboSeed/riboScore.py
import os
import sys
import subprocess
import argparse
import multiprocessing
import glob
import pandas as pd
from Bio import SeqIO
from Bio.Blast.Applications import NcbiblastnCommandline
from .shared_methods import set_up_logging, combine_contigs

                contigs_name="combinedSnags",
                logger=logger)
            commands, paths_to_outputs, paths_to_recip_outputs = \
                make_nuc_nuc_recip_blast_cmds(
                    query_list=ref_snags,
                    subject_file=combined_full_snags,
                    output=full_blast_results,
                    logger=logger)
        else:
            commands = []

        contig_snags = sorted(glob.glob(
            os.path.join(snagdir2, "") +
            "*_riboSnag.fasta"))
        contig_snags_flanking = sorted(glob.glob(
            os.path.join(snagdir2, "flanking_regions_output", "") +
            "*_riboSnag_flanking_regions.fasta"))
        logger.debug(contig_snags)
        logger.debug(contig_snags_flanking)
        # combine the assembly contigs
        if len(contig_snags) == 0:
            report_list.append("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\n".format(
                os.path.abspath(os.path.expanduser(args.indir)),  # 0
                os.path.basename(fasta),  # 1
                len(ref_snags),  # 2
                0,  # 3
                0,  # 4
                0  # 5
            ))
            continue

        combined_flanking_snags = combine_contigs(