def matches_to_marker_results(df):
    """Perfect BLAST matches to marker results dict

    Parse perfect BLAST matches to marker results dict.


    Args:
        df (pandas.DataFrame): DataFrame of perfect BLAST matches

    Returns:
        dict: cgMLST330 marker names to matching allele numbers
    """
    assert isinstance(df, pd.DataFrame)
    from collections import defaultdict
    d = defaultdict(list)
    for idx, row in df.iterrows():
        marker = row['marker']
        d[marker].append(row)

    marker_results = {}
    for k,v in d.items():
        if len(v) > 1:
            logging.debug('Multiple potential cgMLST allele matches (n=%s) found for marker %s. Selecting match on longest contig.', len(v), k)
            df_marker = pd.DataFrame(v)
            df_marker.sort_values('slen', ascending=False, inplace=True)
            for i,r in df_marker.iterrows():
                allele = r['allele_name']
                slen = r['slen']
                logging.debug('Selecting allele %s from contig with length %s', allele, slen)
                seq = r['sseq']
                if '-' in seq:
                    logging.warning('Gaps found in allele. Removing gaps. %s', r)
                    seq = seq.replace('-', '').upper()
                    allele = allele_name(seq)
                marker_results[k] = allele_result_dict(allele, seq, r.to_dict())
                break
        elif len(v) == 1:
            row = v[0]
            seq = row['sseq']
            if '-' in seq:
                logging.warning('Gaps found in allele. Removing gaps. %s', row)
                seq = seq.replace('-', '').upper()
            allele = allele_name(seq)
            marker_results[k] = allele_result_dict(allele, seq, row.to_dict())
        else:
            err_msg = 'Empty list of matches for marker {}'.format(k)
            logging.error(err_msg)
            raise Exception(err_msg)
    return marker_results
Perfect BLAST matches to marker results dict

    Parse perfect BLAST matches to marker results dict.


    Args:
        df (pandas.DataFrame): DataFrame of perfect BLAST matches

    Returns:
        dict: cgMLST330 marker names to matching allele numbers