Exemplo n.º 1
0
class PubChemData(EntityBase):
    __tablename__ = 'pubchem_data'

    pubchem_id = Column(String(20), primary_key=True)

    names = Column(ARRAY(TEXT))

    mass = Column(Float)
    #weight = Column(Float)
    monoisotopic_mass = Column(Float)
    logp = Column(Float)

    # structure info -
    smiles = Column(ARRAY(TEXT))
    inchi = Column(TEXT)
    inchikey = Column(String(27))
    formula = Column(String(256))

    chebi_id = Column(String(20), ForeignKey('chebi_data.chebi_id'))
    kegg_id = Column(String(20), ForeignKey('kegg_data.kegg_id'))
    hmdb_id = Column(String(20), ForeignKey('hmdb_data.hmdb_id'))
    chemspider_id = Column(String(20))


    ref_etc = Column(JSON_GEN())

    def __init__(self, **kwargs):
        pass
Exemplo n.º 2
0
class KeggData(EntityBase):
    __tablename__ = 'kegg_data'

    # Primary Ids
    kegg_id = Column(String(20), primary_key=True)

    # Reference Ids
    chebi_id = Column(
        String(20))  #ForeignKey('chebi_data.chebi_id', ondelete='SET NULL'))
    lipidmaps_id = Column(String(
        20))  #ForeignKey('lipidmaps_data.lipidmaps_id', ondelete='SET NULL'))
    pubchem_id = Column(String(
        20))  #ForeignKey('pubchem_data.pubchem_id', ondelete='SET NULL'))
    cas_id = Column(String(20))

    ref_etc = Column(JSON_GEN())  # Extra ref Refs
    pdb_id = Column(String(24))

    # Shared metadata
    names = Column(ARRAY(Text))
    monoisotopic_mass = Column(Float)
    mass = Column(Float)

    # Structure
    formula = Column(String(256))

    # Other Fun Facts
    comments = Column(Text)

    def __init__(self, **kwargs):
        self.kegg_id = kwargs.get('kegg_id')
        self.names = kwargs.get('names')
        self.monoisotopic_mass = kwargs.get('monoisotopic_mass')
        self.mass = kwargs.get('mass')
        self.comments = kwargs.get('comments')
        self.formula = kwargs.get('formula')
        self.cas_id = kwargs.get('cas_id')
        self.kegg_id = kwargs.get('kegg_id')
        self.chebi_id = kwargs.get('chebi_id')
        self.lipidmaps_id = kwargs.get('lipidmaps_id')
        self.pubchem_id = kwargs.get('pubchem_id')
        self.ref_etc = kwargs.get('ref_etc')

        if isinstance(self.monoisotopic_mass, str):
            if not self.monoisotopic_mass:
                self.monoisotopic_mass = None
            else:
                self.monoisotopic_mass = float(self.monoisotopic_mass)

        if isinstance(self.mass, str):
            if not self.mass:
                self.mass = None
            else:
                self.mass = float(self.mass)
