Skip to content

Commit

Permalink
Merge branch 'release-2024.4.2' into feature/bencap/251/variant-mappi…
Browse files Browse the repository at this point in the history
…ng-script
  • Loading branch information
bencap committed Oct 18, 2024
2 parents 775fc79 + 65dd9cb commit 083bb82
Show file tree
Hide file tree
Showing 182 changed files with 5,857 additions and 2,916 deletions.
11 changes: 0 additions & 11 deletions .flake8

This file was deleted.

20 changes: 17 additions & 3 deletions .github/workflows/run-tests-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- run: pip install --upgrade pip
- run: pip install poetry
- run: poetry install --with dev --extras server
- run: poetry run pytest tests/ --show-capture=stdout
- run: poetry run pytest tests/ --show-capture=stdout --cov=src

run-tests-3_10:
runs-on: ubuntu-latest
Expand All @@ -32,7 +32,7 @@ jobs:
- run: pip install --upgrade pip
- run: pip install poetry
- run: poetry install --with dev --extras server
- run: poetry run pytest tests/ --show-capture=stdout
- run: poetry run pytest tests/ --show-capture=stdout --cov=src

run-tests-3_11:
runs-on: ubuntu-latest
Expand All @@ -46,7 +46,7 @@ jobs:
- run: pip install --upgrade pip
- run: pip install poetry
- run: poetry install --with dev --extras server
- run: poetry run pytest tests/ --show-capture=stdout
- run: poetry run pytest tests/ --show-capture=stdout --cov=src

run-mypy-3_10:
runs-on: ubuntu-latest
Expand All @@ -61,3 +61,17 @@ jobs:
- run: pip install poetry
- run: poetry install --with dev --extras server
- run: poetry run mypy src/

run-ruff-lint:
runs-on: ubuntu-latest
name: Ruff linting on Python 3.10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: 'pip'
- run: pip install --upgrade pip
- run: pip install poetry
- run: poetry install --with dev --extras server
- run: poetry run ruff check
13 changes: 7 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
repos:
- repo: https://github.com/psf/black
rev: 23.3.0
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.6.8
hooks:
- id: black
# Latest version of Python supported by the project
# See https://pre-commit.com/#top_level-default_language_version
language_version: python3.9
# Run the linter.
- id: ruff
# Run the formatter.
- id: ruff-format
3 changes: 2 additions & 1 deletion alembic/alembic_helpers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# From https://improveandrepeat.com/2021/09/python-friday-87-handling-pre-existing-tables-with-alembic-and-sqlalchemy/
# Based on https://github.com/talkpython/data-driven-web-apps-with-flask

from alembic import op
from sqlalchemy import engine_from_config
from sqlalchemy.engine import reflection

from alembic import op


def table_does_not_exist(table, schema=None):
config = op.get_context().config
Expand Down
5 changes: 2 additions & 3 deletions alembic/env.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from logging.config import fileConfig
import os
from logging.config import fileConfig

from sqlalchemy import engine_from_config
from sqlalchemy import pool
from sqlalchemy import engine_from_config, pool

from alembic import context

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import sqlalchemy as sa
from sqlalchemy.orm import Session, configure_mappers

from mavedb.models import *

from mavedb.models.score_set import ScoreSet
from mavedb.models.variant import Variant
from mavedb.models.target_gene import TargetGene
from mavedb.models.target_accession import TargetAccession

from mavedb.db.session import SessionLocal

configure_mappers()


def do_migration(db: Session):
accession_based_score_sets = db.execute(
sa.select(ScoreSet).join(TargetGene).where(TargetGene.accession_id.isnot(None))
).scalars()

for score_set in accession_based_score_sets:
total_targets = len(
list(db.execute(sa.select(TargetGene).where(TargetGene.score_set_id == score_set.id)).scalars())
)

# Variants from score sets with multiple targets are already in the desired format.
if total_targets > 1:
continue

target_accession = db.execute(
sa.select(TargetAccession.accession).join(TargetGene).where(TargetGene.score_set_id == score_set.id)
).scalar()
variants = db.execute(sa.select(Variant).where(Variant.score_set_id == score_set.id)).scalars()

if target_accession is None:
raise ValueError("target accession should never be None.")

for variant in variants:
if variant.hgvs_nt:
variant.hgvs_nt = f"{target_accession}:{variant.hgvs_nt}"
if variant.hgvs_pro:
variant.hgvs_pro = f"{target_accession}:{variant.hgvs_pro}"
if variant.hgvs_splice:
variant.hgvs_splice = f"{target_accession}:{variant.hgvs_splice}"

db.add(variant)


if __name__ == "__main__":
db = SessionLocal()
db.current_user = None # type: ignore

do_migration(db)

