# Path: pyani/pyani_classify.py
# class Cliquesinfo(NamedTuple):
# def build_graph_from_results(
#     results, label_dict: Dict[int, str], cov_min: float = 0, id_min: float = 0
# ) -> nx.Graph:
# def analyse_cliques(graph: nx.Graph) -> Cliquesinfo:
# def all_components_k_complete(graph: nx.Graph) -> bool:
# def k_complete_component_status(graph: nx.Graph) -> List[bool]:
# def remove_low_weight_edges(
#     graph: nx.Graph, threshold: float, attribute: str = "identity"
# ) -> Tuple[nx.Graph, List]:
# 
# Path: pyani/pyani_orm.py
# class PyaniORMException(PyaniException):
# class LabelTuple(NamedTuple):
# class Label(Base):
# class BlastDB(Base):
# class Genome(Base):
# class Run(Base):
# class Comparison(Base):
#     def __str__(self) -> str:
#     def __repr__(self) -> str:
#     def __str__(self) -> str:
#     def __repr__(self) -> str:
#     def __str__(self) -> str:
#     def __repr__(self) -> str:
#     def __str__(self) -> str:
#     def __repr__(self) -> str:
#     def __str__(self) -> str:
#     def __repr__(self) -> str:
# def create_db(dbpath: Path) -> None:
# def get_session(dbpath: Path) -> Any:
# def get_comparison_dict(session: Any) -> Dict[Tuple, Any]:
# def get_matrix_labels_for_run(session: Any, run_id: int) -> Dict:
# def get_matrix_classes_for_run(session: Any, run_id: int) -> Dict[str, List]:
# def filter_existing_comparisons(
#     session,
#     run,
#     comparisons,
#     program,
#     version,
#     fragsize: Optional[int] = None,
#     maxmatch: Optional[bool] = False,
#     kmersize: Optional[int] = None,
#     minmatch: Optional[float] = None,
# ) -> List:
# def add_run(session, method, cmdline, date, status, name):
# def add_run_genomes(
#     session, run, indir: Path, classpath: Path, labelpath: Path, **kwargs
# ) -> List:
# def update_comparison_matrices(session, run) -> None:
# 
# Path: pyani/pyani_tools.py
# def termcolor(
#     logstr: str, color: Optional[str] = None, bold: Optional[bool] = False
# ) -> str:
#     """Return the passed logstr, wrapped in terminal colouring."""
#     # For terminal colouring
#     termcolors = {
#         "BLACK": 0,
#         "RED": 1,
#         "GREEN": 2,
#         "YELLOW": 3,
#         "BLUE": 4,
#         "MAGENTA": 5,
#         "CYAN": 6,
#         "WHITE": 7,
#     }
#     reset = "\033[0m"
# 
#     # Colour the string
#     if isinstance(color, str) and color.upper() in termcolors:
#         logstr = f"\033[1;{30 + termcolors[color.upper()]}m{logstr}{reset}"
# 
#     # Make the string bold
#     if bold is True:
#         logstr = f"\033[1m{logstr}"
#         if not logstr.endswith(reset):
#             logstr += reset
# 
#     return logstr


import logging
import networkx as nx  # pylint: disable=E0401
import numpy as np
from argparse import Namespace
from typing import Generator, NamedTuple
from tqdm import tqdm
from pyani import pyani_classify, pyani_orm
from pyani.pyani_tools import termcolor







class SubgraphData(NamedTuple):

    """Subgraph clique/classification output."""

    interval: float  # the trimming threshold for this subgraph
    graph: nx.Graph  # the trimmed subgraph
    cliqueinfo: pyani_classify.Cliquesinfo


