from warnings import warn


def find_sample_id(file_name: str,
                   pattern: str) -> str:
    """Gets the sample id for the given file.
    :param file_name: File name to get sample id from.
    :param pattern: Glob pattern which matches the file_name, where wildcards match to the sample id.
      It is currently assumed that there is a single instance of the sample id in the file_name, and
      therefore a single wildcard in pattern.
    :example: find_sample_id('3H.align.o', '*.align.o') --> '3H'
    """
    n_id_instances = pattern.count('*')
    if n_id_instances == 0:
        raise ValueError('Glob pattern must have a wildcard to specify location of sample ID.')
    elif n_id_instances > 1:
        warn('Multiple wildcards in glob pattern; may cause unexpected behavior')

    sample_id = file_name
    for s in pattern.split('*'):
        sample_id = sample_id.replace(s, '', 1)
    return sample_id