Skip to content

Commit

Permalink
Fix SA2.0 (query->select) in galaxy.visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavcs committed Aug 7, 2023
1 parent 14e5784 commit 742ba08
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions lib/galaxy/visualization/genomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Dict

from bx.seq.twobit import TwoBitFile
from sqlalchemy import select

from galaxy.exceptions import (
ObjectNotFound,
Expand Down Expand Up @@ -291,7 +292,7 @@ def chroms(self, trans, dbkey=None, num=None, chrom=None, low=None):
# If there is no dbkey owner, default to current user.
dbkey_owner, dbkey = decode_dbkey(dbkey)
if dbkey_owner:
dbkey_user = trans.sa_session.query(trans.app.model.User).filter_by(username=dbkey_owner).first()
dbkey_user = self._get_dbkey_user(trans, dbkey_owner)
else:
dbkey_user = trans.user

Expand All @@ -310,8 +311,8 @@ def chroms(self, trans, dbkey=None, num=None, chrom=None, low=None):

# If there's a fasta for genome, convert to 2bit for later use.
if "fasta" in dbkey_attributes:
build_fasta = trans.sa_session.query(trans.app.model.HistoryDatasetAssociation).get(
dbkey_attributes["fasta"]
build_fasta = trans.sa_session.get(
trans.app.model.HistoryDatasetAssociation, dbkey_attributes["fasta"]
)
len_file = build_fasta.get_converted_dataset(trans, "len").file_name
build_fasta.get_converted_dataset(trans, "twobit")
Expand All @@ -321,11 +322,9 @@ def chroms(self, trans, dbkey=None, num=None, chrom=None, low=None):
twobit_file = True
# Backwards compatibility: look for len file directly.
elif "len" in dbkey_attributes:
len_file = (
trans.sa_session.query(trans.app.model.HistoryDatasetAssociation)
.get(user_keys[dbkey]["len"])
.file_name
)
len_file = trans.sa_session.get(
trans.app.model.HistoryDatasetAssociation, user_keys[dbkey]["len"]
).file_name
if len_file:
genome = Genome(dbkey, dbkey_name, len_file=len_file, twobit_file=twobit_file)

Expand Down Expand Up @@ -374,7 +373,7 @@ def reference(self, trans, dbkey, chrom, low, high):
# If there is no dbkey owner, default to current user.
dbkey_owner, dbkey = decode_dbkey(dbkey)
if dbkey_owner:
dbkey_user = trans.sa_session.query(trans.app.model.User).filter_by(username=dbkey_owner).first()
dbkey_user = self._get_dbkey_user(trans, dbkey_owner)
else:
dbkey_user = trans.user

Expand All @@ -391,9 +390,7 @@ def reference(self, trans, dbkey, chrom, low, high):
else:
user_keys = loads(dbkey_user.preferences["dbkeys"])
dbkey_attributes = user_keys[dbkey]
fasta_dataset = trans.sa_session.query(trans.app.model.HistoryDatasetAssociation).get(
dbkey_attributes["fasta"]
)
fasta_dataset = trans.sa_session.get(trans.app.model.HistoryDatasetAssociation, dbkey_attributes["fasta"])
msg = fasta_dataset.convert_dataset(trans, "twobit")
if msg:
return msg
Expand All @@ -411,3 +408,7 @@ def _get_reference_data(twobit_file_name, chrom, low, high):
if chrom in twobit:
seq_data = twobit[chrom].get(int(low), int(high))
return GenomeRegion(chrom=chrom, start=low, end=high, sequence=seq_data)

def _get_dbkey_user(self, trans, dbkey_owner):
stmt = select(trans.app.model.User).filter_by(username=dbkey_owner).limit(1)
return trans.sa_session.scalars(stmt).first()

0 comments on commit 742ba08

Please sign in to comment.