async def matchStrandToClass(pdbid: str, strand_id: str) -> str or None: CYPHER = f""" match (r:RibosomeStructure{{rcsb_id: "{pdbid.upper()}"}})-[]-(rp:RibosomalProtein)-[]-(n:NomenclatureClass) where rp.strand_id contains "{strand_id}" return n.class_id""" banClass = _neoget(CYPHER) if len(banClass) != 1: return None else: return banClass
def parseLigandNeighborhoods(pdbid:str): """ @pdibd is the 4-letter rcsb id. """ pdbid=pdbid.upper() entry:List = _neoget("""match (l:Ligand)-[]-(r:RibosomeStructure{{rcsb_id:"{pdbid}"}}) return {{struct: r.rcsb_id, ligs: collect({{ id:l.chemicalId, name: l.chemicalName }})}}""".format_map({ "pdbid":pdbid }))[0] if len(entry) == 0: print(f"No ligands found for {pdbid} the DB. Exiting..") return else: print("Received ligands for {}: ".format(pdbid), entry) ligandsResponse:List[str] = entry[0]['ligs'] ligandIds = [* map(lambda x : filterIons(x), ligandsResponse) ] ligandIds = [i for i in ligandIds if i] pathtostruct = os.path.join(STATIC_ROOT,pdbid,'{}.cif'.format(pdbid)) """Iterate over""" for x in ligandIds: savepath = os.path.join(STATIC_ROOT, pdbid, 'LIGAND_{}.json'.format(x)) #! These structures and ligand either take forever to render or fail silently. Why? if x in ["A"]: continue # if pdbid in ['4U3N'] or x in ['A', 'OHX', ]: # print("Skipping problematic {}".format(pdbid)) # continue # if pdbid in ['5TGM'] or x in ['A', 'OHX', 'LEU']: # continue # if os.path.exists(savepath): # print(savepath, " already exists. Skipping rendering.") # continue # else: struct = fetchStructure(pdbid, pathtostruct) print("Parsing residues of {}".format(x)) asresiudes = getLigandResIds(x, struct, 'res') internals = [addBanClass( ResidueId(residue) ) for residue in asresiudes ] nbrs = getLigandNbrs(asresiudes, struct) for nbr in nbrs: run(matchStrandToClass(nbr[ 'struct' ],nbr[ 'strand_id' ])) ligprofile = {'constituents': internals,'nbrs': nbrs} with open(savepath, 'w') as json_file: json.dump(ligprofile,json_file) print(f'Wrote to {savepath}')
async def matchClassToStrand(pdbid: str, banClass: str) -> str: CYPHER = f""" match (r:RibosomeStructure{{rcsb_id: "{pdbid.upper()}"}})-[]-(rp:RibosomalProtein)-[]-(n:NomenclatureClass{{class_id:'{banClass}'}}) return rp.strand_id""" strand_id = _neoget(CYPHER) if len(strand_id) != 1: print( 'ERROR: Matched none or multiple subchains for a single nomenclature class {} in {}' .format(banClass, pdbid)) raise NameError print( f"Matched strand {strand_id[0][0]} of {pdbid} to nomenclature class {banClass}" ) return strand_id[0][0]
async def matchStrandToClass(pdbid:str, strand_id:str)->str: CYPHER="""match (r:RibosomeStructure{{rcsb_id: "{}"}})-[]-(rp:RibosomalProtein{{entity_poly_strand_id:"{}"}})-[]-(n:NomenclatureClass) return n.class_id""".format(pdbid.upper(), strand_id) # CYPHER="""match (r:RibosomeStructure{rcsb_id:"4U3N"})-[]-(rp:RibosomalProtein)-[]-(n:NomenclatureClass) where rp.entity_poly_strand_id contains "s8" # return n""".format() resp = _neoget(CYPHER) print(CYPHER) print("RESP", resp) if len(resp) > 0: return resp[0] else: return None
def __deprecated_addResidue(self, res: Residue) -> None: parentStrand = res.get_parent().get_id() if res.get_resname() not in [AMINO_ACIDS.keys(), *Nucleotides ] and res not in self.ligands: self.ligands.append(res) if parentStrand not in self.adjacentRnaStrands and parentStrand not in self.adjacentRPStrands: response = _neoget(""" match (n {{entity_poly_strand_id:"{parentStrand}"}})-[]-(r:RibosomeStructure{{rcsb_id:"{pdbid}"}}) \ return {{type: n.entity_poly_polymer_type, nomenclature:n.nomenclature}};""" .format_map({ "parentStrand": parentStrand, "pdbid": self.pdbid })) try: profile = response[0] if profile['type'] == 'RNA': self.adjacentRnaStrands.append(parentStrand) self.rna[parentStrand] = [] if profile['type'] == 'Protein': self.adjacentRPStrands.append(parentStrand) self.rps[parentStrand] = [] self.nomenclatureMap[parentStrand] = profile[ 'nomenclature'] except: pass if parentStrand in self.adjacentRnaStrands: if res in self.rna[parentStrand]: None else: self.rna[parentStrand].append(res) elif parentStrand in self.adjacentRPStrands: if res in self.rps[parentStrand]: None else: self.rps[parentStrand].append(res) print("added residue") self.rescount += 1
def getConstrictedProteins(pdbid: str) -> List[str]: cypher = """ match (n:RibosomeStructure{{rcsb_id:"{pdbid}"}})-[]-(rp:RibosomalProtein) where "uL4" in rp.nomenclature or "uL22" in rp.nomenclature return rp.entity_poly_strand_id,rp.nomenclature, n.rcsb_id """.format_map({"pdbid": pdbid.upper()}) response = _neoget(cypher) resplist = [ *map( lambda x: (x['rp.nomenclature'][0], x['rp.entity_poly_strand_id']), response) ] uL22 = None uL4 = None for nom in resplist: if nom[0] == "uL22": uL22 = nom[1] if nom[0] == "uL4": uL4 = nom[1] return {"uL4": uL4, "uL22": uL22}
def add_nomenclature_map_to_report(pdbid: str, path_to_report: str): with open(path_to_report, mode='rb') as reportfile: report = json.load(reportfile) chains = [] for chain in report['adjacent_strands'].keys(): chains.append(chain) chains = ",".join(map(lambda x: "\"{}\"".format(x), chains)) nresponse = _neoget(""" match (r:RibosomeStructure{{rcsb_id:"{}"}})-[]-(n) where n.entity_poly_strand_id in [{}] return {{strand:n.entity_poly_strand_id,type: n.entity_poly_polymer_type, nomenclature:n.nomenclature}}; """.format(pdbid, chains)) report['nomenclatureMap'] = {} for strand in nresponse: strand_profile = [*strand.values()][0] nomenclature = strand_profile['nomenclature'] strand = strand_profile['strand'] polytype = strand_profile['type'] report['nomenclatureMap'][strand] = { "type": polytype, "nomenclature": nomenclature } with open(path_to_report, 'w') as reportfile: json.dump(report, reportfile) print("Added nomenclature map to {}".format(path_to_report)) # x = InitWalls(PDBID)
from ciftools.Neoget import _neoget prs = FastMMCIFParser(QUIET=True) io = MMCIFIO() for pdbid in [ '1vy4', ]: pdbid = pdbid.upper() struct: Structure = prs.get_structure(f'{pdbid}', f'{pdbid}.cif') for chain in struct[0].child_list: strand_id = chain.id nomclass_result = _neoget( f"""match (r:RibosomeStructure{{rcsb_id: "{pdbid.upper()}"}})-[]-(rp:RibosomalProtein)-[]-(n:NomenclatureClass) where rp.entity_poly_strand_id = "{strand_id}" return n.class_id""") print(nomclass_result) if len(nomclass_result) > 0: struct[0][strand_id].id = f"{strand_id}[{nomclass_result[0][0]}]" print("got nomcalss", nomclass_result[0][0]) else: struct[0][strand_id].id = f"{strand_id}[-]" print("got empty") io.set_structure(struct) io.save(f'{pdbid}+.cif') # print(run(matchStrandToClass('3j9m','D'))) # k:Model =struct[0] # chain:Chain;