affinity_search/evaluate_cross.py
def analyze_cross_results(results,outname,uniquify):
    '''Compute error metrics from resulst.  
    results is formated: (correct, prediction, receptor, ligand, label, posescore,rmsd)
    This is assumed to be a cross docked input, where receptor filename is
    POCKET/PDB_CH_rec_0.gninatypes
    and the ligand is
    POCKET/PDB1_CH_rec_PDB2_lig_...gninatypes
    
    
    RMSE, Pearson, Spearman, AUC and top-1 percentage are computed.
    
    select can be pose or rmsd.  With pose we use the best pose scoring pose
    of all ligand poses in a pocket.  For rmsd we use the lowest rmsd line for
    that ligand in the pocket.
    
    AUC is calculated before any reduction.
    
    Writes the reduced set to outname.predictions
    '''

    #calc auc before reduction
    labels = np.array([r[4] for r in results])
    posescores = np.array([r[5] for r in results])
    predictions = np.array([r[1] for r in results])
    aucpose = sklearn.metrics.roc_auc_score(labels, posescores)
    aucaff = sklearn.metrics.roc_auc_score(labels, predictions)

    if uniquify == 'rmsd':
        results = reduce_results(results, 6, 'small')
    elif uniquify == 'affinity':
        results = reduce_results(results, 1, 'large')
    elif uniquify == 'pose':
        results = reduce_results(results, 5, 'large')

    predictions = np.array([r[1] for r in results])
    correctaff = np.array([abs(r[0]) for r in results])
    #(correct, prediction, receptor, ligand, label (optional), posescore (optional))    
    #skip cases with no affinity
    predictions = predictions[correctaff != 0]
    correctaff = np.abs(correctaff[correctaff != 0])
    rmse = np.sqrt(sklearn.metrics.mean_squared_error(correctaff, predictions))
    R = scipy.stats.pearsonr(correctaff, predictions)[0]
    S = scipy.stats.spearmanr(correctaff, predictions)[0]
    out = open('%s.predictions'%outname,'w')
    out.write('aff,pred,rec,lig,lab,score,rmsd\n')
    for res in results:
        out.write(','.join(map(str,res))+'\n')
    out.write('#RMSD %f\n'%rmse)
    out.write('#R %f\n'%R)

    labels = np.array([r[4] for r in results])
    top = np.count_nonzero(labels > 0)/float(len(labels))
    return (rmse, R, S, aucpose, aucaff, top)
Compute error metrics from resulst.  
    results is formated: (correct, prediction, receptor, ligand, label, posescore,rmsd)
    This is assumed to be a cross docked input, where receptor filename is
    POCKET/PDB_CH_rec_0.gninatypes
    and the ligand is
    POCKET/PDB1_CH_rec_PDB2_lig_...gninatypes
    
    
    RMSE, Pearson, Spearman, AUC and top-1 percentage are computed.
    
    select can be pose or rmsd.  With pose we use the best pose scoring pose
    of all ligand poses in a pocket.  For rmsd we use the lowest rmsd line for
    that ligand in the pocket.
    
    AUC is calculated before any reduction.
    
    Writes the reduced set to outname.predictions
    
Compute error metrics from resulst.
results is formated: (correct, prediction, receptor, ligand, label, posescore,rmsd)
This is assumed to be a cross docked input, where receptor filename is
POCKET/PDB_CH_rec_0.gninatypes
and the ligand is
POCKET/PDB1_CH_rec_PDB2_lig_...gninatypes

RMSE, Pearson, Spearman, AUC and top-1 percentage are computed.

select can be pose or rmsd.  With pose we use the best pose scoring pose
of all ligand poses in a pocket.  For rmsd we use the lowest rmsd line for
that ligand in the pocket.

AUC is calculated before any reduction.

