Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
More credoscript examples to show the implementation of SQLAlchemy.
@hybrid_method
@requires.rdkit
def contains(self, smiles):
return self.rdmol.HasSubstructMatch(MolFromSmiles(str(smiles)))
@contains.expression
def contains(self, smiles):
return self.rdmol.op('OPERATOR(rdkit.@>)')(smiles)
from credoscript.models import Domain
from credoscript.adaptors import DomainAdaptor
adaptor = DomainAdaptor()
adaptor.fetch_all_by_substruct('c1cc(cnc1)c2ccncn2', Domain.db_source=='Pfam')
query = query.with_entities(Domain.db_accession_id, Domain.description)
query = query.filter(and_(Domain.db_source=='Pfam',
ChemCompRDMol.contains('c1cc(cnc1)c2ccncn2')))
query = Domain.query.join('Ligands','Components','ChemComp','RDMol')
from sqlalchemy.sql import and_
from credoscript.models import *
# get all Pfam domains that interact with the scaffold c1cc(cnc1)c2ccncn2
query = Domain.query.join('Ligands','Components','ChemComp','RDMol')
query = query.filter(and_(Domain.db_source=='Pfam',
ChemCompRDMol.contains('c1cc(cnc1)c2ccncn2')))
query.distinct().all()
# resulting list of domain entities
[<Domain(Pfam PF00069)>, <Domain(Pfam PF00326)>,
<Domain(Pfam PF00454)>, <Domain(Pfam PF00930)>,
<Domain(Pfam PF02518)>, <Domain(Pfam PF02525)>,
<Domain(Pfam PF07714)>]
query = query.with_entities(Domain.db_accession_id, Domain.description)
query.distinct().all()
[(u'PF00069', u'Protein kinase domain'),
(u'PF00326', u'Prolyl oligopeptidase family'),
(u'PF00454', u'Phosphatidylinositol 3- and 4-kinase'),
(u'PF00930', u'Dipeptidyl peptidase IV (DPP IV) N-terminal region'),
(u'PF02518', u'Histidine kinase-, DNA gyrase B-, and HSP90-like ATPase'),
(u'PF02525', u'Flavodoxin-like fold'),
(u'PF07714', u'Protein tyrosine kinase')]
Ligands = relationship("Ligand",
secondary=Base.metadata.tables['credo.binding_site_domains'],
primaryjoin="Domain.domain_id==BindingSiteDomain.domain_id",
secondaryjoin="BindingSiteDomain.ligand_id==Ligand.ligand_id",
foreign_keys="[BindingSiteDomain.domain_id, Ligand.ligand_id]",
uselist=True, innerjoin=True, lazy='dynamic',
backref=backref('Domains', uselist=True, lazy='dynamic', innerjoin=True))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment