Coverage for src/python/ensembl/ncbi_taxonomy/models.py: 100%
27 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-17 13:09 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-17 13:09 +0000
1# See the NOTICE file distributed with this work for additional information
2# regarding copyright ownership.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""NCBI Taxonomy database ORM."""
15# Ignore some pylint and mypy checks due to the nature of SQLAlchemy ORMs
16# pylint: disable=missing-class-docstring
17# mypy: disable-error-code="misc, valid-type"
19from sqlalchemy import (
20 Column,
21 ForeignKey,
22 join,
23)
24from sqlalchemy.dialects.mysql import (
25 INTEGER,
26 TINYINT,
27 VARCHAR,
28 CHAR,
29)
30from sqlalchemy.orm import (
31 relationship,
32 column_property,
33)
34from sqlalchemy.orm import declarative_base
36Base = declarative_base()
39class NCBITaxaNode(Base):
40 __tablename__ = "ncbi_taxa_node"
42 taxon_id = Column(INTEGER(10), primary_key=True)
43 parent_id = Column(INTEGER(10), ForeignKey("ncbi_taxa_node.taxon_id"), nullable=False, index=True)
44 rank = Column(CHAR(32), nullable=False, index=True)
45 genbank_hidden_flag = Column(TINYINT(1), nullable=False, default=0)
46 left_index = Column(INTEGER(10), nullable=False, default=0, index=True)
47 right_index = Column(INTEGER(10), nullable=False, default=0, index=True)
48 root_id = Column(INTEGER(10), nullable=False, default=1)
50 parent = relationship("NCBITaxaNode", remote_side=[taxon_id])
51 children = relationship("NCBITaxaName")
54class NCBITaxaName(Base):
55 __tablename__ = "ncbi_taxa_name"
57 taxon_id = Column(INTEGER(10), ForeignKey("ncbi_taxa_node.taxon_id"), index=True, primary_key=True)
58 name = Column(VARCHAR(500), index=True, primary_key=True)
59 name_class = Column(VARCHAR(50), nullable=False, index=True)
62class NCBITaxonomy(Base):
63 ncbi_taxa_name_table = NCBITaxaName.__table__
64 ncbi_taxa_node_table = NCBITaxaNode.__table__
66 name_node_join = join(ncbi_taxa_name_table, ncbi_taxa_node_table)
68 __table__ = name_node_join
70 taxon_id = column_property(ncbi_taxa_name_table.c.taxon_id, ncbi_taxa_node_table.c.taxon_id)