Exemplo n.º 3
0
class KeggData(EntityBase):
    __tablename__ = 'kegg_data'

    kegg_id = Column(String(20), primary_key=True)

    names = Column(ARRAY(TEXT))

    exact_mass = Column(Float)
    mol_weight = Column(Float)

    comments = Column(TEXT)

    # structure info -
    formula = Column(String(256))

    # RefIds - from database_accession.tsv
    #cas_id = Column(String(20))
    chebi_id = Column(String(20), ForeignKey('chebi_data.chebi_id'))
    lipidmaps_id = Column(String(20),
                          ForeignKey('lipidmaps_data.lipidmaps_id'))
    pubchem_id = Column(String(20), ForeignKey('pubchem_data.pubchem_id'))

    ref_etc = Column(JSON_GEN())

    def __init__(self, **kwargs):
        self.kegg_id = kwargs.get('kegg_id')
        self.names = kwargs.get('names')
        self.exact_mass = kwargs.get('exact_mass')
        self.mol_weight = kwargs.get('mol_weight')
        self.comments = kwargs.get('comments')
        self.formula = kwargs.get('formula')
        self.cas_id = kwargs.get('cas_id')
        self.kegg_id = kwargs.get('kegg_id')
        self.chebi_id = kwargs.get('chebi_id')
        self.lipidmaps_id = kwargs.get('lipidmaps_id')
        self.pubchem_id = kwargs.get('pubchem_id')
        self.ref_etc = kwargs.get('ref_etc')

        if isinstance(self.mol_weight, str):
            if not self.mol_weight:
                self.mol_weight = None
            else:
                self.mol_weight = float(self.mol_weight)

        if isinstance(self.exact_mass, str):
            if not self.exact_mass:
                self.exact_mass = None
            else:
                self.exact_mass = float(self.exact_mass)
Exemplo n.º 4
0
class CHEBIData(EntityBase):
    __tablename__ = 'chebi_data'

    # Metadata - from compounds.tsv
    chebi_id = Column(String(20), primary_key=True)
    chebi_id_alt = Column(ARRAY(String(20)))

    #chebi_name = Column(TEXT)
    names = Column(ARRAY(TEXT))

    description = Column(TEXT)
    quality = Column(Integer)

    # Fun facts - from chemical_data.tsv
    charge = Column(Float)
    mass = Column(Float)
    monoisotopic_mass = Column(Float)

    # structure info -
    smiles = Column(TEXT)
    inchi = Column(TEXT)
    inchikey = Column(String(27))
    formula = Column(String(256))

    # from comments.tsv
    comments = Column(TEXT)

    # RefIds - from database_accession.tsv
    #cas_id = Column(String(20))
    kegg_id = Column(String(20), ForeignKey('kegg_data.kegg_id'))
    hmdb_id = Column(String(20), ForeignKey('hmdb_data.hmdb_id'))
    lipidmaps_id = Column(String(20),
                          ForeignKey('lipidmaps_data.lipidmaps_id'))
    pubchem_id = Column(String(20), ForeignKey('pubchem_data.pubchem_id'))

    ref_etc = Column(JSON_GEN())

    def __init__(self, **kwargs):
        self.chebi_id = kwargs.get('chebi_id')
        self.chebi_id_alt = kwargs.get('chebi_id_alt')
        self.chebi_name = kwargs.get('chebi_name')
        self.names = kwargs.get('names')
        self.description = kwargs.get('description')
        self.quality = kwargs.get('quality')
        self.charge = kwargs.get('charge')
        self.mass = kwargs.get('mass')
        self.monoisotopic_mass = kwargs.get('monoisotopic_mass')
        self.smiles = kwargs.get('smiles')
        self.inchi = kwargs.get('inchi')
        self.inchikey = kwargs.get('inchikey')
        self.formula = kwargs.get('formula')
        self.comments = kwargs.get('comments')
        #self.cas_id = kwargs.get('cas_id')
        self.kegg_id = kwargs.get('kegg_id')
        self.hmdb_id = kwargs.get('hmdb_id')
        self.lipidmaps_id = kwargs.get('lipidmaps_id')
        self.pubchem_id = kwargs.get('pubchem_id')
        self.ref_etc = kwargs.get('ref_etc')

        if isinstance(self.monoisotopic_mass, str):
            if not self.monoisotopic_mass:
                self.monoisotopic_mass = None
            else:
                self.monoisotopic_mass = float(self.monoisotopic_mass)

        if isinstance(self.mass, str):
            if not self.mass:
                self.mass = None
            else:
                self.mass = float(self.mass)

        if isinstance(self.charge, str):
            if not self.charge:
                self.charge = None
            else:
                self.charge = float(self.charge)

        if isinstance(self.quality, str):
            if not self.quality:
                self.quality = None
            else:
                self.quality = int(self.quality)
