Skip to content

API Reference

biokb_coconut.db.models

This module contains the SQLAlchemy ORM models for the biokb_coconut database.

Each class in this module represents a table in the database, with attributes corresponding to the columns of the table. Relationships between tables are defined using SQLAlchemy's relationship function.

CAS

Bases: Base

Class definition for table cas.

Attributes:

Name Type Description
id int

Primary key.

number str

Unique CAS number.

compounds list[Compound]

List of compounds associated with this CAS number.

Source code in src/biokb_coconut/db/models.py
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
class CAS(Base):
    """Class definition for table cas.

    Attributes:
        id (int): Primary key.
        number (str): Unique CAS number.
        compounds (list[Compound]): List of compounds associated with this CAS number.
    """

    __tablename__ = Base.table_prefix + "cas"

    id = Column(Integer, primary_key=True)
    number = Column(
        String(255).with_variant(String(255, collation="utf8mb4_bin"), "mysql"),
        unique=True,
    )
    compounds: Mapped[list["Compound"]] = relationship(
        secondary=CompoundCAS.__table__, back_populates="cas_numbers"
    )

    def __repr__(self) -> str:
        return f"<CAS(id={self.id}, number={self.number})>"

ChemicalClass

Bases: Base, OnlyName

Chemical Class model.

Attributes:

Name Type Description
id int

Primary key.

name str

Unique name of the chemical class.

compounds list[Compound]

List of compounds associated with this class.

Source code in src/biokb_coconut/db/models.py
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
class ChemicalClass(Base, OnlyName):
    """Chemical Class model.

    Attributes:
        id (int): Primary key.
        name (str): Unique name of the chemical class.
        compounds (list[Compound]): List of compounds associated with this class.
    """

    __tablename__ = Base.table_prefix + "chemical_class"

    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str] = mapped_column(String(255), unique=True)

    compounds: Mapped[list["Compound"]] = relationship(back_populates="chemical_class")

    @property
    def compound_identifiers(self) -> list[str]:
        return [compound.identifier for compound in self.compounds]

    def __repr__(self) -> str:
        return f"<ChemicalClass(id={self.id}, name={self.name})>"

ChemicalSubClass

Bases: Base, OnlyName

Chemical Sub-Class model.

Attributes:

Name Type Description
id int

Primary key.

name str

Unique name of the chemical sub-class.

compounds list[Compound]

List of compounds associated with this sub-class.

Source code in src/biokb_coconut/db/models.py
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
class ChemicalSubClass(Base, OnlyName):
    """Chemical Sub-Class model.

    Attributes:
        id (int): Primary key.
        name (str): Unique name of the chemical sub-class.
        compounds (list[Compound]): List of compounds associated with this sub-class.
    """

    __tablename__ = Base.table_prefix + "chemical_sub_class"

    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str] = mapped_column(String(255), unique=True)

    compounds: Mapped[list["Compound"]] = relationship(
        back_populates="chemical_sub_class"
    )

    @property
    def compound_identifiers(self) -> list[str]:
        return [compound.identifier for compound in self.compounds]

    def __repr__(self) -> str:
        return f"<ChemicalSubClass(id={self.id}, name={self.name})>"

ChemicalSuperClass

Bases: Base, OnlyName

Chemical Super-Class model.

Attributes:

Name Type Description
id int

Primary key.

name str

Unique name of the chemical super-class.

compounds list[Compound]

List of compounds associated with this super-class.

Source code in src/biokb_coconut/db/models.py
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
class ChemicalSuperClass(Base, OnlyName):
    """Chemical Super-Class model.

    Attributes:
        id (int): Primary key.
        name (str): Unique name of the chemical super-class.
        compounds (list[Compound]): List of compounds associated with this super-class.
    """

    __tablename__ = Base.table_prefix + "chemical_super_class"

    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str] = mapped_column(String(255), unique=True)

    compounds: Mapped[list["Compound"]] = relationship(
        back_populates="chemical_super_class"
    )

    @property
    def compound_identifiers(self) -> list[str]:
        return [compound.identifier for compound in self.compounds]

    def __repr__(self) -> str:
        return f"<ChemicalSuperClass(id={self.id}, name={self.name})>"

Collection

Bases: Base

Class definition for table collection.

Attributes:

Name Type Description
id int

Primary key.

name str

Unique name of the collection.

compounds list[Compound]

List of compounds associated with this collection.

Source code in src/biokb_coconut/db/models.py
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
class Collection(Base):
    """Class definition for table collection.

    Attributes:
        id (int): Primary key.
        name (str): Unique name of the collection.
        compounds (list[Compound]): List of compounds associated with this collection.
    """

    __tablename__ = Base.table_prefix + "collection"

    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str] = mapped_column(
        String(255).with_variant(String(255, collation="utf8mb4_bin"), "mysql"),
        unique=True,
    )
    compounds: Mapped[list["Compound"]] = relationship(
        secondary=CompoundCollection.__table__, back_populates="collections"
    )

    @property
    def compound_identifiers(self) -> list[str]:
        return [compound.identifier for compound in self.compounds]

    def __repr__(self) -> str:
        return f"<Collection(id={self.id}, name={self.name})>"

Compound

Bases: Base

Class definition for table compound.

Attributes:

Name Type Description
id int

Primary key.

identifier str

Unique identifier for the compound.

canonical_smiles str

Canonical SMILES representation of the compound.

standard_inchi str

Standard InChI representation of the compound.

standard_inchi_key str

Standard InChI Key of the compound.

name Optional[str]

Name of the compound.

iupac_name Optional[str]

IUPAC name of the compound.

annotation_level int

Annotation level of the compound.

total_atom_count int

Total atom count of the compound.

heavy_atom_count int

Heavy atom count of the compound.

molecular_weight float

Molecular weight of the compound.

exact_molecular_weight float

Exact molecular weight of the compound.

molecular_formula str

Molecular formula of the compound.

alogp float

ALogP value of the compound.

topological_polar_surface_area float

Topological polar surface area of the compound.

rotatable_bond_count int

Rotatable bond count of the compound.

hydrogen_bond_acceptors int

Number of hydrogen bond acceptors.

hydrogen_bond_donors int

Number of hydrogen bond donors.

hydrogen_bond_acceptors_lipinski int

Number of hydrogen bond acceptors according to Lipinski's rule.

hydrogen_bond_donors_lipinski int

Number of hydrogen bond donors according to Lipinski's rule.

lipinski_rule_of_five_violations int

Number of Lipinski's rule of five violations.

aromatic_rings_count int

Aromatic rings count of the compound.

qed_drug_likeliness float

QED drug-likeliness score of the compound.

formal_charge int

Formal charge of the compound.

fractioncsp3 float

Fraction of sp3 hybridized carbons in the compound.

number_of_minimal_rings int

Number of minimal rings in the compound.

van_der_walls_volume Optional[float]

Van der Waals volume of the compound.

contains_sugar Optional[bool]

Indicates if the compound contains sugar.

contains_ring_sugars bool

Indicates if the compound contains ring sugars.

contains_linear_sugars bool

Indicates if the compound contains linear sugars.

murcko_framework Optional[str]

Murcko framework of the compound.

np_likeness float

Natural product-likeness score of the compound.

np_classifier_is_glycoside Optional[bool]

Indicates if the compound is classified as a glycoside by the NP classifier.

chemical_class_id Optional[int]

Foreign key to the chemical class table.

chemical_sub_class_id Optional[int]

Foreign key to the chemical sub-class table.

direct_parent_classification_id Optional[int]

Foreign key to the direct parent classification table.

chemical_super_class_id Optional[int]

Foreign key to the chemical super-class table.

np_classifier_pathway_id Optional[int]

Foreign key to the NP classifier pathway table.

np_classifier_superclass_id Optional[int]

Foreign key to the NP classifier superclass table.

np_classifier_class_id Optional[int]

Foreign key to the NP classifier class table.

chemical_class Optional[ChemicalClass]

Relationship to the chemical class.

chemical_sub_class Optional[ChemicalSubClass]

Relationship to the chemical sub-class.

direct_parent_classification Optional[DirectParentClassification]

Relationship to the direct parent classification.

chemical_super_class Optional[ChemicalSuperClass]

Relationship to the chemical super-class.

np_classifier_pathway Optional[NpClassifierPathway]

Relationship to the NP classifier pathway.

np_classifier_superclass Optional[NpClassifierSuperclass]

Relationship to the NP classifier superclass.

np_classifier_class Optional[NpClassifierClass]

Relationship to the NP classifier class.

organisms list[Organism]

List of organisms associated with the compound.

collections list[Collection]

List of collections associated with the compound.

dois list[DOI]

List of DOIs associated with the compound.

synonyms list[Synonym]

List of synonyms associated with the compound.

cas_numbers list[CAS]

List of CAS numbers associated with the compound.

Source code in src/biokb_coconut/db/models.py
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
class Compound(Base):
    """Class definition for table compound.

    Attributes:
        id (int): Primary key.
        identifier (str): Unique identifier for the compound.
        canonical_smiles (str): Canonical SMILES representation of the compound.
        standard_inchi (str): Standard InChI representation of the compound.
        standard_inchi_key (str): Standard InChI Key of the compound.
        name (Optional[str]): Name of the compound.
        iupac_name (Optional[str]): IUPAC name of the compound.
        annotation_level (int): Annotation level of the compound.
        total_atom_count (int): Total atom count of the compound.
        heavy_atom_count (int): Heavy atom count of the compound.
        molecular_weight (float): Molecular weight of the compound.
        exact_molecular_weight (float): Exact molecular weight of the compound.
        molecular_formula (str): Molecular formula of the compound.
        alogp (float): ALogP value of the compound.
        topological_polar_surface_area (float): Topological polar surface area of the compound.
        rotatable_bond_count (int): Rotatable bond count of the compound.
        hydrogen_bond_acceptors (int): Number of hydrogen bond acceptors.
        hydrogen_bond_donors (int): Number of hydrogen bond donors.
        hydrogen_bond_acceptors_lipinski (int): Number of hydrogen bond acceptors according to Lipinski's rule.
        hydrogen_bond_donors_lipinski (int): Number of hydrogen bond donors according to Lipinski's rule.
        lipinski_rule_of_five_violations (int): Number of Lipinski's rule of five violations.
        aromatic_rings_count (int): Aromatic rings count of the compound.
        qed_drug_likeliness (float): QED drug-likeliness score of the compound.
        formal_charge (int): Formal charge of the compound.
        fractioncsp3 (float): Fraction of sp3 hybridized carbons in the compound.
        number_of_minimal_rings (int): Number of minimal rings in the compound.
        van_der_walls_volume (Optional[float]): Van der Waals volume of the compound.
        contains_sugar (Optional[bool]): Indicates if the compound contains sugar.
        contains_ring_sugars (bool): Indicates if the compound contains ring sugars.
        contains_linear_sugars (bool): Indicates if the compound contains linear sugars.
        murcko_framework (Optional[str]): Murcko framework of the compound.
        np_likeness (float): Natural product-likeness score of the compound.
        np_classifier_is_glycoside (Optional[bool]): Indicates if the compound is classified as a glycoside by the NP classifier.
        chemical_class_id (Optional[int]): Foreign key to the chemical class table.
        chemical_sub_class_id (Optional[int]): Foreign key to the chemical sub-class table.
        direct_parent_classification_id (Optional[int]): Foreign key to the direct parent classification table.
        chemical_super_class_id (Optional[int]): Foreign key to the chemical super-class table.
        np_classifier_pathway_id (Optional[int]): Foreign key to the NP classifier pathway table.
        np_classifier_superclass_id (Optional[int]): Foreign key to the NP classifier superclass table.
        np_classifier_class_id (Optional[int]): Foreign key to the NP classifier class table.
        chemical_class (Optional[ChemicalClass]): Relationship to the chemical class.
        chemical_sub_class (Optional[ChemicalSubClass]): Relationship to the chemical sub-class.
        direct_parent_classification (Optional[DirectParentClassification]): Relationship to the direct parent classification.
        chemical_super_class (Optional[ChemicalSuperClass]): Relationship to the chemical super-class.
        np_classifier_pathway (Optional[NpClassifierPathway]): Relationship to the NP classifier pathway.
        np_classifier_superclass (Optional[NpClassifierSuperclass]): Relationship to the NP classifier superclass.
        np_classifier_class (Optional[NpClassifierClass]): Relationship to the NP classifier class.
        organisms (list[Organism]): List of organisms associated with the compound.
        collections (list[Collection]): List of collections associated with the compound.
        dois (list[DOI]): List of DOIs associated with the compound.
        synonyms (list[Synonym]): List of synonyms associated with the compound.
        cas_numbers (list[CAS]): List of CAS numbers associated with the compound.
    """

    __tablename__ = Base.table_prefix + "compound"

    id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
    identifier: Mapped[str] = mapped_column(String(255), unique=True, nullable=False)
    canonical_smiles: Mapped[str] = mapped_column(Text)
    standard_inchi: Mapped[str] = mapped_column(Text)
    standard_inchi_key: Mapped[str] = mapped_column(String(32))
    name: Mapped[Optional[str]] = mapped_column(String(10000), nullable=True)
    iupac_name: Mapped[Optional[str]] = mapped_column(Text)
    annotation_level: Mapped[int]
    total_atom_count: Mapped[int]
    heavy_atom_count: Mapped[int]
    molecular_weight: Mapped[Decimal] = mapped_column(Numeric(8, 2))
    exact_molecular_weight: Mapped[Decimal] = mapped_column(Numeric(11, 5))
    molecular_formula: Mapped[str] = mapped_column(String(255))
    alogp: Mapped[Decimal] = mapped_column(Numeric(6, 2))
    topological_polar_surface_area: Mapped[Decimal] = mapped_column(Numeric(8, 2))
    rotatable_bond_count: Mapped[int]
    hydrogen_bond_acceptors: Mapped[int]
    hydrogen_bond_donors: Mapped[int]
    hydrogen_bond_acceptors_lipinski: Mapped[int]
    hydrogen_bond_donors_lipinski: Mapped[int]
    lipinski_rule_of_five_violations: Mapped[int]
    aromatic_rings_count: Mapped[int]
    qed_drug_likeliness: Mapped[Decimal] = mapped_column(Numeric(5, 2))
    formal_charge: Mapped[int]
    fractioncsp3: Mapped[Decimal] = mapped_column(Numeric(5, 2))
    number_of_minimal_rings: Mapped[int]
    van_der_walls_volume: Mapped[Optional[Decimal]] = mapped_column(Numeric(8, 2))
    contains_sugar: Mapped[Optional[bool]]
    contains_ring_sugars: Mapped[bool]
    contains_linear_sugars: Mapped[bool]
    murcko_framework: Mapped[Optional[str]] = mapped_column(Text)
    np_likeness: Mapped[Decimal] = mapped_column(Numeric(5, 2))
    np_classifier_is_glycoside: Mapped[Optional[bool]]
    number_of_organisms: Mapped[Optional[int]] = mapped_column(
        Integer, default=0, server_default=text("0")
    )

    # foreign keys to classification tables
    chemical_class_id: Mapped[Optional[int]] = mapped_column(
        ForeignKey(Base.table_prefix + "chemical_class.id")
    )
    chemical_sub_class_id: Mapped[Optional[int]] = mapped_column(
        ForeignKey(Base.table_prefix + "chemical_sub_class.id")
    )
    direct_parent_classification_id: Mapped[Optional[int]] = mapped_column(
        ForeignKey(Base.table_prefix + "direct_parent_classification.id")
    )
    chemical_super_class_id: Mapped[Optional[int]] = mapped_column(
        ForeignKey(Base.table_prefix + "chemical_super_class.id")
    )
    np_classifier_pathway_id: Mapped[Optional[int]] = mapped_column(
        ForeignKey(Base.table_prefix + "np_classifier_pathway.id")
    )
    np_classifier_superclass_id: Mapped[Optional[int]] = mapped_column(
        ForeignKey(Base.table_prefix + "np_classifier_superclass.id")
    )
    np_classifier_class_id: Mapped[Optional[int]] = mapped_column(
        ForeignKey(Base.table_prefix + "np_classifier_class.id")
    )

    # relationships
    chemical_class: Mapped[Optional["ChemicalClass"]] = relationship(
        back_populates="compounds"
    )
    chemical_sub_class: Mapped[Optional["ChemicalSubClass"]] = relationship(
        back_populates="compounds"
    )
    direct_parent_classification: Mapped[Optional["DirectParentClassification"]] = (
        relationship(back_populates="compounds")
    )
    chemical_super_class: Mapped[Optional["ChemicalSuperClass"]] = relationship(
        back_populates="compounds"
    )
    np_classifier_pathway: Mapped[Optional["NpClassifierPathway"]] = relationship(
        back_populates="compounds"
    )
    np_classifier_superclass: Mapped[Optional["NpClassifierSuperclass"]] = relationship(
        back_populates="compounds"
    )
    np_classifier_class: Mapped[Optional["NpClassifierClass"]] = relationship(
        back_populates="compounds"
    )
    # many-to-many relationships
    organisms: Mapped[list["Organism"]] = relationship(
        secondary=CompoundOrganism.__table__, back_populates="compounds"
    )
    collections: Mapped[list["Collection"]] = relationship(
        secondary=CompoundCollection.__table__, back_populates="compounds"
    )
    dois: Mapped[list["DOI"]] = relationship(
        secondary=CompoundDOI.__table__, back_populates="compounds"
    )
    synonyms: Mapped[list["Synonym"]] = relationship(
        secondary=CompoundSynonym.__table__, back_populates="compounds"
    )
    cas_numbers: Mapped[list["CAS"]] = relationship(
        secondary=CompoundCAS.__table__, back_populates="compounds"
    )

    @property
    def organism_names(self) -> list[str]:
        return [organism.name for organism in self.organisms]

    def __repr__(self) -> str:
        return (
            f"<Compound(id={self.id}, name={self.name}, identifier={self.identifier})>"
        )

    __table_args__ = (
        Index(
            f"ix_{__tablename__}__name",
            "name",
            mysql_length=768,
        ),
    )

CompoundCAS

Bases: Base

Joining table for Compound and CAS many-to-many relationship.

Attributes:

Name Type Description
compound_id int

Foreign key to the compound table.

cas_number_id int

Foreign key to the cas table.

Source code in src/biokb_coconut/db/models.py
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
class CompoundCAS(Base):
    """Joining table for Compound and CAS many-to-many relationship.

    Attributes:
        compound_id (int): Foreign key to the compound table.
        cas_number_id (int): Foreign key to the cas table.
    """

    __tablename__ = Base.table_prefix + "compound_cas"

    compound_id: Mapped[int] = mapped_column(
        ForeignKey(Base.table_prefix + "compound.id"), primary_key=True
    )
    cas_number_id: Mapped[int] = mapped_column(
        ForeignKey(Base.table_prefix + "cas.id"), primary_key=True
    )

CompoundCollection

Bases: Base

Joining table for Compound and Collection many-to-many relationship.

Attributes:

Name Type Description
compound_id int

Foreign key to the compound table.

collection_id int

Foreign key to the collection table.

Source code in src/biokb_coconut/db/models.py
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class CompoundCollection(Base):
    """Joining table for Compound and Collection many-to-many relationship.

    Attributes:
        compound_id (int): Foreign key to the compound table.
        collection_id (int): Foreign key to the collection table.
    """

    __tablename__ = Base.table_prefix + "compound__collection"

    compound_id: Mapped[int] = mapped_column(
        ForeignKey(Base.table_prefix + "compound.id"), primary_key=True
    )
    collection_id: Mapped[int] = mapped_column(
        ForeignKey(Base.table_prefix + "collection.id"), primary_key=True
    )

CompoundDOI

Bases: Base

Joining table for Compound and DOI many-to-many relationship.

Attributes:

Name Type Description
compound_id int

Foreign key to the compound table.

doi_id int

Foreign key to the doi table.

Source code in src/biokb_coconut/db/models.py
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
class CompoundDOI(Base):
    """Joining table for Compound and DOI many-to-many relationship.

    Attributes:
        compound_id (int): Foreign key to the compound table.
        doi_id (int): Foreign key to the doi table.
    """

    __tablename__ = Base.table_prefix + "compound_doi"

    compound_id: Mapped[int] = mapped_column(
        ForeignKey(Base.table_prefix + "compound.id"), primary_key=True
    )
    doi_id: Mapped[int] = mapped_column(
        ForeignKey(Base.table_prefix + "doi.id"), primary_key=True
    )

CompoundOrganism

Bases: Base

Joining table for Compound and Organism many-to-many relationship.

Attributes:

Name Type Description
compound_id int

Foreign key to the compound table.

organism_id int

Foreign key to the organism table.

Source code in src/biokb_coconut/db/models.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class CompoundOrganism(Base):
    """Joining table for Compound and Organism many-to-many relationship.

    Attributes:
        compound_id (int): Foreign key to the compound table.
        organism_id (int): Foreign key to the organism table.
    """

    __tablename__ = Base.table_prefix + "compound__organism"

    compound_id: Mapped[int] = mapped_column(
        ForeignKey(Base.table_prefix + "compound.id"), primary_key=True
    )
    organism_id: Mapped[int] = mapped_column(
        ForeignKey(Base.table_prefix + "organism.id"), primary_key=True
    )

