-
Notifications
You must be signed in to change notification settings - Fork 12
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
Replace alchy with sqlservice and unfreeze SQLAlchemy #255
Conversation
context.abort() | ||
LOG.info("delete sample (%s) from database", sample_id) | ||
store.session.delete(sample_obj) | ||
store.save() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
store.save() is no longer required, read below
except IntegrityError: | ||
LOG.exception('elements already linked?') | ||
chanjo_db.session.rollback() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rollback is handled automatically by the session, see here
@@ -105,21 +100,3 @@ def tear_down(self): | |||
# drop/delete the tables | |||
self.drop_all() | |||
return self | |||
|
|||
def save(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer required because sessions handle commits and rollbacks automatically
@@ -23,40 +22,14 @@ def test_no_dialect(): | |||
assert chanjo_db.dialect == "sqlite" | |||
|
|||
|
|||
def test_save(chanjo_db): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was testing a function that is now removed
I've tested it locally and got the same result as with master brach. Also all automatic tests pass. Marking it ready for review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done! Looks good to me, and tested as suggested locally without issue.
@@ -2,14 +2,13 @@ | |||
from collections import namedtuple | |||
from datetime import datetime | |||
|
|||
from alchy import ModelBase, make_declarative_base | |||
from sqlservice import declarative_base |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
from sqlalchemy import Column, types, ForeignKey, UniqueConstraint, orm | ||
|
||
Exon = namedtuple('Exon', ['chrom', 'start', 'end', 'completeness']) | ||
|
||
# base for declaring a mapping | ||
BASE = make_declarative_base(Base=ModelBase) | ||
|
||
BASE = declarative_base() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅
@@ -89,11 +87,13 @@ class TranscriptStat(BASE): | |||
threshold = Column(types.Integer) | |||
_incomplete_exons = Column(types.Text) | |||
|
|||
sample_id = Column(types.String(32), ForeignKey('sample.id'), | |||
sample_id = Column(types.String(32), ForeignKey('sample.id', ondelete='CASCADE'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same there, nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without that param if you removed a sample it didin't remove the linked records in TranscriptStat any more. I guess something has changed in SQLAlchemy when switching to version 2?
data = json.loads(lines[0].strip()) | ||
assert data['sample_id'] == 'sample' | ||
assert isinstance(data['mean_coverage'], float) | ||
with popexist_db.begin() as session: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥇
Test loading coverage for a case:One of the samples was already loaded but the other 2 got loaded. The report looks like this: |
This PR adds | fixes:
How to prepare for test:
How to test:
chanjo init --auto demodata
demodata
containing these 3 files:chanjo --config demodata/chanjo.yaml link demodata/hgnc.grch37p13.exons.bed
chanjo --config demodata/chanjo.yaml load chanjo/init/demo-files/sample1.coverage.bed
Expected outcome:
chanjo --config demodata/chanjo.yaml calculate mean -s sample1
Review:
This version is a: