# Path: pyani/anib.py
# class PyaniANIbException(PyaniException):
# def get_version(blast_exe: Path = pyani_config.BLASTN_DEFAULT) -> str:
# def fragment_fasta_files(
#     infiles: List[Path], outdirname: Path, fragsize: int
# ) -> Tuple[List, Dict]:
# def get_fraglength_dict(fastafiles: List[Path]) -> Dict:
# def get_fragment_lengths(fastafile: Path) -> Dict:
# def build_db_jobs(infiles: List[Path], blastcmds: BLASTcmds) -> Dict:
# def make_blastcmd_builder(
#     mode: str,
#     outdir: Path,
#     format_exe: Optional[Path] = None,
#     blast_exe: Optional[Path] = None,
#     prefix: str = "ANIBLAST",
# ) -> BLASTcmds:
# def make_job_graph(
#     infiles: List[Path], fragfiles: List[Path], blastcmds: BLASTcmds
# ) -> List[pyani_jobs.Job]:
# def generate_blastdb_commands(
#     filenames: List[Path],
#     outdir: Path,
#     blastdb_exe: Optional[Path] = None,
#     mode: str = "ANIb",
# ) -> List[Tuple[str, Path]]:
# def construct_makeblastdb_cmd(
#     filename: Path, outdir: Path, blastdb_exe: Path = pyani_config.MAKEBLASTDB_DEFAULT
# ) -> Tuple[str, Path]:
# def construct_formatdb_cmd(
#     filename: Path, outdir: Path, blastdb_exe: Path = pyani_config.FORMATDB_DEFAULT
# ) -> Tuple[str, Path]:
# def generate_blastn_commands(
#     filenames: List[Path],
#     outdir: Path,
#     blast_exe: Optional[Path] = None,
#     mode: str = "ANIb",
# ) -> List[str]:
# def construct_blastn_cmdline(
#     fname1: Path,
#     fname2: Path,
#     outdir: Path,
#     blastn_exe: Path = pyani_config.BLASTN_DEFAULT,
# ) -> str:
# def construct_blastall_cmdline(
#     fname1: Path,
#     fname2: Path,
#     outdir: Path,
#     blastall_exe: Path = pyani_config.BLASTALL_DEFAULT,
# ) -> str:
# def process_blast(
#     blast_dir: Path,
#     org_lengths: Dict,
#     fraglengths: Dict,
#     mode: str = "ANIb",
#     logger: Optional[Logger] = None,
# ) -> ANIResults:
# def parse_blast_tab(
#     filename: Path, fraglengths: Dict, mode: str = "ANIb"
# ) -> Tuple[int, int, int]:
# 
# Path: pyani/pyani_files.py
# class PyaniFilesException(PyaniException):
# def get_fasta_files(dirname: Path = Path(".")) -> List[Path]:
# def get_fasta_paths(
#     dirname: Path = Path("."), extlist: Optional[List] = None
# ) -> List[Path]:
# def get_fasta_and_hash_paths(dirname: Path = Path(".")) -> List[Tuple[Path, Path]]:
# def get_input_files(dirname: Path, *ext) -> List[Path]:
# def get_sequence_lengths(fastafilenames: Iterable[Path]) -> Dict[str, int]:
# def read_hash_string(filename: Path) -> Tuple[str, str]:
# def read_fasta_description(filename: Path) -> str:
# def load_classes_labels(path: Path) -> Dict[str, str]:
# def collect_existing_output(dirpath: Path, program: str, args: Namespace) -> List[Path]:


from pathlib import Path
from typing import List, NamedTuple
from pandas.testing import assert_frame_equal
from pyani import anib, pyani_files
import pandas as pd
import pytest  # noqa: F401  # pylint: disable=unused-import
import unittest
def test_blastall_single(path_fna_two, tmp_path):
    """Generate legacy BLASTN command-line."""
    cmd = anib.construct_blastall_cmdline(path_fna_two[0], path_fna_two[1], tmp_path)
    expected = (
        f"blastall -p blastn -o {tmp_path / str(path_fna_two[0].stem + '_vs_' + path_fna_two[1].stem + '.blast_tab')} "
        f"-i {path_fna_two[0]} "
        f"-d {path_fna_two[1]} "
        "-X 150 -q -1 -F F -e 1e-15 -b 1 -v 1 -m 8"
    )
    assert cmd == expected


# Test BLAST+ (blastn) command generation
def test_blastn_dbjobdict(path_fna_all, tmp_path):
    """Generate dictionary of BLASTN+ database jobs."""
    blastcmds = anib.make_blastcmd_builder("ANIb", tmp_path)
    jobdict = anib.build_db_jobs(path_fna_all, blastcmds)
    expected = [
        (
            tmp_path / _.name,
            f"makeblastdb -dbtype nucl -in {_} -title {_.stem} -out {tmp_path / _.name}",
        )
        for _ in path_fna_all
    ]
    assert sorted([(k, v.script) for (k, v) in jobdict.items()]) == sorted(expected)


def test_blastn_graph(path_fna_all, tmp_path, fragment_length):
    """Create jobgraph for BLASTN+ jobs."""
    fragresult = anib.fragment_fasta_files(path_fna_all, tmp_path, fragment_length)