CompoundSynonym

Bases: Base

Joining table for Compound and Synonym many-to-many relationship.

Attributes:

Name Type Description
compound_id int

Foreign key to the compound table.

synonym_id int

Foreign key to the synonym table.

Source code in src/biokb_coconut/db/models.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
class CompoundSynonym(Base):
    """Joining table for Compound and Synonym many-to-many relationship.

    Attributes:
        compound_id (int): Foreign key to the compound table.
        synonym_id (int): Foreign key to the synonym table.
    """

    __tablename__ = Base.table_prefix + "compound__synonym"

    compound_id: Mapped[int] = mapped_column(
        ForeignKey(Base.table_prefix + "compound.id"), primary_key=True
    )
    synonym_id: Mapped[int] = mapped_column(
        ForeignKey(Base.table_prefix + "synonym.id"), primary_key=True
    )

DOI

Bases: Base

Class definition for table doi.

Attributes:

Name Type Description
id int

Primary key.

identifier str

Unique identifier for the DOI.

compounds list[Compound]

List of compounds associated with this DOI.

Source code in src/biokb_coconut/db/models.py
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
class DOI(Base):
    """Class definition for table doi.

    Attributes:
        id (int): Primary key.
        identifier (str): Unique identifier for the DOI.
        compounds (list[Compound]): List of compounds associated with this DOI.
    """

    __tablename__ = Base.table_prefix + "doi"

    id: Mapped[int] = mapped_column(primary_key=True)
    identifier: Mapped[str] = mapped_column(
        String(255).with_variant(String(255, collation="utf8mb4_bin"), "mysql"),
        unique=True,
    )
    compounds: Mapped[list["Compound"]] = relationship(
        secondary=CompoundDOI.__table__, back_populates="dois"
    )

    def __repr__(self) -> str:
        return f"<DOI(id={self.id}, identifier={self.identifier})>"

DirectParentClassification

Bases: Base, OnlyName

Direct Parent Classification model.

Attributes:

Name Type Description
id int

Primary key.

name str

Unique name of the direct parent classification.

compounds list[Compound]

List of compounds associated with this classification.

Source code in src/biokb_coconut/db/models.py
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
class DirectParentClassification(Base, OnlyName):
    """Direct Parent Classification model.

    Attributes:
        id (int): Primary key.
        name (str): Unique name of the direct parent classification.
        compounds (list[Compound]): List of compounds associated with this classification.
    """

    __tablename__ = Base.table_prefix + "direct_parent_classification"

    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str] = mapped_column(String(255), unique=True)

    compounds: Mapped[list["Compound"]] = relationship(
        back_populates="direct_parent_classification"
    )

    @property
    def compound_identifiers(self) -> list[str]:
        return [compound.identifier for compound in self.compounds]

    def __repr__(self) -> str:
        return f"<DirectParentClassification(id={self.id}, name={self.name})>"

NpClassifierClass

Bases: Base, OnlyName

Natural Product Classifier Class model.

Attributes:

Name Type Description
id int

Primary key.

name str

Unique name of the NP classifier class.

compounds list[Compound]

List of compounds associated with this class.

