Skip to content

Commit ac1b7ee

Browse files
authored
Merge branch 'release-2024.4.2' into maintenance/bencap/74/update-permitted-licenses
2 parents eddb987 + e4ec609 commit ac1b7ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1228
-520
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import sqlalchemy as sa
2+
from sqlalchemy.orm import Session, configure_mappers
3+
4+
from mavedb.models import *
5+
from mavedb.models.enums.target_category import TargetCategory
6+
from mavedb.models.target_gene import TargetGene
7+
8+
from mavedb.db.session import SessionLocal
9+
10+
configure_mappers()
11+
12+
def api_like_target_gene_category(category: str):
13+
if category == "Protein coding":
14+
return TargetCategory.protein_coding
15+
elif category == "Other noncoding":
16+
return TargetCategory.other_noncoding
17+
elif category == "Regulatory":
18+
return TargetCategory.regulatory
19+
else:
20+
raise ValueError()
21+
22+
23+
def do_migration(db: Session):
24+
target_genes = db.scalars(sa.select(TargetGene)).all()
25+
26+
for target in target_genes:
27+
target.category = api_like_target_gene_category(target.category)
28+
db.add(target)
29+
30+
db.commit()
31+
32+
33+
if __name__ == "__main__":
34+
db = SessionLocal()
35+
db.current_user = None # type: ignore
36+
37+
do_migration(db)
38+
39+
db.commit()
40+
db.close()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import sqlalchemy as sa
2+
from sqlalchemy.orm import Session, configure_mappers
3+
4+
from mavedb.models import *
5+
6+
from mavedb.lib.score_sets import refresh_variant_urns
7+
8+
from mavedb.models.score_set import ScoreSet
9+
from mavedb.models.variant import Variant
10+
11+
from mavedb.db.session import SessionLocal
12+
13+
configure_mappers()
14+
15+
16+
def do_migration(db: Session):
17+
published_score_sets_with_associated_tmp_variants: sa.ScalarResult[str]
18+
published_score_sets_with_associated_tmp_variants = db.execute(
19+
sa.select(sa.distinct(ScoreSet.urn)).join(Variant).where(ScoreSet.published_date.is_not(None), Variant.urn.like("%tmp:%"))
20+
).scalars()
21+
22+
for score_set_urn in published_score_sets_with_associated_tmp_variants:
23+
refresh_variant_urns(db, db.execute(sa.select(ScoreSet).where(ScoreSet.urn == score_set_urn)).scalar_one())
24+
25+
26+
if __name__ == "__main__":
27+
db = SessionLocal()
28+
db.current_user = None # type: ignore
29+
30+
do_migration(db)
31+
32+
db.commit()
33+
db.close()
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""Target category enum
2+
3+
Revision ID: 03c7124c33e1
4+
Revises: 2b6f40ea2fb6
5+
Create Date: 2024-11-01 11:27:03.609116
6+
7+
"""
8+
9+
from alembic import op
10+
import sqlalchemy as sa
11+
12+
13+
# revision identifiers, used by Alembic.
14+
revision = "03c7124c33e1"
15+
down_revision = "2b6f40ea2fb6"
16+
branch_labels = None
17+
depends_on = None
18+
19+
20+
def upgrade():
21+
# ### commands auto generated by Alembic - please adjust! ###
22+
op.alter_column(
23+
"target_genes",
24+
"category",
25+
type_=sa.Enum(
26+
"protein_coding",
27+
"other_noncoding",
28+
"regulatory",
29+
name="targetcategory",
30+
native_enum=False,
31+
create_constraint=True,
32+
length=32,
33+
),
34+
)
35+
# ### end Alembic commands ###
36+
37+
38+
def downgrade():
39+
# ### commands auto generated by Alembic - please adjust! ###
40+
op.alter_column(
41+
"target_genes",
42+
"category",
43+
type_=sa.String(),
44+
existing_type=sa.Enum(
45+
"protein_coding",
46+
"other_noncoding",
47+
"regulatory",
48+
name="targetcategory",
49+
native_enum=False,
50+
create_constraint=True,
51+
length=32,
52+
),
53+
)
54+
# ### end Alembic commands ###

poetry.lock

Lines changed: 307 additions & 248 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ python = "^3.9"
2626

2727
fqfa = "~1.3.0"
2828
pyhumps = "~3.8.0"
29-
pyyaml = "~5.1"
29+
pyyaml = "~6.0.1"
3030
IDUtils = "~1.2.0"
3131
mavehgvs = "~0.6.0"
3232
eutils = "~0.6.0"
@@ -99,6 +99,7 @@ mypy_path = "mypy_stubs"
9999
addopts = "-v -rP --import-mode=importlib --disable-socket --allow-hosts localhost,::1,127.0.0.1"
100100
asyncio_mode = 'strict'
101101
testpaths = "tests/"
102+
pythonpath = "."
102103
norecursedirs = "tests/helpers/"
103104
# Uncomment the following lines to include application log output in Pytest logs.
104105
# log_cli = true

src/mavedb/lib/experiments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def search_experiments(
9999
)
100100
)
101101

102-
items: list[Experiment] = query.order_by(Experiment.title).all()
102+
items: list[Experiment] = query.order_by(Experiment.urn, Experiment.title).all()
103103
if not items:
104104
items = []
105105

src/mavedb/lib/score_sets.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,21 @@ def create_variants(db, score_set: ScoreSet, variants_data: list[VariantData], b
617617
return len(score_set.variants)
618618

619619

620+
def refresh_variant_urns(db: Session, score_set: ScoreSet):
621+
variants = db.execute(select(Variant).where(Variant.score_set_id == score_set.id)).scalars()
622+
623+
for variant in variants:
624+
if not variant.urn:
625+
raise ValueError("All variants should have an associated URN.")
626+
627+
variant_number = variant.urn.split("#")[1]
628+
refreshed_urn = f"{score_set.urn}#{variant_number}"
629+
variant.urn = refreshed_urn
630+
db.add(variant)
631+
632+
db.commit()
633+
634+
620635
def bulk_create_urns(n, score_set, reset_counter=False) -> list[str]:
621636
start_value = 0 if reset_counter else score_set.num_variants
622637
parent_urn = score_set.urn
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
valid_categories = ["Protein coding", "Regulatory", "Other noncoding"]
21
valid_sequence_types = ["infer", "dna", "protein"]

src/mavedb/lib/validation/target.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,10 @@
11
from fqfa import infer_sequence_type
22
from fqfa.validator import amino_acids_validator, dna_bases_validator
33

4-
from mavedb.lib.validation.constants.target import valid_categories, valid_sequence_types
4+
from mavedb.lib.validation.constants.target import valid_sequence_types
55
from mavedb.lib.validation.exceptions import ValidationError
66

77

8-
def validate_target_category(category: str):
9-
"""
10-
If the target category provided does not fall within a pre-defined list of valid categories.
11-
12-
Parameters
13-
__________
14-
category: str
15-
The target category to be validated.
16-
17-
Raises
18-
______
19-
ValidationError
20-
If the target category provided is not valid.
21-
"""
22-
if category not in valid_categories:
23-
raise ValidationError(
24-
"{} is not a valid target category. Valid categories are "
25-
"Protein coding, Regulatory, and Other noncoding".format(category)
26-
)
27-
28-
298
def validate_sequence_category(sequence_type: str):
309
"""
3110
If the sequence type provided does not fall within a pre-defined list of valid sequence types.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from enum import Enum
2+
3+
4+
class TargetCategory(str, Enum):
5+
protein_coding = "protein_coding"
6+
regulatory = "regulatory"
7+
other_noncoding = "other_noncoding"

0 commit comments

Comments
 (0)