# Path: abstar/utils/pandaseq.py
# def pair_files(files, nextseq):
#     pairs = {}
#     for f in files:
#         if nextseq:
#             f_prefix = '_'.join(os.path.basename(f).split('_')[:-2])
#         else:
#             f_prefix = '_'.join(os.path.basename(f).split('_')[:-3])
#         if f_prefix in pairs:
#             pairs[f_prefix].append(f)
#         else:
#             pairs[f_prefix] = [f, ]
#     return pairs


from multiprocessing import cpu_count
from subprocess import Popen, PIPE
from Bio import SeqIO
from .utils.pandaseq import pair_files
from abutils.utils.log import get_logger
from abutils.utils.pipeline import list_files, make_dir
import os
import sys

        paired_reads (bool): If ``True``, reads will be processed as paired reads. If ``False``,
            each read will be processed separately. It is not advisable to process paired
            reads with ``paired_reads`` set to ``False`` because if paired read files are
            processed separately and one read passes filters while the paired read doesn't,
            this may cause problems with downstream processes (like read merging).

        allow_5prime_trimming (bool): If ``True``, quality trimming will be performed
            on the 5' end of the reads as well as the 3' end. Default is ``False``.


    Returns:

        str: Path to the output directory
    '''
    if input_directory is None and any([file_pairs is None, output_directory is None]):
        err = '\nERROR: Either an input_directory must be provided or '
        err += 'both file_pairs and an output_directory must be provided.\n'
        print(err)
        sys.exit(1)
    if file_pairs:
        files = file_pairs
    else:
        input_directory = os.path.normpath(input_directory)
        if output_directory is None:
            oparent = os.path.dirname(input_directory)
            output_directory = os.path.join(oparent, 'quality_trimmed')
        make_dir(output_directory)
        if paired_reads:
            files = list_files(input_directory)

# Path: abstar/utils/pandaseq.py
# def pair_files(files, nextseq):
#     pairs = {}
#     for f in files:
#         if nextseq:
#             f_prefix = '_'.join(os.path.basename(f).split('_')[:-2])
#         else:
#             f_prefix = '_'.join(os.path.basename(f).split('_')[:-3])
#         if f_prefix in pairs:
#             pairs[f_prefix].append(f)
#         else:
#             pairs[f_prefix] = [f, ]
#     return pairs


# Path: abstar/preprocess.py
from multiprocessing import cpu_count
from subprocess import Popen, PIPE
from Bio import SeqIO
from .utils.pandaseq import pair_files
from abutils.utils.log import get_logger
from abutils.utils.pipeline import list_files, make_dir
import os
import sys


        paired_reads (bool): If ``True``, reads will be processed as paired reads. If ``False``,
            each read will be processed separately. It is not advisable to process paired
            reads with ``paired_reads`` set to ``False`` because if paired read files are
            processed separately and one read passes filters while the paired read doesn't,
            this may cause problems with downstream processes (like read merging).

        allow_5prime_trimming (bool): If ``True``, quality trimming will be performed
            on the 5' end of the reads as well as the 3' end. Default is ``False``.


    Returns:

        str: Path to the output directory
    '''
    if input_directory is None and any([file_pairs is None, output_directory is None]):
        err = '\nERROR: Either an input_directory must be provided or '
        err += 'both file_pairs and an output_directory must be provided.\n'
        print(err)
        sys.exit(1)
    if file_pairs:
        files = file_pairs
    else:
        input_directory = os.path.normpath(input_directory)
        if output_directory is None:
            oparent = os.path.dirname(input_directory)
            output_directory = os.path.join(oparent, 'quality_trimmed')
        make_dir(output_directory)
        if paired_reads:
            files = list_files(input_directory)

            file_pairs = pair_files(files, nextseq)