Exemplo n.º 5
0
class ChEBIData(EntityBase):
    __tablename__ = 'chebi_data'

    # Primary Ids
    chebi_id = Column(String(20), primary_key=True)

    # Reference Ids
    # from database_accession.tsv  # todo: add Foreign Keys!
    kegg_id = Column(
        String(24))  #ForeignKey('kegg_data.kegg_id', ondelete='SET NULL'))
    hmdb_id = Column(
        String(24))  #ForeignKey('hmdb_data.hmdb_id', ondelete='SET NULL'))
    lipidmaps_id = Column(String(
        32))  #ForeignKey('lipidmaps_data.lipidmaps_id', ondelete='SET NULL'))
    pubchem_id = Column(String(
        24))  #ForeignKey('pubchem_data.pubchem_id', ondelete='SET NULL'))
    cas_id = Column(String(24))

    ref_etc = Column(JSON_GEN())  # Extra ref Refs
    chemspider_id = Column(String(24))
    metlin_id = Column(String(24))
    pubchem_sub_id = Column(String(24))
    wiki_id = Column(String(256))
    drugbank_id = Column(String(24))
    pdb_id = Column(String(24))
    #pubmed_id = Column(String(24))
    uniprot_id = Column(String(24))

    # Shared metadata
    names = Column(ARRAY(Text))
    description = Column(Text)
    charge = Column(Float)  # from chemical_data.tsv
    mass = Column(Float)
    monoisotopic_mass = Column(Float)

    # Structure
    smiles = Column(Text)
    inchi = Column(Text)
    inchikey = Column(Text)
    formula = Column(Text)

    # Other Fun Facts
    quality = Column(Integer)  # from compounds.tsv
    comments = Column(Text)  # from comments.tsv

    def __init__(self, **kwargs):
        self.chebi_id = kwargs.get('chebi_id')
        self.kegg_id = kwargs.get('kegg_id')
        self.hmdb_id = kwargs.get('hmdb_id')
        self.lipidmaps_id = kwargs.get('lipidmaps_id')
        self.pubchem_id = kwargs.get('pubchem_id')
        self.cas_id = kwargs.get('cas_id')
        self.ref_etc = kwargs.get('ref_etc')
        self.chemspider_id = kwargs.get('chemspider_id')
        self.metlin_id = kwargs.get('metlin_id')
        self.pubchem_sub_id = kwargs.get('pubchem_sub_id')
        self.wiki_id = kwargs.get('wiki_id')
        self.drugbank_id = kwargs.get('drugbank_id')
        self.pdb_id = kwargs.get('pdb_id')
        #self.pubmed_id = kwargs.get('pubmed_id')
        self.uniprot_id = kwargs.get('uniprot_id')
        self.names = kwargs.get('names')
        self.description = kwargs.get('description')
        self.charge = kwargs.get('charge')
        self.mass = kwargs.get('mass')
        self.monoisotopic_mass = kwargs.get('monoisotopic_mass')
        self.smiles = kwargs.get('smiles')
        self.inchi = kwargs.get('inchi')
        self.inchikey = kwargs.get('inchikey')
        self.formula = kwargs.get('formula')
        self.quality = kwargs.get('quality')
        self.comments = kwargs.get('comments')

        if isinstance(self.monoisotopic_mass, str):
            if not self.monoisotopic_mass:
                self.monoisotopic_mass = None
            else:
                self.monoisotopic_mass = float(self.monoisotopic_mass)

        if isinstance(self.mass, str):
            if not self.mass:
                self.mass = None
            else:
                self.mass = float(self.mass)

        if isinstance(self.charge, str):
            if not self.charge:
                self.charge = None
            else:
                self.charge = float(self.charge)

        if isinstance(self.quality, str):
            if not self.quality:
                self.quality = None
            else:
                self.quality = int(self.quality)
