from pathlib import Path


def field_name_from_path(path):
    """Extract field name from file path."""
    parts = Path(path).stem.split('.')
    field_name = parts[-1]
    if len(parts) > 1:
        if parts[-1] in ('bam', 'sam', 'cram'):
            field_name = parts[-2]
    return field_name