def _scorematrix2rankedlist_greedy(M, nPairs, doKeepZeros=False):
''' Return the nPairs highest-ranked pairs in score matrix M
Args
-------
M : score matrix, K x K
should have only entries kA,kB where kA <= kB
Returns
--------
aList : list of integer ids for rows of M
bList : list of integer ids for cols of M
Example
---------
_scorematrix2rankedlist( [0 2 3], [0 0 1], [0 0 0], 3)
>> [ (0,2), (0,1), (1,2)]
'''
M = M.copy()
M[np.tril_indices(M.shape[0])] = - np.inf
Mflat = M.flatten()
sortIDs = np.argsort(-1 * Mflat)
# Remove any entries that are -Inf
sortIDs = sortIDs[Mflat[sortIDs] != -np.inf]
if not doKeepZeros:
# Remove any entries that are zero
sortIDs = sortIDs[Mflat[sortIDs] != 0]
bestrs, bestcs = np.unravel_index(sortIDs, M.shape)
return bestrs[:nPairs].tolist(), bestcs[:nPairs].tolist()
评论列表
文章目录