Skip to content

Commit

Permalink
Simplified import of SQL classes from scout.models.sql_model
Browse files Browse the repository at this point in the history
  • Loading branch information
Chiara Rasi committed Oct 19, 2023
1 parent 96dd057 commit 7c6c708
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 42 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [unreleased]
### Changed
- Simplified the import of SQL classes from `scout.models.sql_model`

## [1.2]
### Added
- Load genes, transcripts and exons from pre-downloaded files
Expand Down
4 changes: 1 addition & 3 deletions src/chanjo2/crud/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
from sqlalchemy.engine.cursor import CursorResult
from sqlalchemy.orm import Session, query

from chanjo2.models import SQLCase, SQLSample, CaseSample
from chanjo2.models.pydantic_models import Case, CaseCreate
from chanjo2.models.sql_models import Case as SQLCase
from chanjo2.models.sql_models import CaseSample
from chanjo2.models.sql_models import Sample as SQLSample


def filter_cases_by_name(cases: query.Query, case_name: str) -> SQLCase:
Expand Down
4 changes: 1 addition & 3 deletions src/chanjo2/crud/intervals.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
TranscriptBase,
TranscriptTag,
)
from chanjo2.models.sql_models import Exon as SQLExon
from chanjo2.models.sql_models import Gene as SQLGene
from chanjo2.models.sql_models import Transcript as SQLTranscript
from chanjo2.models import SQLGene, SQLExon, SQLTranscript

LOG = logging.getLogger("uvicorn.access")

Expand Down
4 changes: 1 addition & 3 deletions src/chanjo2/crud/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
from chanjo2.constants import SAMPLE_NOT_FOUND, WRONG_COVERAGE_FILE_MSG
from chanjo2.crud.cases import filter_cases_by_name
from chanjo2.meta.handle_d4 import get_d4_file
from chanjo2.models import SQLCase, SQLSample, CaseSample
from chanjo2.models.pydantic_models import SampleCreate
from chanjo2.models.sql_models import Case as SQLCase
from chanjo2.models.sql_models import CaseSample
from chanjo2.models.sql_models import Sample as SQLSample


def _filter_samples_by_name(
Expand Down
4 changes: 1 addition & 3 deletions src/chanjo2/endpoints/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@
get_intervals_completeness,
get_sample_interval_coverage,
)
from chanjo2.models import SQLExon, SQLGene, SQLTranscript
from chanjo2.models.pydantic_models import (
SampleGeneIntervalQuery,
FileCoverageQuery,
FileCoverageIntervalsFileQuery,
IntervalCoverage,
GeneCoverage,
)
from chanjo2.models.sql_models import Exon as SQLExon
from chanjo2.models.sql_models import Gene as SQLGene
from chanjo2.models.sql_models import Transcript as SQLTranscript

router = APIRouter()

Expand Down
3 changes: 1 addition & 2 deletions src/chanjo2/endpoints/intervals.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
update_genes,
update_transcripts,
)
from chanjo2.models import SQLExon, SQLTranscript
from chanjo2.models.pydantic_models import (
Builds,
Exon,
Expand All @@ -23,8 +24,6 @@
GeneQuery,
GeneIntervalQuery,
)
from chanjo2.models.sql_models import Exon as SQLExon
from chanjo2.models.sql_models import Transcript as SQLTranscript

router = APIRouter()

Expand Down
4 changes: 1 addition & 3 deletions src/chanjo2/meta/handle_d4.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@
from sqlalchemy.orm import Session

from chanjo2.crud.intervals import get_gene_intervals
from chanjo2.models import SQLExon, SQLGene, SQLTranscript
from chanjo2.models.pydantic_models import (
IntervalCoverage,
Sex,
GeneCoverage,
IntervalType,
TranscriptTag,
)
from chanjo2.models.sql_models import Exon as SQLExon
from chanjo2.models.sql_models import Gene as SQLGene
from chanjo2.models.sql_models import Transcript as SQLTranscript

LOG = logging.getLogger("uvicorn.access")

Expand Down
4 changes: 1 addition & 3 deletions src/chanjo2/meta/handle_load_intervals.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@
count_intervals_for_build,
delete_intervals_for_build,
)
from chanjo2.models import SQLExon, SQLGene, SQLTranscript
from chanjo2.models.pydantic_models import (
Builds,
ExonBase,
GeneBase,
IntervalType,
TranscriptBase,
)
from chanjo2.models.sql_models import Exon as SQLExon
from chanjo2.models.sql_models import Gene as SQLGene
from chanjo2.models.sql_models import Transcript as SQLTranscript

