Skip to content

Commit 9c5faee

Browse files
committed
WIP #97, WIP tests fail
1 parent ee03991 commit 9c5faee

File tree

10 files changed

+538
-265
lines changed

10 files changed

+538
-265
lines changed

Diff for: server/migrations/versions/80658585dbb2_add_trna.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""add_trna
2+
3+
Revision ID: 80658585dbb2
4+
Revises: 622810482837
5+
Create Date: 2024-06-11 14:25:58.871272
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = "80658585dbb2"
14+
down_revision = "622810482837"
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade() -> None:
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.create_table(
22+
"sprinzl",
23+
sa.Column("id", sa.Integer(), nullable=False),
24+
sa.Column("data_id", sa.Integer(), nullable=False),
25+
sa.Column("position", sa.String(length=32), nullable=False),
26+
sa.ForeignKeyConstraint(
27+
["data_id"], ["data.id"], name=op.f("fk_sprinzl_data_id_data")
28+
),
29+
sa.PrimaryKeyConstraint("id", name=op.f("pk_sprinzl")),
30+
sa.UniqueConstraint("data_id", "position", name=op.f("uq_sprinzl_data_id")),
31+
)
32+
op.create_index(op.f("ix_sprinzl_data_id"), "sprinzl", ["data_id"], unique=False)
33+
op.add_column(
34+
"annotation", sa.Column("source", sa.String(length=128), nullable=False)
35+
)
36+
op.drop_constraint("uq_annotation_rtv", "annotation", type_="unique")
37+
op.create_unique_constraint(
38+
"uq_annotation_rtv", "annotation", ["release", "taxa_id", "source", "version"]
39+
)
40+
op.add_column(
41+
"assembly", sa.Column("alt_name", sa.String(length=128), nullable=False)
42+
)
43+
op.create_unique_constraint(op.f("uq_assembly_alt_name"), "assembly", ["alt_name"])
44+
# ### end Alembic commands ###
45+
46+
47+
def downgrade() -> None:
48+
# ### commands auto generated by Alembic - please adjust! ###
49+
op.drop_constraint(op.f("uq_assembly_alt_name"), "assembly", type_="unique")
50+
op.drop_column("assembly", "alt_name")
51+
op.drop_constraint("uq_annotation_rtv", "annotation", type_="unique")
52+
op.create_unique_constraint(
53+
"uq_annotation_rtv", "annotation", ["release", "taxa_id", "version"]
54+
)
55+
op.drop_column("annotation", "source")
56+
op.drop_index(op.f("ix_sprinzl_data_id"), table_name="sprinzl")
57+
op.drop_table("sprinzl")
58+
# ### end Alembic commands ###
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""assembly_drop_constraint
2+
3+
Revision ID: be4f58630610
4+
Revises: 80658585dbb2
5+
Create Date: 2024-06-11 17:16:15.019905
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
from sqlalchemy.dialects import mysql
11+
12+
# revision identifiers, used by Alembic.
13+
revision = "be4f58630610"
14+
down_revision = "80658585dbb2"
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade() -> None:
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.alter_column(
22+
"assembly", "alt_name", existing_type=mysql.VARCHAR(length=128), nullable=True
23+
)
24+
op.drop_index("uq_assembly_alt_name", table_name="assembly")
25+
# ### end Alembic commands ###
26+
27+
28+
def downgrade() -> None:
29+
# ### commands auto generated by Alembic - please adjust! ###
30+
op.create_index("uq_assembly_alt_name", "assembly", ["alt_name"], unique=True)
31+
op.alter_column(
32+
"assembly", "alt_name", existing_type=mysql.VARCHAR(length=128), nullable=False
33+
)
34+
# ### end Alembic commands ###

Diff for: server/src/scimodom/database/models.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ class Assembly(Base):
190190

191191
id: Mapped[int] = mapped_column(primary_key=True)
192192
name: Mapped[str] = mapped_column(String(128), nullable=False, unique=True)
193+
alt_name: Mapped[str] = mapped_column(String(128), nullable=True)
193194
taxa_id: Mapped[int] = mapped_column(ForeignKey("ncbi_taxa.id"), index=True)
194195
version: Mapped[str] = mapped_column(
195196
String(12), nullable=False
@@ -216,12 +217,13 @@ class Annotation(Base):
216217
id: Mapped[int] = mapped_column(primary_key=True)
217218
release: Mapped[int] = mapped_column(nullable=False)
218219
taxa_id: Mapped[int] = mapped_column(ForeignKey("ncbi_taxa.id"), index=True)
220+
source: Mapped[str] = mapped_column(String(128), nullable=False)
219221
version: Mapped[str] = mapped_column(
220222
String(12), nullable=False
221223
) # current is annotation_version.version_num
222224

223225
__table_args__ = (
224-
UniqueConstraint(release, taxa_id, version, name="uq_annotation_rtv"),
226+
UniqueConstraint(release, taxa_id, source, version, name="uq_annotation_rtv"),
225227
)
226228

227229
inst_taxa: Mapped["Taxa"] = relationship(back_populates="annotations")
@@ -245,12 +247,14 @@ class GenomicAnnotation(Base):
245247

246248
id: Mapped[str] = mapped_column(
247249
String(128), primary_key=True, autoincrement=False
248-
) # Ensembl ID
250+
) # Ensembl ID or GtRNAdb_id incl. organism
249251
annotation_id: Mapped[int] = mapped_column(ForeignKey("annotation.id"), index=True)
250-
name: Mapped[str] = mapped_column(String(128), nullable=True) # Ensembl gene name
252+
name: Mapped[str] = mapped_column(
253+
String(128), nullable=True
254+
) # Ensembl gene name or GtRNAdb_id
251255
biotype: Mapped[str] = mapped_column(
252256
String(255), nullable=True
253-
) # Ensembl gene biotype
257+
) # Ensembl gene biotype or tRNA
254258

255259
__table_args__ = (Index("idx_genomic", "annotation_id", "biotype", "name"),)
256260

@@ -437,6 +441,18 @@ class DataAnnotation(Base):
437441
inst_data: Mapped["Data"] = relationship(back_populates="annotations")
438442

439443

444+
class Sprinzl(Base):
445+
"""Sprinzl tRNA position numbering"""
446+
447+
__tablename__ = "sprinzl"
448+
449+
id: Mapped[int] = mapped_column(primary_key=True)
450+
data_id: Mapped[int] = mapped_column(ForeignKey("data.id"), index=True)
451+
position: Mapped[str] = mapped_column(String(32), nullable=False)
452+
453+
__table_args__ = (UniqueConstraint(data_id, position),)
454+
455+
440456
class UserState(enum.Enum):
441457
wait_for_confirmation = 0
442458
active = 1

0 commit comments

Comments
 (0)