from pathlib import Path


def detect_filetype(file):
    """
    Detect FoldX filetype from the filenames
    """
    file = Path(file).stem
    filetype = file.split('_')[0].lower()
    if filetype not in ('interface', 'interaction', 'indiv', 'summary'):
        raise ValueError('Unknown type detected')
    return filetype