LOG = logging.getLogger("uvicorn.access")
MAX_NR_OF_RECORDS = 10_000
Expand Down
5 changes: 1 addition & 4 deletions src/chanjo2/meta/handle_report_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from chanjo2.crud.intervals import get_genes, get_hgnc_gene
from chanjo2.crud.samples import get_sample
from chanjo2.meta.handle_d4 import get_samples_sex_metrics, get_sample_interval_coverage
from chanjo2.models import SQLExon, SQLGene, SQLSample, SQLTranscript
from chanjo2.models.pydantic_models import (
ReportQuery,
ReportQuerySample,
Expand All @@ -17,10 +18,6 @@
IntervalType,
GeneReportForm,
)
from chanjo2.models.sql_models import Exon as SQLExon
from chanjo2.models.sql_models import Gene as SQLGene
from chanjo2.models.sql_models import Sample as SQLSample
from chanjo2.models.sql_models import Transcript as SQLTranscript

LOG = logging.getLogger("uvicorn.access")

Expand Down
6 changes: 6 additions & 0 deletions src/chanjo2/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from chanjo2.models.sql_models import Case as SQLCase
from chanjo2.models.sql_models import CaseSample
from chanjo2.models.sql_models import Exon as SQLExon
from chanjo2.models.sql_models import Gene as SQLGene
from chanjo2.models.sql_models import Sample as SQLSample
from chanjo2.models.sql_models import Transcript as SQLTranscript
2 changes: 1 addition & 1 deletion tests/src/chanjo2/crud/test_crud_intervals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from chanjo2.constants import BUILD_37
from chanjo2.crud.intervals import get_gene_intervals
from chanjo2.models.sql_models import Transcript as SQLTranscript
from chanjo2.models import SQLTranscript


def test_get_gene_intervals_all_transcripts(
Expand Down
3 changes: 1 addition & 2 deletions tests/src/chanjo2/meta/test_handle_report_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
get_genes_overview_incomplete_coverage_rows,
get_gene_coverage_stats_by_interval,
)
from chanjo2.models.sql_models import Gene as SQLGene
from chanjo2.models.sql_models import Transcript as SQLTranscript
from chanjo2.models import SQLGene, SQLTranscript

DEFAULT_COVERAGE_LEVEL = 20

Expand Down
31 changes: 16 additions & 15 deletions tests/src/chanjo2/test_populate_demo.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from fastapi.testclient import TestClient
from sqlalchemy.orm import sessionmaker

from chanjo2.crud.cases import get_cases
from chanjo2.crud.intervals import get_genes, get_gene_intervals
from chanjo2.crud.samples import get_samples
from chanjo2.models import SQLCase, SQLGene, SQLTranscript, SQLExon, SQLSample
from chanjo2.models.pydantic_models import Builds
from chanjo2.models.sql_models import Case, Sample, Gene, Transcript, Exon
from fastapi.testclient import TestClient
from sqlalchemy.orm import sessionmaker


def test_load_demo_data(demo_client: TestClient, demo_session: sessionmaker):
Expand All @@ -13,48 +14,48 @@ def test_load_demo_data(demo_client: TestClient, demo_session: sessionmaker):
# WHEN the app is launched
with demo_client:
# THEN database should contain a case
cases: List[Case] = get_cases(db=demo_session)
assert isinstance(cases[0], Case)
cases: List[SQLCase] = get_cases(db=demo_session)
assert isinstance(cases[0], SQLCase)

# THEN database should contain samples
samples: List[Sample] = get_samples(db=demo_session)
assert isinstance(samples[0], Sample)
samples: List[SQLSample] = get_samples(db=demo_session)
assert isinstance(samples[0], SQLSample)

# THEN for each genome build
for build in Builds.get_enum_values():
# database should contain genes
genes: List[Gene] = get_genes(
genes: List[SQLGene] = get_genes(
db=demo_session,
build=build,
ensembl_ids=None,
hgnc_ids=None,
hgnc_symbols=None,
limit=1,
)
assert isinstance(genes[0], Gene)
assert isinstance(genes[0], SQLGene)

# database should contain transcripts
transcripts: List[Transcripts] = get_gene_intervals(
transcripts: List[SQLTranscripts] = get_gene_intervals(
db=demo_session,
build=build,
ensembl_ids=None,
hgnc_ids=None,
hgnc_symbols=None,
ensembl_gene_ids=None,
limit=1,
interval_type=Transcript,
interval_type=SQLTranscript,
)
assert isinstance(transcripts[0], Transcript)
assert isinstance(transcripts[0], SQLTranscript)

# database should contain exons
exons: List[Exon] = get_gene_intervals(
exons: List[SQLExon] = get_gene_intervals(
db=demo_session,
build=build,
ensembl_ids=None,
hgnc_ids=None,
hgnc_symbols=None,
ensembl_gene_ids=None,
limit=1,
interval_type=Exon,
interval_type=SQLExon,
)
assert isinstance(exons[0], Exon)
assert isinstance(exons[0], SQLExon)

0 comments on commit 7c6c708

Please sign in to comment.