# Path: pyani/pyani_tools.py
# def label_results_matrix(matrix: pd.DataFrame, labels: Dict) -> pd.DataFrame:
#     """Return results matrix dataframe with labels.
# 
#     :param matrix:  results dataframe deriving from Run object
#     :param labels:  dictionary of genome labels
#         labels must be keyed by index/col values from matrix
# 
#     Applies the labels from the dictionary to the dataframe in
#     matrix, and returns the result.
#     """
#     # The dictionary uses string keys!
#     # Create a label function that produces <label>:<genome_id>
#     # when a label is available; and just Genome_id:<genome_id> when no
#     # label exists
#     label = lambda gen_id: f"{labels.get(str(gen_id), 'Genome_id')}:{gen_id}"
#     matrix.columns = [label(_) for _ in matrix.columns]
#     matrix.index = [label(_) for _ in matrix.index]
#     return matrix


from typing import Dict, List, NamedTuple, Tuple
from pyani.pyani_tools import label_results_matrix
import networkx as nx  # type: ignore
import pandas as pd  # type: ignore

# Holds summary information about a graph's cliques
class Cliquesinfo(NamedTuple):

    """Summary of clique structure."""

    n_nodes: int
    n_subgraphs: int
    all_k_complete: bool


# Build an undirected graph from an ANIResults object
def build_graph_from_results(
    results, label_dict: Dict[int, str], cov_min: float = 0, id_min: float = 0
) -> nx.Graph:
    """Return undirected graph representing the passed ANIResults object.

    The passed ANIResults object is converted to an undirected graph where
    nodes on the graph represent genomes, and edges represent pairwise
    comparisons having the minimum coverage and identity indicated.

    :param results:     - Run object from pyani_orm
    :param label_dict:  dictionary of genome labels for result matrices
        the dict is keyed by the index/column values for the results
        matrices
    :param cov_min:     - minimum coverage for an edge
    :param id_min:      - minimum identity for an edge
    """
    # Parse identity and coverage matrices
    mat_identity = label_results_matrix(pd.read_json(results.df_identity), label_dict)

# Path: pyani/pyani_tools.py
# def label_results_matrix(matrix: pd.DataFrame, labels: Dict) -> pd.DataFrame:
#     """Return results matrix dataframe with labels.
# 
#     :param matrix:  results dataframe deriving from Run object
#     :param labels:  dictionary of genome labels
#         labels must be keyed by index/col values from matrix
# 
#     Applies the labels from the dictionary to the dataframe in
#     matrix, and returns the result.
#     """
#     # The dictionary uses string keys!
#     # Create a label function that produces <label>:<genome_id>
#     # when a label is available; and just Genome_id:<genome_id> when no
#     # label exists
#     label = lambda gen_id: f"{labels.get(str(gen_id), 'Genome_id')}:{gen_id}"
#     matrix.columns = [label(_) for _ in matrix.columns]
#     matrix.index = [label(_) for _ in matrix.index]
#     return matrix


# Path: pyani/pyani_classify.py
from typing import Dict, List, NamedTuple, Tuple
from pyani.pyani_tools import label_results_matrix
import networkx as nx  # type: ignore
import pandas as pd  # type: ignore


# Holds summary information about a graph's cliques
class Cliquesinfo(NamedTuple):

    """Summary of clique structure."""

    n_nodes: int
    n_subgraphs: int
    all_k_complete: bool


# Build an undirected graph from an ANIResults object
def build_graph_from_results(
    results, label_dict: Dict[int, str], cov_min: float = 0, id_min: float = 0
) -> nx.Graph:
    """Return undirected graph representing the passed ANIResults object.

    The passed ANIResults object is converted to an undirected graph where
    nodes on the graph represent genomes, and edges represent pairwise
    comparisons having the minimum coverage and identity indicated.

    :param results:     - Run object from pyani_orm
    :param label_dict:  dictionary of genome labels for result matrices
        the dict is keyed by the index/column values for the results
        matrices
    :param cov_min:     - minimum coverage for an edge
    :param id_min:      - minimum identity for an edge
    """
    # Parse identity and coverage matrices
    mat_identity = label_results_matrix(pd.read_json(results.df_identity), label_dict)

    mat_coverage = label_results_matrix(pd.read_json(results.df_coverage), label_dict)