# Path: pyani/anib.py
# class PyaniANIbException(PyaniException):
# def get_version(blast_exe: Path = pyani_config.BLASTN_DEFAULT) -> str:
# def fragment_fasta_files(
#     infiles: List[Path], outdirname: Path, fragsize: int
# ) -> Tuple[List, Dict]:
# def get_fraglength_dict(fastafiles: List[Path]) -> Dict:
# def get_fragment_lengths(fastafile: Path) -> Dict:
# def build_db_jobs(infiles: List[Path], blastcmds: BLASTcmds) -> Dict:
# def make_blastcmd_builder(
#     mode: str,
#     outdir: Path,
#     format_exe: Optional[Path] = None,
#     blast_exe: Optional[Path] = None,
#     prefix: str = "ANIBLAST",
# ) -> BLASTcmds:
# def make_job_graph(
#     infiles: List[Path], fragfiles: List[Path], blastcmds: BLASTcmds
# ) -> List[pyani_jobs.Job]:
# def generate_blastdb_commands(
#     filenames: List[Path],
#     outdir: Path,
#     blastdb_exe: Optional[Path] = None,
#     mode: str = "ANIb",
# ) -> List[Tuple[str, Path]]:
# def construct_makeblastdb_cmd(
#     filename: Path, outdir: Path, blastdb_exe: Path = pyani_config.MAKEBLASTDB_DEFAULT
# ) -> Tuple[str, Path]:
# def construct_formatdb_cmd(
#     filename: Path, outdir: Path, blastdb_exe: Path = pyani_config.FORMATDB_DEFAULT
# ) -> Tuple[str, Path]:
# def generate_blastn_commands(
#     filenames: List[Path],
#     outdir: Path,
#     blast_exe: Optional[Path] = None,
#     mode: str = "ANIb",
# ) -> List[str]:
# def construct_blastn_cmdline(
#     fname1: Path,
#     fname2: Path,
#     outdir: Path,
#     blastn_exe: Path = pyani_config.BLASTN_DEFAULT,
# ) -> str:
# def construct_blastall_cmdline(
#     fname1: Path,
#     fname2: Path,
#     outdir: Path,
#     blastall_exe: Path = pyani_config.BLASTALL_DEFAULT,
# ) -> str:
# def process_blast(
#     blast_dir: Path,
#     org_lengths: Dict,
#     fraglengths: Dict,
#     mode: str = "ANIb",
#     logger: Optional[Logger] = None,
# ) -> ANIResults:
# def parse_blast_tab(
#     filename: Path, fraglengths: Dict, mode: str = "ANIb"
# ) -> Tuple[int, int, int]:
# 
# Path: pyani/pyani_files.py
# class PyaniFilesException(PyaniException):
# def get_fasta_files(dirname: Path = Path(".")) -> List[Path]:
# def get_fasta_paths(
#     dirname: Path = Path("."), extlist: Optional[List] = None
# ) -> List[Path]:
# def get_fasta_and_hash_paths(dirname: Path = Path(".")) -> List[Tuple[Path, Path]]:
# def get_input_files(dirname: Path, *ext) -> List[Path]:
# def get_sequence_lengths(fastafilenames: Iterable[Path]) -> Dict[str, int]:
# def read_hash_string(filename: Path) -> Tuple[str, str]:
# def read_fasta_description(filename: Path) -> str:
# def load_classes_labels(path: Path) -> Dict[str, str]:
# def collect_existing_output(dirpath: Path, program: str, args: Namespace) -> List[Path]:


# Path: tests/test_anib.py
from pathlib import Path
from typing import List, NamedTuple
from pandas.testing import assert_frame_equal
from pyani import anib, pyani_files
import pandas as pd
import pytest  # noqa: F401  # pylint: disable=unused-import
import unittest

def test_blastall_single(path_fna_two, tmp_path):
    """Generate legacy BLASTN command-line."""
    cmd = anib.construct_blastall_cmdline(path_fna_two[0], path_fna_two[1], tmp_path)
    expected = (
        f"blastall -p blastn -o {tmp_path / str(path_fna_two[0].stem + '_vs_' + path_fna_two[1].stem + '.blast_tab')} "
        f"-i {path_fna_two[0]} "
        f"-d {path_fna_two[1]} "
        "-X 150 -q -1 -F F -e 1e-15 -b 1 -v 1 -m 8"
    )
    assert cmd == expected


# Test BLAST+ (blastn) command generation
def test_blastn_dbjobdict(path_fna_all, tmp_path):
    """Generate dictionary of BLASTN+ database jobs."""
    blastcmds = anib.make_blastcmd_builder("ANIb", tmp_path)
    jobdict = anib.build_db_jobs(path_fna_all, blastcmds)
    expected = [
        (
            tmp_path / _.name,
            f"makeblastdb -dbtype nucl -in {_} -title {_.stem} -out {tmp_path / _.name}",
        )
        for _ in path_fna_all
    ]
    assert sorted([(k, v.script) for (k, v) in jobdict.items()]) == sorted(expected)


def test_blastn_graph(path_fna_all, tmp_path, fragment_length):
    """Create jobgraph for BLASTN+ jobs."""
    fragresult = anib.fragment_fasta_files(path_fna_all, tmp_path, fragment_length)

    blastcmds = anib.make_blastcmd_builder("ANIb", tmp_path)