Skip to content

Commit

Permalink
Fix SA2.0 ORM usage in galaxy.visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavcs committed Sep 21, 2023
1 parent 33083a8 commit 5f64930
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions lib/galaxy/visualization/genomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,12 @@ def chroms(self, trans, dbkey=None, num=None, chrom=None, low=None):
Returns a naturally sorted list of chroms/contigs for a given dbkey.
Use either chrom or low to specify the starting chrom in the return list.
"""
session = trans.sa_session
self.check_and_reload()
# 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 = get_user_by_username(session, dbkey_owner)
else:
dbkey_user = trans.user

Expand All @@ -309,12 +310,9 @@ def chroms(self, trans, dbkey=None, num=None, chrom=None, low=None):
if dbkey in user_keys:
dbkey_attributes = user_keys[dbkey]
dbkey_name = dbkey_attributes["name"]

# 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 = session.get(HistoryDatasetAssociation, dbkey_attributes["fasta"])
len_file = build_fasta.get_converted_dataset(trans, "len").file_name
build_fasta.get_converted_dataset(trans, "twobit")
# HACK: set twobit_file to True rather than a file name because
Expand All @@ -323,11 +321,7 @@ 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 = session.get(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 @@ -376,7 +370,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 = get_user_by_username(trans.sa_session, dbkey_owner)
else:
dbkey_user = trans.user

Expand All @@ -393,9 +387,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(HistoryDatasetAssociation, dbkey_attributes["fasta"])
msg = fasta_dataset.convert_dataset(trans, "twobit")
if msg:
return msg
Expand Down

0 comments on commit 5f64930

Please sign in to comment.