Source code in src/biokb_coconut/db/models.py
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
class NpClassifierClass(Base, OnlyName):
    """Natural Product Classifier Class model.

    Attributes:
        id (int): Primary key.
        name (str): Unique name of the NP classifier class.
        compounds (list[Compound]): List of compounds associated with this class.
    """

    __tablename__ = Base.table_prefix + "np_classifier_class"

    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str] = mapped_column(String(255), unique=True)

    compounds: Mapped[list["Compound"]] = relationship(
        back_populates="np_classifier_class"
    )

    @property
    def compound_identifiers(self) -> list[str]:
        return [compound.identifier for compound in self.compounds]

    def __repr__(self) -> str:
        return f"<NpClassifierClass(id={self.id}, name={self.name})>"

NpClassifierPathway

Bases: Base, OnlyName

Natural Product Classifier Pathway model.

Attributes:

Name Type Description
id int

Primary key.

name str

Unique name of the NP classifier pathway.

compounds list[Compound]

List of compounds associated with this pathway.

Source code in src/biokb_coconut/db/models.py
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
class NpClassifierPathway(Base, OnlyName):
    """Natural Product Classifier Pathway model.

    Attributes:
        id (int): Primary key.
        name (str): Unique name of the NP classifier pathway.
        compounds (list[Compound]): List of compounds associated with this pathway.
    """

    __tablename__ = Base.table_prefix + "np_classifier_pathway"

    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str] = mapped_column(String(255), unique=True)

    compounds: Mapped[list["Compound"]] = relationship(
        back_populates="np_classifier_pathway"
    )

    @property
    def compound_identifiers(self) -> list[str]:
        return [compound.identifier for compound in self.compounds]

    def __repr__(self) -> str:
        return f"<NpClassifierPathway(id={self.id}, name={self.name})>"

NpClassifierSuperclass

Bases: Base, OnlyName

Natural Product Classifier Superclass model.

Attributes:

Name Type Description
id int

Primary key.

name str

Unique name of the NP classifier superclass.

compounds list[Compound]

List of compounds associated with this superclass.

Source code in src/biokb_coconut/db/models.py
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
class NpClassifierSuperclass(Base, OnlyName):
    """Natural Product Classifier Superclass model.

    Attributes:
        id (int): Primary key.
        name (str): Unique name of the NP classifier superclass.
        compounds (list[Compound]): List of compounds associated with this superclass.
    """

    __tablename__ = Base.table_prefix + "np_classifier_superclass"

    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str] = mapped_column(String(255), unique=True)

    compounds: Mapped[list["Compound"]] = relationship(
        back_populates="np_classifier_superclass"
    )

    @property
    def compound_identifiers(self) -> list[str]:
        return [compound.identifier for compound in self.compounds]

    def __repr__(self) -> str:
        return f"<NpClassifierSuperclass(id={self.id}, name={self.name})>"

Organism

Bases: Base

Class definition for table organism.

Attributes:

Name Type Description
id int

Primary key.

name str

Name of the organism.

tax_id Optional[int]

NCBI taxonomy identifier.

wcvp_id Optional[int]

WCVP identifier.

powo_id Optional[str]

POWO identifier.

compounds list[Compound]

List of compounds associated with this organism.

Source code in src/biokb_coconut/db/models.py
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
class Organism(Base):
    """Class definition for table organism.

    Attributes:
        id (int): Primary key.
        name (str): Name of the organism.
        tax_id (Optional[int]): NCBI taxonomy identifier.
        wcvp_id (Optional[int]): WCVP identifier.
        powo_id (Optional[str]): POWO identifier.
        compounds (list[Compound]): List of compounds associated with this organism.
    """

    __tablename__ = Base.table_prefix + "organism"

    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str] = mapped_column(String(1000))
    tax_id: Mapped[Optional[int]] = mapped_column(index=True)
    wcvp_id: Mapped[Optional[int]]
    powo_id: Mapped[Optional[str]] = mapped_column(String(255))
    compounds: Mapped[list["Compound"]] = relationship(
        secondary=CompoundOrganism.__table__, back_populates="organisms"
    )

    @property
    def compound_identifiers(self) -> list[str]:
        return [compound.identifier for compound in self.compounds]

    __table_args__ = (
        Index(
            f"ix_{__tablename__}__name",
            "name",
            mysql_length=768,
        ),
    )

    def __repr__(self) -> str:
        return f"<Organism(id={self.id}, name={self.name}, tax_id={self.tax_id})>"

