import re


def truncate_fastq_to_pair_suffix(fn: str) -> str:
    """
    Turn a XXXBLAFOO_R1.fastq.gz filename into XXXBLAFOO_R1.
    """
    extensions = [
        r"_001\.fastq\.gz$",  # Default Illumina
        r"\.fastq\.gz$",  # ENA/SRA
        r"\.fasta\.gz$",  # occasionally we get FASTA format reads
        r"\.fq\.gz$",  # BGI does this, it seems
        r"\.fastq$",  # Occasionally we need to take uncompressed fastqs
        r"\.fasta$",  # why not
    ]

    # Try removing all of these extensions
    for ext in extensions:
        fn = re.sub(ext, "", fn, 1)

    return fn