Skip to content

Commit

Permalink
fix(IPVC-2399): fix gene id back fill migration script, update paths … (
Browse files Browse the repository at this point in the history
  • Loading branch information
bsgiles73 authored Apr 26, 2024
1 parent 8ff7464 commit b915f31
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
5 changes: 3 additions & 2 deletions misc/gene-update/backfill_gene_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import uta
from uta.models import Gene, Transcript
from uta.tools.file_utils import open_file


logger = None
Expand All @@ -22,7 +23,7 @@ def backfill_gene(uta_session: Session, gene_update_file: str) -> None:
now_ts = datetime.now()
i = 0
new_genes = []
with open(gene_update_file) as f:
with open_file(gene_update_file) as f:
for line in f:
if line.startswith("gene_id"):
continue
Expand Down Expand Up @@ -70,7 +71,7 @@ def backfill_transcript(uta_session: Session, transcript_update_file: str) -> No
tx_ac_to_gene_id = {}

logger.info(f"Reading transcript to gene id mappings from {transcript_update_file}")
with open(transcript_update_file) as f:
with open_file(transcript_update_file) as f:
for line in f:
if line.startswith("origin"):
continue
Expand Down
4 changes: 2 additions & 2 deletions misc/gene-update/upgrade-uta-schema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ alembic -c etc/alembic.ini upgrade 595a586e6de7
# run data migration to back fill gene_id
python misc/gene-update/backfill_gene_id.py \
postgresql://uta_admin:@localhost/uta \
/workdir/backfill/gene_update.tsv \
/workdir/backfill/transcript_update.tsv
misc/gene-update/gene_update.tsv.gz \
misc/gene-update/transcript_update.tsv.gz

# run Alembic migrations to add constraints and update existing views
alembic -c etc/alembic.ini upgrade head
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,17 @@ def upgrade() -> None:
unique=False,
schema="uta",
)
op.create_foreign_key(
"fk_uta_transcript_gene_gene_id",
"transcript",
"gene",
["gene_id"],
["gene_id"],
source_schema="uta",
referent_schema="uta",
onupdate="RESTRICT",
ondelete="RESTRICT",
)
op.create_foreign_key(None, 'transcript', 'gene', ['gene_id'], ['gene_id'], source_schema='uta', referent_schema='uta')
# ### end Alembic commands ###

# ### handle first part of hgnc -> gene_symbol column rename ###
op.add_column("gene", sa.Column("symbol", sa.Text(), nullable=True), schema="uta")
op.create_index(op.f("ix_uta_gene_symbol"), "gene", ["symbol"], unique=False, schema="uta")
op.execute("UPDATE gene SET symbol = hgnc;")
op.alter_column('gene', 'symbol',
existing_type=sa.TEXT(),
nullable=False,
schema='uta')
# ### end of hgnc -> gene_symbol column rename ###

# ### updates required to existing views needed to drop hgnc from transcript. ###
Expand Down Expand Up @@ -301,7 +295,7 @@ def downgrade() -> None:
# ### end of updates to views ###

# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint("fk_uta_transcript_gene_gene_id", "transcript", schema="uta", type_="foreignkey")
op.drop_constraint(None, 'transcript', schema='uta', type_='foreignkey')
op.drop_index(op.f("ix_uta_transcript_gene_id"), table_name="transcript", schema="uta")
op.alter_column("transcript", "gene_id",
existing_type=sa.TEXT(),
Expand Down

0 comments on commit b915f31

Please sign in to comment.