def subcmd_classify(args: Namespace) -> int:
    """Generate classifications for an analysis.

    :param args:  Namespace, command-line arguments
    """
    logger = logging.getLogger(__name__)

    # Tell the user what's going on
    logger.info(
        termcolor("Generating classification for ANI run: %s", "red"), args.run_id
    )
    logger.info("\tWriting output to: %s", args.outdir)
    logger.info(termcolor("\tCoverage threshold: %s", "cyan"), args.cov_min)
    logger.info(

# Path: pyani/pyani_classify.py
# class Cliquesinfo(NamedTuple):
# def build_graph_from_results(
#     results, label_dict: Dict[int, str], cov_min: float = 0, id_min: float = 0
# ) -> nx.Graph:
# def analyse_cliques(graph: nx.Graph) -> Cliquesinfo:
# def all_components_k_complete(graph: nx.Graph) -> bool:
# def k_complete_component_status(graph: nx.Graph) -> List[bool]:
# def remove_low_weight_edges(
#     graph: nx.Graph, threshold: float, attribute: str = "identity"
# ) -> Tuple[nx.Graph, List]:
# 
# Path: pyani/pyani_orm.py
# class PyaniORMException(PyaniException):
# class LabelTuple(NamedTuple):
# class Label(Base):
# class BlastDB(Base):
# class Genome(Base):
# class Run(Base):
# class Comparison(Base):
#     def __str__(self) -> str:
#     def __repr__(self) -> str:
#     def __str__(self) -> str:
#     def __repr__(self) -> str:
#     def __str__(self) -> str:
#     def __repr__(self) -> str:
#     def __str__(self) -> str:
#     def __repr__(self) -> str:
#     def __str__(self) -> str:
#     def __repr__(self) -> str:
# def create_db(dbpath: Path) -> None:
# def get_session(dbpath: Path) -> Any:
# def get_comparison_dict(session: Any) -> Dict[Tuple, Any]:
# def get_matrix_labels_for_run(session: Any, run_id: int) -> Dict:
# def get_matrix_classes_for_run(session: Any, run_id: int) -> Dict[str, List]:
# def filter_existing_comparisons(
#     session,
#     run,
#     comparisons,
#     program,
#     version,
#     fragsize: Optional[int] = None,
#     maxmatch: Optional[bool] = False,
#     kmersize: Optional[int] = None,
#     minmatch: Optional[float] = None,
# ) -> List:
# def add_run(session, method, cmdline, date, status, name):
# def add_run_genomes(
#     session, run, indir: Path, classpath: Path, labelpath: Path, **kwargs
# ) -> List:
# def update_comparison_matrices(session, run) -> None:
# 
# Path: pyani/pyani_tools.py
# def termcolor(
#     logstr: str, color: Optional[str] = None, bold: Optional[bool] = False
# ) -> str:
#     """Return the passed logstr, wrapped in terminal colouring."""
#     # For terminal colouring
#     termcolors = {
#         "BLACK": 0,
#         "RED": 1,
#         "GREEN": 2,
#         "YELLOW": 3,
#         "BLUE": 4,
#         "MAGENTA": 5,
#         "CYAN": 6,
#         "WHITE": 7,
#     }
#     reset = "\033[0m"
# 
#     # Colour the string
#     if isinstance(color, str) and color.upper() in termcolors:
#         logstr = f"\033[1;{30 + termcolors[color.upper()]}m{logstr}{reset}"
# 
#     # Make the string bold
#     if bold is True:
#         logstr = f"\033[1m{logstr}"
#         if not logstr.endswith(reset):
#             logstr += reset
# 
#     return logstr


# Path: pyani/scripts/subcommands/subcmd_classify.py
import logging
import networkx as nx  # pylint: disable=E0401
import numpy as np
from argparse import Namespace
from typing import Generator, NamedTuple
from tqdm import tqdm
from pyani import pyani_classify, pyani_orm
from pyani.pyani_tools import termcolor








class SubgraphData(NamedTuple):

    """Subgraph clique/classification output."""

    interval: float  # the trimming threshold for this subgraph
    graph: nx.Graph  # the trimmed subgraph
    cliqueinfo: pyani_classify.Cliquesinfo


def subcmd_classify(args: Namespace) -> int:
    """Generate classifications for an analysis.

    :param args:  Namespace, command-line arguments
    """
    logger = logging.getLogger(__name__)

    # Tell the user what's going on
    logger.info(
        termcolor("Generating classification for ANI run: %s", "red"), args.run_id
    )
    logger.info("\tWriting output to: %s", args.outdir)
    logger.info(termcolor("\tCoverage threshold: %s", "cyan"), args.cov_min)
    logger.info(

        termcolor("\tInitial minimum identity threshold: %s", "cyan"), args.id_min