Exemplo n.º 6
0
class LipidMapsData(EntityBase):
    __tablename__ = 'lipidmaps_data'

    # Primary Ids
    lipidmaps_id = Column(String(20), primary_key=True)

    # Reference Ids
    kegg_id = Column(
        String(20))  # ForeignKey('kegg_data.kegg_id', ondelete='SET NULL'))
    hmdb_id = Column(
        String(20))  # ForeignKey('hmdb_data.hmdb_id', ondelete='SET NULL'))
    chebi_id = Column(
        String(20))  # ForeignKey('chebi_data.chebi_id', ondelete='SET NULL'))
    pubchem_id = Column(String(
        20))  # ForeignKey('pubchem_data.pubchem_id', ondelete='SET NULL'))
    lipidbank_id = Column(String(20))
    cas_id = Column(String(20))

    ref_etc = Column(JSON_GEN())  # Extra ref Refs
    chemspider_id = Column(String(24))
    metlin_id = Column(String(24))
    pubchem_sub_id = Column(String(24))
    wiki_id = Column(String(256))
    drugbank_id = Column(String(24))
    pdb_id = Column(String(24))
    pubmed_id = Column(String(24))

    # Shared metadata
    names = Column(ARRAY(Text))
    mass = Column(Float)

    # Structure
    smiles = Column(Text)
    inchi = Column(Text)
    inchikey = Column(Text)
    formula = Column(Text)

    # Other Fun Facts
    category = Column(String(32))
    main_class = Column(String(64))
    sub_class = Column(String(128))
    lvl4_class = Column(String(128))

    def __init__(self, **kwargs):
        self.lipidmaps_id = kwargs.get('lipidmaps_id')
        self.kegg_id = kwargs.get('kegg_id')
        self.hmdb_id = kwargs.get('hmdb_id')
        self.chebi_id = kwargs.get('chebi_id')
        self.pubchem_id = kwargs.get('pubchem_id')
        self.lipidbank_id = kwargs.get('lipidbank_id')
        self.cas_id = kwargs.get('cas_id')
        self.ref_etc = kwargs.get('ref_etc')
        self.chemspider_id = kwargs.get('chemspider_id')
        self.metlin_id = kwargs.get('metlin_id')
        self.pubchem_sub_id = kwargs.get('pubchem_sub_id')
        self.wiki_id = kwargs.get('wiki_id')
        self.drugbank_id = kwargs.get('drugbank_id')
        self.pdb_id = kwargs.get('pdb_id')
        self.pubmed_id = kwargs.get('pubmed_id')
        self.names = kwargs.get('names')
        self.mass = kwargs.get('mass')
        self.smiles = kwargs.get('smiles')
        self.inchi = kwargs.get('inchi')
        self.inchikey = kwargs.get('inchikey')
        self.formula = kwargs.get('formula')
        self.category = kwargs.get('category')
        self.main_class = kwargs.get('main_class')
        self.sub_class = kwargs.get('sub_class')
        self.lvl4_class = kwargs.get('lvl4_class')

        if isinstance(self.mass, str):
            if not self.mass:
                self.mass = None
            else:
                self.mass = float(self.mass)
