import tarfile


def list_cohorts_in_tar(tar_fname):
    """ Returns a multiline string formatted list of cohorts contained in tar file """
    cohorts = []
    with tarfile.open(tar_fname, 'r:gz') as tar:
        for t in tar:
            haystack = t.name.lower()
            if haystack.endswith(".aa_mutations.txt"):
                cohorts.append("\t" + haystack.split("/")[1].split('.')[0])
    return "\n".join(cohorts)