def preferred_change(data):
    ''' Determines preferred existing id based on curie prefix in the ranking list '''
    ranking = [
        'CHEBI',
        'NCBITaxon',
        'COGPO',
        'CAO',
        'DICOM',
        'UBERON',
        'NLX',
        'NLXANAT',
        'NLXCELL',
        'NLXFUNC',
        'NLXINV',
        'NLXORG',
        'NLXRES',
        'NLXSUB'
        'BIRNLEX',
        'SAO',
        'NDA.CDE',
        'PR',
        'IAO',
        'NIFEXT',
        'OEN',
        'ILX',
    ]
    mock_rank = ranking[::-1]
    score = []
    old_pref_index = None
    for i, d in enumerate(data['existing_ids']):
        if not d.get('preferred'): # db allows None or '' which will cause a problem
            d['preferred'] = 0
        if int(d['preferred']) == 1:
            old_pref_index = i
        if d.get('curie'):
            pref = d['curie'].split(':')[0]
            if pref in mock_rank:
                score.append(mock_rank.index(pref))
            else:
                score.append(-1)
        else:
            score.append(-1)

    new_pref_index = score.index(max(score))
    new_pref_iri = data['existing_ids'][new_pref_index]['iri']
    if new_pref_iri.rsplit('/', 1)[0] == 'http://uri.interlex.org/base':
        if old_pref_index:
            if old_pref_index != new_pref_index:
                return data
    for e in data['existing_ids']:
        e['preferred'] = 0
    data['existing_ids'][new_pref_index]['preferred'] = 1
    return data
def preferred_change ( data ) : ranking = [ 'CHEBI' , 'NCBITaxon' , 'COGPO' , 'CAO' , 'DICOM' , 'UBERON' , 'NLX' , 'NLXANAT' , 'NLXCELL' , 'NLXFUNC' , 'NLXINV' , 'NLXORG' , 'NLXRES' , 'NLXSUB' 'BIRNLEX' , 'SAO' , 'NDA.CDE' , 'PR' , 'IAO' , 'NIFEXT' , 'OEN' , 'ILX' , ] mock_rank = ranking [ : : - 1 ] score = [ ] old_pref_index = None for i , d in enumerate ( data [ 'existing_ids' ] ) : if not d . get ( 'preferred' ) : d [ 'preferred' ] = 0 if int ( d [ 'preferred' ] ) == 1 : old_pref_index = i if d . get ( 'curie' ) : pref = d [ 'curie' ] . split ( ':' ) [ 0 ] if pref in mock_rank : score . append ( mock_rank . index ( pref ) ) else : score . append ( - 1 ) else : score . append ( - 1 ) new_pref_index = score . index ( max ( score ) ) new_pref_iri = data [ 'existing_ids' ] [ new_pref_index ] [ 'iri' ] if new_pref_iri . rsplit ( '/' , 1 ) [ 0 ] == 'http://uri.interlex.org/base' : if old_pref_index : if old_pref_index != new_pref_index : return data for e in data [ 'existing_ids' ] : e [ 'preferred' ] = 0 data [ 'existing_ids' ] [ new_pref_index ] [ 'preferred' ] = 1 return data
Determines preferred existing id based on curie prefix in the ranking list