-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #362 from VariantEffect/release-2024.4.2
Release 2024.4.2
- Loading branch information
Showing
59 changed files
with
2,017 additions
and
630 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
alembic/manual_migrations/migrate_non_api_like_constants.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import sqlalchemy as sa | ||
from sqlalchemy.orm import Session, configure_mappers | ||
|
||
from mavedb.models import * | ||
from mavedb.models.enums.target_category import TargetCategory | ||
from mavedb.models.target_gene import TargetGene | ||
|
||
from mavedb.db.session import SessionLocal | ||
|
||
configure_mappers() | ||
|
||
def api_like_target_gene_category(category: str): | ||
if category == "Protein coding": | ||
return TargetCategory.protein_coding | ||
elif category == "Other noncoding": | ||
return TargetCategory.other_noncoding | ||
elif category == "Regulatory": | ||
return TargetCategory.regulatory | ||
else: | ||
raise ValueError() | ||
|
||
|
||
def do_migration(db: Session): | ||
target_genes = db.scalars(sa.select(TargetGene)).all() | ||
|
||
for target in target_genes: | ||
target.category = api_like_target_gene_category(target.category) | ||
db.add(target) | ||
|
||
db.commit() | ||
|
||
|
||
if __name__ == "__main__": | ||
db = SessionLocal() | ||
db.current_user = None # type: ignore | ||
|
||
do_migration(db) | ||
|
||
db.commit() | ||
db.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import sqlalchemy as sa | ||
from sqlalchemy.orm import Session, configure_mappers | ||
|
||
from mavedb.models import * | ||
|
||
from mavedb.lib.score_sets import refresh_variant_urns | ||
|
||
from mavedb.models.score_set import ScoreSet | ||
from mavedb.models.variant import Variant | ||
|
||
from mavedb.db.session import SessionLocal | ||
|
||
configure_mappers() | ||
|
||
|
||
def do_migration(db: Session): | ||
published_score_sets_with_associated_tmp_variants: sa.ScalarResult[str] | ||
published_score_sets_with_associated_tmp_variants = db.execute( | ||
sa.select(sa.distinct(ScoreSet.urn)).join(Variant).where(ScoreSet.published_date.is_not(None), Variant.urn.like("%tmp:%")) | ||
).scalars() | ||
|
||
for score_set_urn in published_score_sets_with_associated_tmp_variants: | ||
refresh_variant_urns(db, db.execute(sa.select(ScoreSet).where(ScoreSet.urn == score_set_urn)).scalar_one()) | ||
|
||
|
||
if __name__ == "__main__": | ||
db = SessionLocal() | ||
db.current_user = None # type: ignore | ||
|
||
do_migration(db) | ||
|
||
db.commit() | ||
db.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"""Target category enum | ||
Revision ID: 03c7124c33e1 | ||
Revises: 2b6f40ea2fb6 | ||
Create Date: 2024-11-01 11:27:03.609116 | ||
""" | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "03c7124c33e1" | ||
down_revision = "2b6f40ea2fb6" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.alter_column( | ||
"target_genes", | ||
"category", | ||
type_=sa.Enum( | ||
"protein_coding", | ||
"other_noncoding", | ||
"regulatory", | ||
name="targetcategory", | ||
native_enum=False, | ||
create_constraint=True, | ||
length=32, | ||
), | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.alter_column( | ||
"target_genes", | ||
"category", | ||
type_=sa.String(), | ||
existing_type=sa.Enum( | ||
"protein_coding", | ||
"other_noncoding", | ||
"regulatory", | ||
name="targetcategory", | ||
native_enum=False, | ||
create_constraint=True, | ||
length=32, | ||
), | ||
) | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
alembic/versions/68a0ec57694e_add_active_column_to_licenses.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"""Add active column to licenses | ||
Revision ID: 68a0ec57694e | ||
Revises: 03c7124c33e1 | ||
Create Date: 2024-10-22 15:36:41.868909 | ||
""" | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "68a0ec57694e" | ||
down_revision = "03c7124c33e1" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column("licenses", sa.Column("active", sa.Boolean(), nullable=False, server_default=sa.true())) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column("licenses", "active") | ||
# ### end Alembic commands ### |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import logging | ||
from typing import Optional | ||
|
||
from sqlalchemy import func, or_ | ||
from sqlalchemy.orm import Session | ||
|
||
from mavedb.lib.logging.context import logging_context, save_to_logging_context | ||
from mavedb.models.contributor import Contributor | ||
from mavedb.models.score_set import ScoreSet | ||
from mavedb.models.target_gene import TargetGene | ||
from mavedb.models.user import User | ||
from mavedb.view_models.search import TextSearch | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def search_target_genes( | ||
db: Session, | ||
owner_or_contributor: Optional[User], | ||
search: TextSearch, | ||
limit: Optional[int], | ||
) -> list[TargetGene]: | ||
save_to_logging_context({"target_gene_search_criteria": search.dict()}) | ||
|
||
query = db.query(TargetGene) | ||
|
||
if search.text and len(search.text.strip()) > 0: | ||
lower_search_text = search.text.strip().lower() | ||
query = query.filter(func.lower(TargetGene.name).contains(lower_search_text)) | ||
if owner_or_contributor is not None: | ||
query = query.filter( | ||
TargetGene.score_set.has( | ||
or_( | ||
ScoreSet.created_by_id == owner_or_contributor.id, | ||
ScoreSet.contributors.any( | ||
Contributor.orcid_id == owner_or_contributor.username | ||
), | ||
) | ||
) | ||
) | ||
|
||
query = query.order_by(TargetGene.name) | ||
if limit is not None: | ||
query = query.limit(limit) | ||
|
||
target_genes = query.all() | ||
if not target_genes: | ||
target_genes = [] | ||
|
||
save_to_logging_context({"matching_resources": len(target_genes)}) | ||
logger.debug( | ||
msg=f"Target gene search yielded {len(target_genes)} matching resources.", | ||
extra=logging_context(), | ||
) | ||
|
||
return target_genes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
valid_categories = ["Protein coding", "Regulatory", "Other noncoding"] | ||
valid_sequence_types = ["infer", "dna", "protein"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from enum import Enum | ||
|
||
|
||
class TargetCategory(str, Enum): | ||
protein_coding = "protein_coding" | ||
regulatory = "regulatory" | ||
other_noncoding = "other_noncoding" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.