db.commit()
db.close()
3 changes: 1 addition & 2 deletions alembic/versions/194cfebabe32_rename_wild_type_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
Create Date: 2023-08-29 12:48:18.390567
"""
from alembic import op
import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision = "194cfebabe32"
Expand Down
29 changes: 29 additions & 0 deletions alembic/versions/1cee01c42909_make_index_on_contributors_unique.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""make index on contributors unique
Revision ID: 1cee01c42909
Revises: 76e1e55bc5c1
Create Date: 2024-09-03 09:53:21.635751
"""

from alembic import op

# revision identifiers, used by Alembic.
revision = "1cee01c42909"
down_revision = "1d4933b4b6f7"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index("ix_contributors_orcid_id", table_name="contributors")
op.create_index(op.f("ix_contributors_orcid_id"), "contributors", ["orcid_id"], unique=True)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f("ix_contributors_orcid_id"), table_name="contributors")
op.create_index("ix_contributors_orcid_id", "contributors", ["orcid_id"], unique=False)
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
Create Date: 2024-09-04 16:17:20.875937
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '1d4933b4b6f7'
down_revision = ('76e1e55bc5c1', 'd7e6f8c3b9dc')
revision = "1d4933b4b6f7"
down_revision = ("76e1e55bc5c1", "d7e6f8c3b9dc")
branch_labels = None
depends_on = None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@
Create Date: 2023-06-01 14:51:04.700969
"""
from typing import Optional

import os
from typing import Optional

import eutils
from eutils._internal.xmlfacades.pubmedarticleset import PubmedArticleSet
import sqlalchemy as sa
from eutils import EutilsNCBIError
from mavedb.lib.exceptions import AmbiguousIdentifierError
from eutils._internal.xmlfacades.pubmedarticleset import PubmedArticleSet
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.orm import Session

from alembic import op
from mavedb.lib.identifiers import ExternalPublication
from mavedb.lib.exceptions import AmbiguousIdentifierError
from mavedb.lib.external_publications import Rxiv
from mavedb.lib.identifiers import ExternalPublication
from mavedb.models.publication_identifier import PublicationIdentifier

# revision identifiers, used by Alembic.
Expand Down
30 changes: 30 additions & 0 deletions alembic/versions/2b6f40ea2fb6_add_score_range_column.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Add score range column
Revision ID: 2b6f40ea2fb6
Revises: 1d4933b4b6f7
Create Date: 2024-09-09 12:25:33.180077
"""

import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

from alembic import op

# revision identifiers, used by Alembic.
revision = "2b6f40ea2fb6"
down_revision = "1cee01c42909"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("scoresets", sa.Column("score_ranges", postgresql.JSONB(astext_type=sa.Text()), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("scoresets", "score_ranges")
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
Create Date: 2024-05-16 13:06:05.561411
"""
from alembic import op

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision = "2c8d7e2bf2fe"
Expand Down
32 changes: 19 additions & 13 deletions alembic/versions/33e99d4b90cc_add_mapped_variants_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,39 @@
Create Date: 2023-05-15 17:24:07.847206
"""
from alembic import op

import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

from alembic import op

# revision identifiers, used by Alembic.
revision = '33e99d4b90cc'
down_revision = 'da9ba478647d'
revision = "33e99d4b90cc"
down_revision = "da9ba478647d"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('mapped_variants',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('pre_mapped', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
sa.Column('post_mapped', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
sa.Column('variant_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['variant_id'], ['variants.id'], ),
sa.PrimaryKeyConstraint('id')
op.create_table(
"mapped_variants",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("pre_mapped", postgresql.JSONB(astext_type=sa.Text()), nullable=False),
sa.Column("post_mapped", postgresql.JSONB(astext_type=sa.Text()), nullable=False),
sa.Column("variant_id", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(
["variant_id"],
["variants.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(op.f('ix_mapped_variants_id'), 'mapped_variants', ['id'], unique=False)
op.create_index(op.f("ix_mapped_variants_id"), "mapped_variants", ["id"], unique=False)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_mapped_variants_id'), table_name='mapped_variants')
op.drop_table('mapped_variants')
op.drop_index(op.f("ix_mapped_variants_id"), table_name="mapped_variants")
op.drop_table("mapped_variants")
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
Create Date: 2024-04-18 09:19:04.008237
"""
from alembic import op

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision = "377bb8c30bde"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
Create Date: 2024-08-16 13:25:14.980820
"""

from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = "44a45d616036"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
Create Date: 2023-08-24 15:20:01.208691
"""
from alembic import op

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision = "44d5c568f64b"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
Create Date: 2023-05-09 16:18:41.360541
"""
from alembic import op
import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision = "5cad62af3705"
Expand Down
3 changes: 2 additions & 1 deletion alembic/versions/60103ad1cb5b_add_target_sequence_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
Create Date: 2023-08-29 16:04:44.620385
"""
from alembic import op

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision = "60103ad1cb5b"
Expand Down
Loading

0 comments on commit 083bb82

Please sign in to comment.