Skip to content
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

feat(IPVC-2280): add codon_table to transcript + migration #21

Merged
merged 2 commits into from
Apr 8, 2024

Conversation

sptaylor
Copy link

@sptaylor sptaylor commented Apr 8, 2024

This PR adds codon_table to the Transcript model and adds a migration. By setting server_default to 1, all existing transcripts will be assigned 1 during the migration.

Note: I did not add codon_table to any of the views. I'd be happy to add that to my migration if we want to update any views.

Because alembic can be a bit finicky, here are the steps I used to successfully apply and validate the migration:

docker build --target uta -t uta-update .
docker compose up -d uta-update
docker-compose exec uta-update bash
root@lima-rancher-desktop:/opt/repos/uta# alembic -c etc/alembic.ini history
edadb97f6502 -> cc51f50ae896 (head), add sqlalchemy model for assocacs
<base> -> edadb97f6502, initial state
root@lima-rancher-desktop:/opt/repos/uta# alembic -c etc/alembic.ini upgrade head
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
root@lima-rancher-desktop:/opt/repos/uta# alembic -c etc/alembic.ini revision --autogenerate -m "add codon_table to Transcript"
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO  [alembic.autogenerate.compare] Detected add column 'uta.transcript.codon_table'
  Generating /opt/repos/uta/src/alembic/versions/a697b584f699_add_codon_table_to_transcript.py ...  done
root@lima-rancher-desktop:/opt/repos/uta# alembic -c etc/alembic.ini upgrade head
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade cc51f50ae896 -> a697b584f699, add codon_table to Transcript
root@lima-rancher-desktop:/opt/repos/uta# uta --conf=etc/global.conf --conf=etc/[email protected] shell
INFO:uta.cli:loaded etc/global.conf
INFO:uta.cli:loaded etc/[email protected]
INFO:uta.cli:connecting to postgresql://uta_admin@localhost/uta
INFO:uta:connected to postgresql://uta_admin@localhost/uta
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.23.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from sqlalchemy.orm import Session
   ...: from sqlalchemy import create_engine
   ...: from uta.models import *

In [2]:  engine = create_engine("postgresql://uta_admin:@localhost/uta")
   ...: connection = engine.connect()
   ...: session = Session(bind=connection)
   ...:  t = session.query(Transcript).filter(Transcript.ac == 'NM_007297.4').first()  # BRCA1

In [3]: t.codon_table
Out[3]: 1

Confirmed outside of the shell as well:

(uta-venv2) ➜  uta git:(IPVC-2280) ✗ alembic -c etc/alembic.ini history
cc51f50ae896 -> a697b584f699 (head), add codon_table to Transcript
edadb97f6502 -> cc51f50ae896, add sqlalchemy model for assocacs
<base> -> edadb97f6502, initial state
(uta-venv2) ➜  uta git:(IPVC-2280) ✗ alembic -c etc/alembic.ini upgrade head
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
(uta-venv2) ➜  uta git:(IPVC-2280) ✗  psql "postgresql://uta_admin:@localhost/uta"

psql (14.3, server 14.9 (Debian 14.9-1.pgdg120+1))
Type "help" for help.

uta=> set search_path = uta;
SET
uta=> select * from transcript limit 10;
       ac        | origin_id |   hgnc   | cds_start_i | cds_end_i |             cds_md5              |           added            | codon_table
-----------------+-----------+----------+-------------+-----------+----------------------------------+----------------------------+-------------
 ENST00000596924 |        10 | A1BG     |             |           |                                  | 2015-08-25 23:59:17.412518 |           1
 ENST00000263100 |        10 | A1BG     |          62 |      1550 | 80dcb3d1bc2d2154d109dfa1287b561e | 2015-08-25 23:59:17.412518 |           1
 ENST00000595014 |        10 | A1BG     |             |           |                                  | 2015-08-25 23:59:17.412518 |           1
 ENST00000598345 |        10 | A1BG     |             |           |                                  | 2015-08-25 23:59:17.412518 |           1
 ENST00000600966 |        10 | A1BG     |           0 |       917 | 8c35c193d0252d7b0003d70ca5b1ea5a | 2015-08-25 23:59:17.412518 |           1
 ENST00000594950 |        10 | A1BG-AS1 |             |           |                                  | 2015-08-25 23:59:17.412518 |           1
 ENST00000593374 |        10 | A1BG-AS1 |             |           |                                  | 2015-08-25 23:59:17.412518 |           1
 ENST00000599728 |        10 | A1BG-AS1 |             |           |                                  | 2015-08-25 23:59:17.412518 |           1
 ENST00000593960 |        10 | A1BG-AS1 |             |           |                                  | 2015-08-25 23:59:17.412518 |           1
 ENST00000600379 |        10 | A1BG-AS1 |             |           |                                  | 2015-08-25 23:59:17.412518 |           1
(10 rows)

@sptaylor sptaylor marked this pull request as ready for review April 8, 2024 18:59
@sptaylor sptaylor requested review from bsgiles73 and nvta1209 April 8, 2024 19:00
Copy link

@bsgiles73 bsgiles73 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks for the README documentation for Alembic

@sptaylor sptaylor merged commit a072cb1 into main Apr 8, 2024
1 check passed
@sptaylor sptaylor deleted the IPVC-2280 branch April 8, 2024 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants