-
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 #352 from VariantEffect/feature/bencap/35/api-like…
…-target-category-constant Target Category Constant
- Loading branch information
Showing
11 changed files
with
141 additions
and
64 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,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
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
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