def title_parser(line, method='full'):
    """
    Take an MGF TITLE line and return the spectrum title.

    Depending on the software tool that was used to write the MGF files and the
    search engine, we need to extract different parts of the TITLE field. E.g,
    for MaxQuant, everything up until the first space is required

    line: string, line from MGF file containing 'TITLE='
    method: string, one of the following:
    - 'full': take everything after 'TITLE='
    - 'first_space': take everything between 'TITLE=' and first space.
    - 'first_space_no_charge': take everything between 'TITLE=' and first space,
      but leave out everything after last dot. (required for MaxQuant pipeline).
    - 'scan=': everything between `scan=` and the first space after `scan=`.
    - 'TRFP_MQ': For MGF parsed with ThermoRawFileParser and spec_ids from
      MaxQuant msms.txt.
    """

    if method == 'full':
        title = line[6:].strip()
    elif method == 'first_space':
        title = line[6:].split(' ')[0].strip()
    elif method == 'first_space_no_charge':
        title = '.'.join(line[6:].split(' ')[0].split('.')[:-1]).strip()
    elif method == 'scan=':
        title = line.split('scan=')[1].split(' ')[0].strip()
    elif method == 'TRFP_MQ':
        line = line.strip().split('mzspec=')[1].split(' ')
        filename = line[0].replace('.raw:', '')
        scan = line[3].replace('scan=', '')
        title = '.'.join([filename, scan, scan])
    else:
        raise ValueError("method '{}' is not a valid title parsing method".format(
            method
        ))
    return title