def removeVersion(endpoint): va = sandVersion(endpoint) vb = lastVersion(endpoint, -1) if va == vb: return (False, 'no more removable versions') # check exposed version if not checkOldSynthax(endpoint): return (False, 'Unable to fix service-version.txt') ndir = wkd + '/' + endpoint if os.path.isfile(ndir + '/service-version.txt'): versions = [] f = open(ndir + '/service-version.txt', 'r') versions = f.readlines() f.close() del versions[-1] f = open(ndir + '/service-version.txt', 'w') for vi in versions: f.write(vi) f.close() # remove directory try: shutil.rmtree(vb, ignore_errors=True) except: return (False, 'unable to remove ' + vb) return (True, 'version ' + vb + ' removed OK')
def removeVersion (endpoint): va = sandVersion (endpoint) vb = lastVersion (endpoint,-1) if va == vb: return (False, 'no more removable versions') # check exposed version if not checkOldSynthax (endpoint): return (False, 'Unable to fix service-version.txt') ndir = wkd +'/'+endpoint if os.path.isfile (ndir+'/service-version.txt'): versions = [] f = open (ndir+'/service-version.txt','r') versions = f.readlines() f.close() del versions[-1] f = open (ndir+'/service-version.txt','w') for vi in versions: f.write (vi) f.close() # remove directory try: shutil.rmtree (vb, ignore_errors=True) except: return (False, 'unable to remove '+vb) return (True,'version '+vb+' removed OK')
def get(endpoint, ver, piece): if 'model' in piece: piece_name = '/imodel.py' elif 'series' in piece: piece_name = '/training.sdf' vb = lastVersion(endpoint, ver) try: shutil.copy(vb + piece_name, './') except: return (False, 'Unable to copy ' + piece_name) return (True, 'File retrieved OK')
def get (endpoint, ver, piece): if 'model' in piece: piece_name = '/imodel.py' elif 'series' in piece: piece_name = '/training.sdf' vb = lastVersion (endpoint,ver) try: shutil.copy(vb+piece_name,'./') except: return (False,'Unable to copy '+piece_name) return (True, 'File retrieved OK')
def view(endpoint, molecules, verID, vtype, background, refname, refver): """Top level view function molecules: SDFile containing the collection of 2D structures to be predicted verID: version of the model that will be used. Value -1 means the last one """ if verID != -99: va = lastVersion(endpoint, verID) ## if not molecules: ## molecules = va+'/training.sdf' # load model try: sys.path.append(va) from imodel import imodel model = imodel(va) except: return (False, 'unable to load imodel') if not model: return (False, 'unable to load imodel') # arguments of the call overwrite existing view settings of imodel.py ## viewMode = query or series if vtype != None: model.viewType = vtype if background != None: model.viewBackground = background if molecules: model.viewMode = 'query' model.viewReferenceEndpoint = endpoint model.viewReferenceVersion = verID else: model.viewMode = 'series' if refname != None: model.viewReferenceEndpoint = refname if refver != None: model.viewReferenceVersion = refver result = model.viewWorkflow(molecules) return (result)
def predict(endpoint, molecules, verID=-1, api=0, loc=-99, detail=False, progress=False, extValid=False): """Top level prediction function molecules: SDFile containing the collection of 2D structures to be predicted verID: version of the model that will be used. Value -1 means the last one detail: level of detail of the prediction. If True the structure of the closest compond will be returned """ # web calls, we look for web exposed versions if api in (1, 2, 5): vpath = exposedVersion(endpoint) if vpath == None: return (False, 'no published model found') else: vpath = lastVersion(endpoint, verID) ## also for api==6 (API v3.0) if not vpath: return (False, "No versions directory found") ##print vpath if loc != -99: vpath += '/local%0.4d' % loc sys.path.append(vpath) from imodel import imodel # load model model = imodel(vpath) # to maintain back-compatibility, the last parameter is only introduced when set to TRUE # this is used only in command mode (-x flag) and therefore never set for web-based preditions if extValid: success, pred = model.predictWorkflow(molecules, detail, progress, extValid) else: success, pred = model.predictWorkflow(molecules, detail, progress) return (success, pred)
def predict (endpoint, molecules, verID=-1, api=0, loc=-99, detail=False, progress=False, extValid=False): """Top level prediction function molecules: SDFile containing the collection of 2D structures to be predicted verID: version of the model that will be used. Value -1 means the last one detail: level of detail of the prediction. If True the structure of the closest compond will be returned """ # web calls, we look for web exposed versions if api in (1,2,5): vpath = exposedVersion (endpoint) if vpath == None: return (False, 'no published model found') else: vpath = lastVersion (endpoint,verID) ## also for api==6 (API v3.0) if not vpath: return (False,"No versions directory found") ##print vpath if loc != -99: vpath += '/local%0.4d' % loc sys.path.append(vpath) from imodel import imodel # load model model = imodel(vpath) # to maintain back-compatibility, the last parameter is only introduced when set to TRUE # this is used only in command mode (-x flag) and therefore never set for web-based preditions if extValid: success, pred = model.predictWorkflow (molecules, detail, progress, extValid) else: success, pred = model.predictWorkflow (molecules, detail, progress) return (success, pred)
def infoVersion(endpoint, ver, style, pubver): vb = lastVersion(endpoint, ver) unk = not os.path.isfile(vb + '/info.pkl') ## ## if : ## if ver == 0: ## print '* no model info available' ## else: ## print '%-4s no model info available'%ver ## return (True, 'OK') ## ## #return (False,'model information file not found') if not unk: modelInfo = open(vb + '/info.pkl', 'rb') infoID = pickle.load(modelInfo) infoSeries = pickle.load(modelInfo) infoMD = pickle.load(modelInfo) infoModel = pickle.load(modelInfo) infoResult = pickle.load(modelInfo) try: infoNotes = pickle.load(modelInfo) except: infoNotes = [] modelInfo.close() #print infoID, infoSeries, infoMD, infoModel, infoResult if style in 'long': if unk: if ver == 0: print '*' else: print '%-4s' % ver #print ' web service :', isWS if pubver > 0: print ' public vers :', pubver else: print ' public vers : none' print ' no model info available' return (True, 'OK') for i in infoID: if 'version' in i: print i[1] for i in infoID: if not 'version' in i: print ' %-10s' % i[0], ' : ' + str(i[1]) #print " web service :", isWS if pubver > 0: print ' public vers :', pubver else: print ' public vers : none' for i in infoSeries: print ' %-10s' % i[0], ' : ' + str(i[1]) for i in infoMD: print ' %-10s' % i[0], ' : ' + str(i[1]) for i in infoModel: print ' %-10s' % i[0], ' : ' + str(i[1]) for i in infoResult: print ' %-10s' % i[0], ' : ' + str(i[1]) for i in infoNotes: print ' %-10s' % i[0], ' : ' + str(i[1]) print
def infoVersion(endpoint, ver, style, pubver): vb = lastVersion(endpoint, ver) unk = not os.path.isfile(vb + '/info.pkl') ## ## if : ## if ver == 0: ## print '* no model info available' ## else: ## print '%-4s no model info available'%ver ## return (True, 'OK') ## ## #return (False,'model information file not found') if not unk: modelInfo = open(vb + '/info.pkl', 'rb') infoID = pickle.load(modelInfo) infoSeries = pickle.load(modelInfo) infoMD = pickle.load(modelInfo) infoModel = pickle.load(modelInfo) infoResult = pickle.load(modelInfo) try: infoNotes = pickle.load(modelInfo) except: infoNotes = [] modelInfo.close() #print infoID, infoSeries, infoMD, infoModel, infoResult if style in 'long': if unk: if ver == 0: print('*') else: print('%-4s' % ver) #print ' web service :', isWS if pubver > 0: print(' public vers :', pubver) else: print(' public vers : none') print(' no model info available') return (True, 'OK') for i in infoID: if 'version' in i: print(i[1]) for i in infoID: if not 'version' in i: print(' %-10s' % i[0], ' : ' + str(i[1])) #print " web service :", isWS if pubver > 0: print(' public vers :', pubver) else: print(' public vers : none') for i in infoSeries: print(' %-10s' % i[0], ' : ' + str(i[1])) for i in infoMD: print(' %-10s' % i[0], ' : ' + str(i[1])) for i in infoModel: print(' %-10s' % i[0], ' : ' + str(i[1])) for i in infoResult: print(' %-10s' % i[0], ' : ' + str(i[1])) for i in infoNotes: print(' %-10s' % i[0], ' : ' + str(i[1])) print() elif style in 'short': iversion = 4 * ' ' iMD = 8 * ' ' imod = 16 * ' ' imol = isen = ispe = iMCC = ir2 = iq2 = isdep = iSSX = 4 * ' ' iconf = '' if pubver == 0: ws = ' ' else: ws = ' %-2d' % pubver ## if isWS : ws = ' @ ' ## else : ws = ' ' ## if ver == 0: print '*' ## else : print '%-4s'%ver if unk: if ver == 0: print('* ' + ws + 'no model info available') else: print('%-4s' % ver + ws + 'no model info available') return (True, 'OK') for i in infoID: if 'version' == i[0]: iversion = '%-4s' % (i[1]) if 'confident' == i[0] and i[1] == 'True': iconf = ' confident' for i in infoMD: if 'MD' == i[0]: iMD = '%-8s' % (i[1]) for i in infoModel: if 'model' == i[0]: imod = '%-16s' % (i[1]) for i in infoResult: if 'nobj' == i[0]: try: imol = '%4d' % int(i[1]) except: imol = ' 0' elif 'sens' == i[0]: try: isen = '%4.2f' % (float(i[1])) except: isen = ' 0.00' elif 'spec' == i[0]: try: ispe = '%4.2f' % (float(i[1])) except: ispe = ' 0.00' elif 'MCC' == i[0]: try: iMCC = '%4.2f' % (float(i[1])) except: iMCC = ' 0.00' elif 'R2' == i[0]: try: ir2 = '%4.2f' % (float(i[1])) except: ir2 = ' 0.00' elif 'Q2' == i[0]: try: iq2 = '%4.2f' % (float(i[1])) except: iq2 = ' 0.00' elif 'SDEP' == i[0]: try: isdep = '%4.2f' % (float(i[1])) except: isdep = ' 0.00' elif 'SSX' == i[0]: try: iSSX = '%4.2f' % (float(i[1])) except: iSSX = ' 0.00' #print '*'+str(iMCC)+'*'+str(iSSX)+'*'+str(ir2)+'*' if iSSX != ' ': # PCA print(iversion + ws + 'MD:' + iMD + ' mod:' + imod + ' mol:' + imol + ' SSX:' + iSSX + iconf) elif iMCC != ' ': # qualitative model / classifier print(iversion + ws + 'MD:' + iMD + ' mod:' + imod + ' mol:' + imol + ' sen:' + isen + ' spe:' + ispe + ' MCC:' + iMCC + iconf) elif ir2 != ' ': cache = iversion + ws + 'MD:' + iMD + ' mod:' + imod + ' mol:' + imol + ' R2:' + ir2 if iq2 != ' ': cache += ' Q2:' + iq2 if isdep != ' ': cache += ' SDEP:' + isdep cache += iconf print(cache) else: print(iversion + ws + 'MD:' + iMD + ' mod:' + imod + ' mol:' + imol + ' R2:' + ir2 + ' Q2:' + iq2 + ' SDEP:' + isdep + iconf) return (True, 'OK')
def infoVersion (endpoint,ver,style,pubver): vb = lastVersion (endpoint,ver) unk = not os.path.isfile (vb+'/info.pkl') ## ## if : ## if ver == 0: ## print '* no model info available' ## else: ## print '%-4s no model info available'%ver ## return (True, 'OK') ## ## #return (False,'model information file not found') if not unk: modelInfo = open (vb+'/info.pkl','rb') infoID = pickle.load(modelInfo) infoSeries = pickle.load(modelInfo) infoMD = pickle.load(modelInfo) infoModel = pickle.load(modelInfo) infoResult = pickle.load(modelInfo) try: infoNotes = pickle.load(modelInfo) except: infoNotes = [] modelInfo.close() #print infoID, infoSeries, infoMD, infoModel, infoResult if style in 'long': if unk : if ver == 0: print '*' else : print '%-4s'%ver #print ' web service :', isWS if pubver > 0 : print ' public vers :', pubver else: print ' public vers : none' print ' no model info available' return (True, 'OK') for i in infoID: if 'version' in i: print i[1] for i in infoID: if not 'version' in i: print ' %-10s'%i[0],' : '+str(i[1]) #print " web service :", isWS if pubver > 0 : print ' public vers :', pubver else: print ' public vers : none' for i in infoSeries: print ' %-10s'%i[0],' : '+str(i[1]) for i in infoMD: print ' %-10s'%i[0],' : '+str(i[1]) for i in infoModel: print ' %-10s'%i[0],' : '+str(i[1]) for i in infoResult: print ' %-10s'%i[0],' : '+str(i[1]) for i in infoNotes: print ' %-10s'%i[0],' : '+str(i[1]) print