Exemplo n.º 7
0
class UserMixin(FlaskUserMixin):
    # login
    uid = Column(GUID(), primary_key=True)
    username = Column(String(32))

    # profile
    admin = Column(Boolean(), default=False)
    face = Column(JSON_GEN())
    points = Column(SmallInteger)
    last_active = Column(TIMESTAMP,
                         server_default=func.now(),
                         onupdate=func.current_timestamp())

    # oauth
    access_token = Column(String(255), unique=True, nullable=False)
    refresh_token = Column(String(255), index=True)
    issued_at = Column(Integer, nullable=False, default=lambda: int(time()))
    expires_in = Column(Integer, nullable=False, default=0)

    def get_id(self):
        return str(self.uid) if self.uid else None

    @property
    def expires_at(self):
        if self.issued_at is None or self.expires_in is None:
            # bugfix for records that have no expiry
            return 0

        return self.issued_at + self.expires_in

    @property
    def is_active(self):
        return True

    @property
    def is_authenticated(self):
        return self.uid is not None

    @property
    def is_anonymous(self):
        return False

    def get_user_id(self):
        # used for oauth2
        return self.uid

    def __hash__(self):
        return hash(self.uid)

    def __repr__(self):
        return "{}({}..)".format(self.username, str(self.uid)[0:4])

    def update_token(self, th):
        self.access_token = th.access_token
        self.issued_at = th.issued_at
        self.expires_in = th.expires_in

        if hasattr(th, 'refresh_token'):
            self.refresh_token = th.refresh_token

    def update_user(self, user):
        if self.access_token != user.access_token and user.access_token is not None:
            self.update_token(user)

        if hasattr(user, 'refresh_token'):
            self.refresh_token = user.refresh_token

        if user.username != self.username and user.username is not None:
            self.username = user.username

        if user.points != self.points and user.points is not None:
            self.points = user.points

        if user.face != self.face and user.face is not None:
            self.face = user.face

        if user.admin != self.admin and user.admin is not None:
            self.admin = user.admin

        if user.last_active != self.last_active and user.last_active is not None:
            self.last_active = user.last_active
Exemplo n.º 8
0
class PubChemData(EntityBase):
    __tablename__ = 'pubchem_data'

    # Primary Ids
    pubchem_id = Column(String(20), primary_key=True)
    #pubchem_sub_id = Column(String(24)) #ForeignKey('pubchem_substrate_data.pubchem_id', ondelete='SET NULL'))

    # Reference Ids
    chebi_id = Column(
        String(24))  #ForeignKey('chebi_data.chebi_id', ondelete='SET NULL'))
    kegg_id = Column(
        String(24))  #ForeignKey('kegg_data.kegg_id', ondelete='SET NULL'))
    hmdb_id = Column(
        String(24))  #ForeignKey('hmdb_data.hmdb_id', ondelete='SET NULL'))
    cas_id = Column(String(24))

    ref_etc = Column(JSON_GEN())  # Extra ref Refs
    chemspider_id = Column(String(24))
    #metlin_id = Column(String(24))
    #wiki_id = Column(String(24))
    #drugbank_id = Column(String(24))
    #pdb_id = Column(String(24))
    #pubmed_id = Column(String(24))

    # Shared metadata
    names = Column(ARRAY(Text))
    mass = Column(Float)
    monoisotopic_mass = Column(Float)

    # Structure
    smiles = Column(ARRAY(Text))
    inchi = Column(Text)
    inchikey = Column(String(27))
    formula = Column(String(256))

    # Other Fun Facts
    logp = Column(Float)

    def __init__(self, **kwargs):
        self.pubchem_id = kwargs.get('pubchem_id')
        self.pubchem_sub_id = kwargs.get('pubchem_sub_id')
        self.chebi_id = kwargs.get('chebi_id')
        self.kegg_id = kwargs.get('kegg_id')
        self.hmdb_id = kwargs.get('hmdb_id')
        self.cas_id = kwargs.get('cas_id')
        self.ref_etc = kwargs.get('ref_etc')
        self.chemspider_id = kwargs.get('chemspider_id')
        self.metlin_id = kwargs.get('metlin_id')
        self.wiki_id = kwargs.get('wiki_id')
        self.drugbank_id = kwargs.get('drugbank_id')
        self.pdb_id = kwargs.get('pdb_id')
        self.pubmed_id = kwargs.get('pubmed_id')
        self.names = kwargs.get('names')
        self.mass = kwargs.get('mass')
        self.weight = kwargs.get('weight')
        self.monoisotopic_mass = kwargs.get('monoisotopic_mass')
        self.smiles = kwargs.get('smiles')
        self.inchi = kwargs.get('inchi')
        self.inchikey = kwargs.get('inchikey')
        self.formula = kwargs.get('formula')
        self.logp = kwargs.get('logp')

        print("TODO: pubchem handle synonyms and description")
