import pathlib


def get_accession_directory(meta_dir, accession):
    """
    Given an NCBI SRA accession number, generate a directory path for it.

    This function breaks each accession into 3-character string and
    creates a directory heirarchy based on the sequence of those sets of
    characters. If the directory does not exist it will be created.

    :param meta_dir:  The base directory where metadata files will be saved.
    :param accession: The NCBI SRA accession ID (experiment, run, sample, etc.)
    """
    dir = meta_dir + '/SRA_META/' + '/'.join([accession[i:i+3] for i in range(0, len(accession), 3)])
    pathlib.Path(dir).mkdir(parents=True, exist_ok=True)
    return dir