Synonym

Bases: Base

Class definition for table synonym.

Attributes:

Name Type Description
id int

Primary key.

name str

Unique name of the synonym.

compounds list[Compound]

List of compounds associated with this synonym.

Source code in src/biokb_coconut/db/models.py
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
class Synonym(Base):
    """Class definition for table synonym.

    Attributes:
        id (int): Primary key.
        name (str): Unique name of the synonym.
        compounds (list[Compound]): List of compounds associated with this synonym.
    """

    __tablename__ = Base.table_prefix + "synonym"

    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str] = mapped_column(
        String(1000).with_variant(String(1000, collation="utf8mb4_bin"), "mysql")
    )

    @property
    def compound_identifiers(self) -> list[str]:
        return [compound.identifier for compound in self.compounds]

    # m2m relationship
    compounds: Mapped[list["Compound"]] = relationship(
        secondary=CompoundSynonym.__table__, back_populates="synonyms"
    )
    __table_args__ = (Index("uq_my_model_name", "name", unique=True, mysql_length=768),)

    def __repr__(self) -> str:
        return f"<Synonym(id={self.id}, name={self.name})>"

TaxonomyName

Bases: Base

Class definition for table taxonomy_name. Name from NCBI taxonomy https://www.ncbi.nlm.nih.gov/taxonomys.

Attributes:

Name Type Description
id int

Primary key.

tax_id int

NCBI taxonomy Identifier.

name str

Name associated with the tax_id.

name_type str

Type of the name (e.g., scientific name, common name, synonym).

Source code in src/biokb_coconut/db/models.py
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
class TaxonomyName(Base):
    """Class definition for table taxonomy_name. Name from
    NCBI taxonomy https://www.ncbi.nlm.nih.gov/taxonomys.

    Attributes:
        id (int): Primary key.
        tax_id (int): NCBI taxonomy Identifier.
        name (str): Name associated with the tax_id.
        name_type (str): Type of the name (e.g., scientific name, common name, synonym).
    """

    __tablename__ = Base.table_prefix + "taxonomy_name"
    id: Mapped[int] = mapped_column(primary_key=True)
    tax_id: Mapped[int] = mapped_column(index=True, comment="NCBI taxonomy Identifier")
    name: Mapped[str] = mapped_column(Text)
    name_type: Mapped[str] = mapped_column(String(255), index=True)

    __table_args__ = (
        Index(
            f"ix_{__tablename__}__name",
            name,
            mysql_length=255,
        ),
    )

    def __repr__(self) -> str:
        return f"<TaxonomyName(id={self.id}, tax_id={self.tax_id}, name={self.name}, name_type={self.name_type})>"

WCVPPlant

Bases: Base

Class definition for table wcvp_plant. Plant names from World Checklist of Vascular Plants (WCVP).

Attributes:

Name Type Description
plant_name_id int

Primary key.

taxon_name Optional[str]

Taxon name of the plant.

accepted_plant_name_id Optional[int]

Accepted plant name identifier.

powo_id Optional[str]

POWO identifier.

Source code in src/biokb_coconut/db/models.py
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
class WCVPPlant(Base):
    """Class definition for table wcvp_plant. Plant names from
    World Checklist of Vascular Plants (WCVP).

    Attributes:
        plant_name_id (int): Primary key.
        taxon_name (Optional[str]): Taxon name of the plant.
        accepted_plant_name_id (Optional[int]): Accepted plant name identifier.
        powo_id (Optional[str]): POWO identifier.
    """

    __tablename__ = Base.table_prefix + "wcvp_plant"
    plant_name_id: Mapped[int] = mapped_column(primary_key=True)
    taxon_name: Mapped[Optional[str]] = mapped_column(String(1000))
    accepted_plant_name_id: Mapped[Optional[int]] = mapped_column(index=True)
    powo_id: Mapped[Optional[str]] = mapped_column(String(255))

    __table_args__ = (
        Index(
            f"ix_{__tablename__}__taxon_name",
            "taxon_name",
            mysql_length=768,
        ),
    )

    def __repr__(self) -> str:
        return f"<WCVPPlant(plant_name_id={self.plant_name_id}, taxon_name={self.taxon_name})>"