Writes the reduced set to outname.predictions
Compute error metrics from resulst . results is formated : ( correct prediction receptor ligand label posescore rmsd ) This is assumed to be a cross docked input where receptor filename is POCKET / PDB_CH_rec_0 . gninatypes and the ligand is POCKET / PDB1_CH_rec_PDB2_lig_ ... gninatypes RMSE Pearson Spearman AUC and top - 1 percentage are computed . select can be pose or rmsd . With pose we use the best pose scoring pose of all ligand poses in a pocket . For rmsd we use the lowest rmsd line for that ligand in the pocket . AUC is calculated before any reduction . Writes the reduced set to outname . predictions
def analyze_cross_results(results,outname,uniquify):
    labels = np.array([r[4] for r in results])
    posescores = np.array([r[5] for r in results])
    predictions = np.array([r[1] for r in results])
    aucpose = sklearn.metrics.roc_auc_score(labels, posescores)
    aucaff = sklearn.metrics.roc_auc_score(labels, predictions)
    if uniquify == 'rmsd':
        results = reduce_results(results, 6, 'small')
    elif uniquify == 'affinity':
        results = reduce_results(results, 1, 'large')
    elif uniquify == 'pose':
        results = reduce_results(results, 5, 'large')
    predictions = np.array([r[1] for r in results])
    correctaff = np.array([abs(r[0]) for r in results])
    predictions = predictions[correctaff != 0]
    correctaff = np.abs(correctaff[correctaff != 0])
    rmse = np.sqrt(sklearn.metrics.mean_squared_error(correctaff, predictions))
    R = scipy.stats.pearsonr(correctaff, predictions)[0]
    S = scipy.stats.spearmanr(correctaff, predictions)[0]
    out = open('%s.predictions'%outname,'w')
    out.write('aff,pred,rec,lig,lab,score,rmsd\n')
    for res in results:
        out.write(','.join(map(str,res))+'\n')
    out.write('#RMSD %f\n'%rmse)
    out.write('#R %f\n'%R)
    labels = np.array([r[4] for r in results])
    top = np.count_nonzero(labels > 0)/float(len(labels))
    return (rmse, R, S, aucpose, aucaff, top)
def analyze_cross_results ( results , outname , uniquify ) : labels = np . array ( [ r [ 4 ] for r in results ] ) posescores = np . array ( [ r [ 5 ] for r in results ] ) predictions = np . array ( [ r [ 1 ] for r in results ] ) aucpose = sklearn . metrics . roc_auc_score ( labels , posescores ) aucaff = sklearn . metrics . roc_auc_score ( labels , predictions ) if uniquify == 'rmsd' : results = reduce_results ( results , 6 , 'small' ) elif uniquify == 'affinity' : results = reduce_results ( results , 1 , 'large' ) elif uniquify == 'pose' : results = reduce_results ( results , 5 , 'large' ) predictions = np . array ( [ r [ 1 ] for r in results ] ) correctaff = np . array ( [ abs ( r [ 0 ] ) for r in results ] ) predictions = predictions [ correctaff != 0 ] correctaff = np . abs ( correctaff [ correctaff != 0 ] ) rmse = np . sqrt ( sklearn . metrics . mean_squared_error ( correctaff , predictions ) ) R = scipy . stats . pearsonr ( correctaff , predictions ) [ 0 ] S = scipy . stats . spearmanr ( correctaff , predictions ) [ 0 ] out = open ( '%s.predictions' % outname , 'w' ) out . write ( 'aff,pred,rec,lig,lab,score,rmsd\n' ) for res in results : out . write ( ',' . join ( map ( str , res ) ) + '\n' ) out . write ( '#RMSD %f\n' % rmse ) out . write ( '#R %f\n' % R ) labels = np . array ( [ r [ 4 ] for r in results ] ) top = np . count_nonzero ( labels > 0 ) / float ( len ( labels ) ) return ( rmse , R , S , aucpose , aucaff , top )
Compute error metrics from resulst.
Compute error metrics from resulst .
'''Compute error metrics from resulst.  
    results is formated: (correct, prediction, receptor, ligand, label, posescore,rmsd)
    This is assumed to be a cross docked input, where receptor filename is
    POCKET/PDB_CH_rec_0.gninatypes
    and the ligand is
    POCKET/PDB1_CH_rec_PDB2_lig_...gninatypes
    
    
    RMSE, Pearson, Spearman, AUC and top-1 percentage are computed.
    
    select can be pose or rmsd.  With pose we use the best pose scoring pose
    of all ligand poses in a pocket.  For rmsd we use the lowest rmsd line for
    that ligand in the pocket.
    
    AUC is calculated before any reduction.
    
    Writes the reduced set to outname.predictions
    ''' #calc auc before reduction #(correct, prediction, receptor, ligand, label (optional), posescore (optional))     #skip cases with no affinity
results
outname
uniquify