def generatePNG(): lsmi = listdir(pathFolder.PR_SMI) for smi in lsmi: psmi = pathFolder.PR_SMI + smi ppng = pathFolder.PR_PNG + smi[:-3] + "png" runExternalSoft.molconvert(psmi, ppng)
def generatePNG(self): pathFolder.createFolder(self.prPNG) lnSMIs = listdir(self.prSMIclean) for nSMI in lnSMIs: runExternalSoft.molconvert(self.prSMIclean + nSMI, self.prPNG + nSMI[:-3] + "png")
def drawMolecules(self, prpng): if not "prsdf" in dir(self): self.splitSDF() pathFolder.createFolder(prpng) self.prpng = prpng if len(listdir(self.prsdf)) == len(listdir(self.prpng)): return lfsdf = listdir(self.prsdf) for sdf in lfsdf: runExternalSoft.molconvert(self.prsdf + sdf, self.prpng + sdf[:-3] + "png")
def get_PNGAndSMI(p_desc, pr_results): # load the ddesc to have SMILES cleanned ddesc = toolbox.loadMatrix(p_desc) pr_smi = pathFolder.createFolder(pr_results + "SMI/") pr_png = pathFolder.createFolder(pr_results + "PNG/") for chemID in ddesc.keys(): print chemID SMILES = ddesc[chemID]["SMILES"] p_fsmi = pr_smi + chemID + ".smi" fsmi = open(p_fsmi, "w") fsmi.write(SMILES) fsmi.close() p_fpng = pr_png + chemID + ".png" runExternalSoft.molconvert(p_fsmi, p_fpng) return
def extractByCluster(pcluster, prout, pdesc): dcluster = toolbox.formatClusterTable(pcluster) lcpddesc = toolbox.tableTolist(pdesc) for cluster in dcluster.keys(): prcluster = pathFolder.createFolder(prout + "cluster" + str(cluster) + "/") for compound in dcluster[cluster]: for cpddec in lcpddesc: if compound == cpddec["ID"]: smile = cpddec["SMILES"] psmi = prcluster + str(compound) + ".smi" filesmi = open(psmi,"w") filesmi.write(smile) filesmi.close() runExternalSoft.molconvert(psmi) break
def runPNG(prSMI, prPNG): if not path.exists(prSMI): print ("ERROR: CREATE CLEAN SMI FIRST") return lSMI = listdir(prSMI) shuffle(lSMI) for SMI in lSMI: #print prSMI + SMI fSMI = open(prSMI + SMI, "r") lelem = fSMI.readlines() #print(lelem) if len(lelem) == 0: continue lelem = lelem[0].split("\t") #if len(lelem) == 1: # print lelem # print prSMI + SMI if lelem[0] == "ERROR": continue else: if len(lelem) < 3: print (prSMI + SMI) #remove(prSMI + SMI) continue inchikey = lelem[1] DSSTOXid = lelem[2] SMIclean = lelem[0] if not path.exists(prPNG + inchikey + ".png"): pSMIclean = prPNG + inchikey + ".smi" fSMIcLean = open(pSMIclean, "w") fSMIcLean.write(SMIclean) fSMIcLean.close() runExternalSoft.molconvert(pSMIclean)
def get_TopRanking(self, ptableCHEMBL, nrank = 5): pr_topChem = pathFolder.createFolder(self.pr_out + "top-" + str(nrank) + "/") # load dock score if not "dscores" in self.__dict__: self.get_bestdockingscore() # load dataset ldchem = toolbox.matrixToList(ptableCHEMBL) dbytypeAct = {} for dchem in ldchem: typeAff = dchem["STANDARD_TYPE"] if not typeAff in dbytypeAct.keys(): dbytypeAct[typeAff] = {} nameChem = dchem["CMPD_CHEMBLID"] dbytypeAct[typeAff][nameChem] = dchem # extract top 10 dock score for typeAff in dbytypeAct.keys(): print typeAff laff = [] for pose in self.cPoses.lc: pose_chem = pose["s_m_entry_name"].split(".")[0] if pose_chem in dbytypeAct[typeAff].keys(): laff.append(float(pose["r_i_docking_score"])) # order laff.sort() i = 0 irank = 1 l_chem_image = [] while irank <= nrank: for pose in self.cPoses.lc: pose_chem = pose["s_m_entry_name"].split(".")[0] try:score_dock = float(pose["r_i_docking_score"]) except:continue if score_dock == laff[i]: if pose_chem in l_chem_image: continue else: l_chem_image.append(pose_chem) # path png and sdf p_image = "%s%s_%s-%s.png"%(pr_topChem, irank, pose_chem, typeAff) p_smiout = "%s%s_%s-%s.smi"%(pr_topChem, irank, pose_chem, typeAff) # to write on figure lw = ["ChEMBL ID: " + str(pose_chem)] lw.append("Rank: " + str(irank)) lw.append("p" + typeAff + ": " + str(dbytypeAct[typeAff][pose_chem]["PCHEMBL_VALUE"])) lw.append("Docking score: {:0.2f}".format(float(pose["r_i_docking_score"]))) lw.append("Emodel score: {:0.2f}".format(float(pose["r_i_glide_emodel"]))) # generate png f_smiout = open(p_smiout, "w") f_smiout.write(dbytypeAct[typeAff][pose_chem]["CANONICAL_SMILES"]) f_smiout.close() # png runExternalSoft.molconvert(p_smiout, p_image) img = Image.open(p_image) imgnew = Image.new("RGBA", (580, 775), (250, 250, 250)) imgnew.paste(img, (0,0)) draw = ImageDraw.Draw(imgnew) draw.text((10, 600), lw[0], (0, 0, 0), font=font) draw.text((10, 625), lw[1], (0, 0, 0), font=font) draw.text((10, 650), lw[2], (0, 0, 0), font=font) draw.text((10, 675), lw[3], (0, 0, 0), font=font) draw.text((10, 700), lw[4], (0, 0, 0), font=font) imgnew.save(p_image) irank = irank + 1 break i = i + 1