-
Notifications
You must be signed in to change notification settings - Fork 11
Unify eFP schema + gene ID validation with combined_master.json #328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rmobmina
wants to merge
35
commits into
BioAnalyticResource:dev
Choose a base branch
from
rmobmina:feature/reena-steven-integrated-endpoint
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
aa56b67
Add eFP/ePlant gene ID validation, microarray probeset support, and m…
rmobmina a577ee3
Integrate Vincent's regex registry, fix master JSON species, refactor…
rmobmina afd8c63
Remove scratch CSVs, MDs, and one-off analysis files from repo root
rmobmina 77b1d51
Remove personal attribution headers from source and test files
rmobmina ec8f3ac
Make combined_master.json build deterministic
rmobmina f72481e
Fix failing tests: generalize mfinder skip, drop orphaned eplant test
rmobmina 16ecfb0
Remove dead-on-arrival DB imports from config/init.sh
rmobmina d61efa2
Add eFP "To the Experiment" link audit script
rmobmina ac83b9c
Merge remote-tracking branch 'upstream/dev' into cleaned-endpoint
rmobmina e15c770
Unify per-species gene ID validation onto Vincent's regex registry
rmobmina 654ba01
Fix CI: real fixture data never loading, rpds-py incompatible with 3.10
rmobmina ec5acbf
Remove api/random_rows_json/ from version control
rmobmina deb0bd1
Add SUPeR Viewer UMAP + pseudobulk gene expression endpoints
rmobmina 9f4b8b0
Add data-retrieval coverage for the UMAP and pseudobulk expression en…
rmobmina 73e6afd
Remove build/scrape/reporting tooling not needed by the running API
rmobmina 196342e
Populate real sample-group data for the 7 SUPeR Viewer pseudobulk dat…
rmobmina f158077
Clean up PR: drop local ePlant XML data, fold master_data_utils into …
rmobmina e7c5f96
Add api/random_rows_json/ fallback dataset for local eFP seed queries
rmobmina 9aee55b
Revert unrelated init.sh/SNP scope creep; simplify regex loading and …
rmobmina d65a345
Update: checked the schemas against prod, verified the SQL schemas an…
VinLau e5e5709
Merge pull request #1 from VinLau/feature/reena-steven-integrated-end…
rmobmina 2bf6d2c
Adapt to VinLau's combined_master.json field rename; restore 10 dropp…
rmobmina 1aa5aeb
Move SUPeR Viewer UMAP + pseudobulk endpoints to feature/steven-changes
rmobmina b31f367
Address PR 328 review: simplify regex validation, drop bootstrap/fall…
rmobmina 6047eef
Replace per-species is_XXX_gene_valid() wrappers with direct is_efp_g…
rmobmina 3050b4c
Fix flake8 E302 in test_efp_data.py
rmobmina 7f420a0
Fix cacao gene ID validation bypass and simplify eFP query service
rmobmina 5215f57
Restore per-species gene ID validators for non-eFP endpoints
rmobmina 5d4681e
Revert mfinder_utils.py to use is_arabidopsis_gene_valid
rmobmina f34219e
cleaning up
rmobmina e824146
fix test assertion for updated invalid-gene error message
rmobmina 4ae2bfd
additional cleaning up
rmobmina 3dc939b
Simplify eFP gene expression querying with dynamic per-database models
rmobmina 2465233
Fix CI: test light_series dump isn't in the seeded test set, use arab…
rmobmina c010801
Replace f-strings with .format() to match project convention
rmobmina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,91 +1,23 @@ | ||
| """ | ||
| Reena Obmina | BCB330 Project 2025-2026 | University of Toronto | ||
|
|
||
| Dynamic SQLAlchemy model generation for all eFP databases. | ||
|
|
||
| At import time, one ORM model class is generated per database entry in | ||
| SIMPLE_EFP_DATABASE_SCHEMAS and stored in SIMPLE_EFP_SAMPLE_MODELS. | ||
| This replaces ~1,984 lines of hand-written boilerplate with a single registry. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Dict | ||
|
|
||
| from sqlalchemy import Float, Integer, String, Text | ||
| from sqlalchemy.dialects.mysql import INTEGER | ||
| """Every eFP database exposes the same sample_data table, so instead of hand-writing | ||
| ~190 near-identical model files we generate one model class per database here.""" | ||
|
|
||
| from api import db | ||
| from api.models.efp_schemas import SIMPLE_EFP_DATABASE_SCHEMAS | ||
|
|
||
|
|
||
| def _to_sqla_type(column_spec): | ||
| """ | ||
| Map a column specification dictionary to a SQLAlchemy column type. | ||
|
|
||
| Converts the simple type descriptors used in schema definitions to the | ||
| appropriate SQLAlchemy type objects for ORM model generation. | ||
|
|
||
| :param column_spec: Column specification with 'type', 'length', and 'unsigned' keys | ||
| :type column_spec: Dict[str, Any] | ||
| :return: SQLAlchemy column type (String, Integer, Float, or Text) | ||
| :rtype: sqlalchemy.types.TypeEngine | ||
| :raises ValueError: If column type is not one of: string, integer, float, text | ||
|
|
||
| Example:: | ||
|
|
||
| col_spec = {"type": "string", "length": 24} | ||
| sqla_type = _to_sqla_type(col_spec) # Returns String(24) | ||
| """ | ||
| col_type = column_spec.get("type") | ||
| if col_type == "string": | ||
| return String(column_spec["length"]) | ||
| if col_type == "integer": | ||
| if column_spec.get("unsigned"): | ||
| return INTEGER(unsigned=True) | ||
| return Integer | ||
| if col_type == "float": | ||
| return Float | ||
| if col_type == "text": | ||
| return Text | ||
| raise ValueError(f"Unsupported column type: {col_type}") | ||
|
|
||
|
|
||
| def _generate_model(bind_key: str, spec) -> db.Model: | ||
| """ | ||
| Build a concrete SQLAlchemy model class for the given schema specification. | ||
|
|
||
| Dynamically creates an ORM model with the specified table name, bind key, | ||
| and columns based on the schema definition. The generated model class can | ||
| be used like any Flask-SQLAlchemy model. | ||
|
|
||
| :param bind_key: Database bind key (e.g., 'cannabis', 'embryo') | ||
| :type bind_key: str | ||
| :param spec: Database schema specification from SIMPLE_EFP_DATABASE_SCHEMAS | ||
| :type spec: Dict[str, Any] | ||
| :return: Dynamically generated SQLAlchemy model class | ||
| :rtype: db.Model | ||
|
|
||
| Example:: | ||
|
|
||
| schema = SIMPLE_EFP_DATABASE_SCHEMAS['cannabis'] | ||
| CannabisModel = _generate_model('cannabis', schema) | ||
| # Returns class: CannabisSampleData(db.Model) | ||
| """ | ||
| attrs = {"__bind_key__": bind_key, "__tablename__": spec["table_name"]} | ||
|
|
||
| for column in spec["columns"]: | ||
| kwargs = {"nullable": column.get("nullable", True)} | ||
| if column.get("primary_key"): | ||
| kwargs["primary_key"] = True | ||
| attrs[column["name"]] = db.mapped_column(_to_sqla_type(column), **kwargs) | ||
| from api.utils.bar_utils import load_combined_master | ||
|
|
||
| class_name = "".join([part.capitalize() for part in bind_key.split("_")]) + "SampleData" | ||
| return type(class_name, (db.Model,), attrs) | ||
|
|
||
| def _sample_data_model(database): | ||
| class_name = "".join(part.capitalize() for part in database.split("_")) + "SampleData" | ||
| return type( | ||
| class_name, | ||
| (db.Model,), | ||
| { | ||
| "__bind_key__": database, | ||
| "__tablename__": "sample_data", | ||
| "data_probeset_id": db.mapped_column(db.String(255), primary_key=True), | ||
| "data_bot_id": db.mapped_column(db.String(255), primary_key=True), | ||
| "data_signal": db.mapped_column(db.Float, primary_key=True), | ||
| }, | ||
| ) | ||
|
|
||
| SIMPLE_EFP_SAMPLE_MODELS: Dict[str, db.Model] = { | ||
| db_name: _generate_model(db_name, spec) for db_name, spec in SIMPLE_EFP_DATABASE_SCHEMAS.items() | ||
| } | ||
|
|
||
| __all__ = ["SIMPLE_EFP_SAMPLE_MODELS"] | ||
| SAMPLE_DATA_MODELS = {database: _sample_data_model(database) for database in load_combined_master()["databases"]} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.