predict.py
def predict(args):
    '''Return yscore and/or y_predaff with rest of input line for each example'''
    if args.gpu >= 0:
        caffe.set_device(args.gpu)
    caffe.set_mode_gpu()
    test_model = 'predict.%d.prototxt' % os.getpid()
    write_model_file(test_model, args.model, args.input, args.data_root)
    test_net = caffe.Net(test_model, args.weights, caffe.TEST)
    with open(args.input, 'r') as f:
        lines = f.readlines()
    result = evaluate_test_net(test_net, len(lines), args.rotations)
    auc = result.auc
    y_true = result.y_true
    y_score = result.y_score
    loss = result.loss
    rmsd = result.rmsd
    pearsonr = None
    y_affinity = result.y_aff
    y_predaff = result.y_predaff
    
#    auc, y_true, y_score, loss, rmsd, y_affinity, y_predaff = result

    if 'labelout' in test_net.outputs:
        assert np.all(y_true == [float(l.split(' ')[0]) for l in lines]) #check alignment
    if 'affout' in test_net.outputs:
        for (l,a) in zip(lines,y_affinity):
            lval = float(l.split()[1])
            if abs(lval-a) > 0.001:
                print("Mismatching values",a,l)
                sys.exit(-1)

    if rmsd != None and auc != None:
        output_lines = [t for t in zip(y_score, y_predaff, lines)]
    elif rmsd != None:
        output_lines = [t for t in zip(y_predaff, lines)]
    elif auc != None:
        output_lines = [t for t in zip(y_score, lines)]
                        

    #this is all awkward and should be rewritten with a smarter approach than munging strings
    if args.max_score or args.max_affinity:
        output_lines = maxLigandScore(output_lines, args.max_affinity)
        #have to recalculate RMSD and AUC  
            
        if auc != None:
            y_true = [float(line[-1].split()[0]) for line in output_lines]
            y_score = [line[0] for line in output_lines]
            auc = sklearn.metrics.roc_auc_score(y_true, y_score)
        if rmsd != None:
            y_affinity = [float(line[-1].split()[1]) for line in output_lines]
            y_predaff = [line[1] for line in output_lines]
            rmsd = np.sqrt(sklearn.metrics.mean_squared_error(np.abs(y_affinity),y_predaff))
            pearsonr = scipy.stats.pearsonr(np.abs(y_affinity),y_predaff)[0]

    if not args.keep:
        os.remove(test_model)
    return output_lines,auc,rmsd,pearsonr
Return yscore and/or y_predaff with rest of input line for each example
Return yscore and/or y_predaff with rest of input line for each example
Return yscore and / or y_predaff with rest of input line for each example
def predict(args):
    if args.gpu >= 0:
        caffe.set_device(args.gpu)
    caffe.set_mode_gpu()
    test_model = 'predict.%d.prototxt' % os.getpid()
    write_model_file(test_model, args.model, args.input, args.data_root)
    test_net = caffe.Net(test_model, args.weights, caffe.TEST)
    with open(args.input, 'r') as f:
        lines = f.readlines()
    result = evaluate_test_net(test_net, len(lines), args.rotations)
    auc = result.auc
    y_true = result.y_true
    y_score = result.y_score
    loss = result.loss
    rmsd = result.rmsd
    pearsonr = None
    y_affinity = result.y_aff
    y_predaff = result.y_predaff
    if 'labelout' in test_net.outputs:
        assert np.all(y_true == [float(l.split(' ')[0]) for l in lines]) 
    if 'affout' in test_net.outputs:
        for (l,a) in zip(lines,y_affinity):
            lval = float(l.split()[1])
            if abs(lval-a) > 0.001:
                print("Mismatching values",a,l)
                sys.exit(-1)
    if rmsd != None and auc != None:
        output_lines = [t for t in zip(y_score, y_predaff, lines)]
    elif rmsd != None:
        output_lines = [t for t in zip(y_predaff, lines)]
    elif auc != None:
        output_lines = [t for t in zip(y_score, lines)]
    if args.max_score or args.max_affinity:
        output_lines = maxLigandScore(output_lines, args.max_affinity)
        if auc != None:
            y_true = [float(line[-1].split()[0]) for line in output_lines]
            y_score = [line[0] for line in output_lines]
            auc = sklearn.metrics.roc_auc_score(y_true, y_score)
        if rmsd != None:
            y_affinity = [float(line[-1].split()[1]) for line in output_lines]
            y_predaff = [line[1] for line in output_lines]
            rmsd = np.sqrt(sklearn.metrics.mean_squared_error(np.abs(y_affinity),y_predaff))
            pearsonr = scipy.stats.pearsonr(np.abs(y_affinity),y_predaff)[0]
    if not args.keep:
        os.remove(test_model)
    return output_lines,auc,rmsd,pearsonr
def predict ( args ) : if args . gpu >= 0 : caffe . set_device ( args . gpu ) caffe . set_mode_gpu ( ) test_model = 'predict.%d.prototxt' % os . getpid ( ) write_model_file ( test_model , args . model , args . input , args . data_root ) test_net = caffe . Net ( test_model , args . weights , caffe . TEST ) with open ( args . input , 'r' ) as f : lines = f . readlines ( ) result = evaluate_test_net ( test_net , len ( lines ) , args . rotations ) auc = result . auc y_true = result . y_true y_score = result . y_score loss = result . loss rmsd = result . rmsd pearsonr = None y_affinity = result . y_aff y_predaff = result . y_predaff if 'labelout' in test_net . outputs : assert np . all ( y_true == [ float ( l . split ( ' ' ) [ 0 ] ) for l in lines ] ) if 'affout' in test_net . outputs : for ( l , a ) in zip ( lines , y_affinity ) : lval = float ( l . split ( ) [ 1 ] ) if abs ( lval - a ) > 0.001 : print ( "Mismatching values" , a , l ) sys . exit ( - 1 ) if rmsd != None and auc != None : output_lines = [ t for t in zip ( y_score , y_predaff , lines ) ] elif rmsd != None : output_lines = [ t for t in zip ( y_predaff , lines ) ] elif auc != None : output_lines = [ t for t in zip ( y_score , lines ) ] if args . max_score or args . max_affinity : output_lines = maxLigandScore ( output_lines , args . max_affinity ) if auc != None : y_true = [ float ( line [ - 1 ] . split ( ) [ 0 ] ) for line in output_lines ] y_score = [ line [ 0 ] for line in output_lines ] auc = sklearn . metrics . roc_auc_score ( y_true , y_score ) if rmsd != None : y_affinity = [ float ( line [ - 1 ] . split ( ) [ 1 ] ) for line in output_lines ] y_predaff = [ line [ 1 ] for line in output_lines ] rmsd = np . sqrt ( sklearn . metrics . mean_squared_error ( np . abs ( y_affinity ) , y_predaff ) ) pearsonr = scipy . stats . pearsonr ( np . abs ( y_affinity ) , y_predaff ) [ 0 ] if not args . keep : os . remove ( test_model ) return output_lines , auc , rmsd , pearsonr
Return yscore and/or y_predaff with rest of input line for each example
Return yscore and / or y_predaff with rest of input line for each example
'''Return yscore and/or y_predaff with rest of input line for each example''' #    auc, y_true, y_score, loss, rmsd, y_affinity, y_predaff = result #check alignment #this is all awkward and should be rewritten with a smarter approach than munging strings #have to recalculate RMSD and AUC  
args