Exemplo n.º 9
0
class HMDBData(EntityBase):
    __tablename__ = 'hmdb_data'

    # Primary Ids
    hmdb_id = Column(String(20), primary_key=True)

    # Reference Ids
    kegg_id = Column(
        String(24))  #ForeignKey('kegg_data.kegg_id', ondelete='SET NULL'))
    pubchem_id = Column(String(
        24))  #ForeignKey('pubchem_data.pubchem_id'), ondelete='SET NULL')
    chebi_id = Column(
        String(24))  #ForeignKey('chebi_data.chebi_id'), ondelete='SET NULL')
    cas_id = Column(String(24))

    ref_etc = Column(JSON_GEN())  # Extra ref Refs
    chemspider_id = Column(String(24))
    metlin_id = Column(String(24))
    pubchem_sub_id = Column(String(24))
    wiki_id = Column(String(256))
    drugbank_id = Column(String(24))
    pdb_id = Column(String(24))
    pubmed_id = Column(String(24))

    # Shared metadata
    names = Column(ARRAY(Text))
    description = Column(Text)
    avg_mol_weight = Column(Float)
    monoisotopic_mol_weight = Column(Float)

    # Structure
    formula = Column(Text)
    smiles = Column(Text)
    inchi = Column(Text)
    inchikey = Column(Text)

    # Other Fun Facts
    state = Column(String(32))

    # biofluid_locations = Column(ARRAY(String(64)))
    # tissue_locations = Column(ARRAY(String(64)))
    #
    # # Complex data
    # taxonomy = Column(JSON_GEN)
    # ontology = Column(JSON_GEN)
    # proteins = Column(JSON_GEN)
    # diseases = Column(JSON_GEN)

    # synthesis_reference = Column(TEXT)

    def __init__(self, **kwargs):
        self.hmdb_id = kwargs.get('hmdb_id')
        self.hmdb_id_alt = kwargs.get('hmdb_id_alt')
        self.kegg_id = kwargs.get('kegg_id')
        self.pubchem_id = kwargs.get('pubchem_id')
        self.chebi_id = kwargs.get('chebi_id')
        self.cas_id = kwargs.get('cas_id')
        self.ref_etc = kwargs.get('ref_etc')
        self.chemspider_id = kwargs.get('chemspider_id')
        self.metlin_id = kwargs.get('metlin_id')
        self.pubchem_sub_id = kwargs.get('pubchem_sub_id')
        self.wiki_id = kwargs.get('wiki_id')
        self.drugbank_id = kwargs.get('drugbank_id')
        self.pdb_id = kwargs.get('pdb_id')
        self.pubmed_id = kwargs.get('pubmed_id')
        self.names = kwargs.get('names')
        self.description = kwargs.get('description')
        self.avg_mol_weight = kwargs.get('avg_mol_weight')
        self.monoisotopic_mol_weight = kwargs.get('monoisotopic_mol_weight')
        self.formula = kwargs.get('formula')
        self.smiles = kwargs.get('smiles')
        self.inchi = kwargs.get('inchi')
        self.inchikey = kwargs.get('inchikey')
        self.state = kwargs.get('state')

        if isinstance(self.avg_mol_weight, str):
            if not self.avg_mol_weight:
                self.avg_mol_weight = None
            else:
                self.avg_mol_weight = str(self.avg_mol_weight)

        if isinstance(self.monoisotopic_mol_weight, str):
            if not self.monoisotopic_mol_weight:
                self.monoisotopic_mol_weight = None
            else:
                self.monoisotopic_mol_weight = str(
                    self.monoisotopic_mol_weight)