Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions pheweb/serve/data_access/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -1858,15 +1858,25 @@ def get_by_variant(self, variant):


class LofMySQLDao(LofDB):
def __init__(self, authentication_file, table_name="lof"):
def __init__(self,
authentication_file,
table_name="lof",
search_table_name: Optional[str] = None):
"""
Args:
search_table_name: Table to search for a particular gene. Genes may have aliases
and it is expected to resolve aliases in this search. If None, defaults to
table_name (preserving the old behavior).
"""
self.authentication_file = authentication_file
auth_module = load_source("mysql_auth", self.authentication_file)
self.user = getattr(auth_module, "mysql")["user"]
self.password = getattr(auth_module, "mysql")["password"]
self.host = getattr(auth_module, "mysql")["host"]
self.db = getattr(auth_module, "mysql")["db"]
self.release = getattr(auth_module, "mysql")["release"]
self.table_name=table_name
self.table_name = table_name
self.search_table_name = search_table_name or self.table_name

def get_connection(self):
return pymysql.connect(
Expand All @@ -1888,7 +1898,7 @@ def get_lofs(self, gene):
conn = self.get_connection()
try:
with conn.cursor(pymysql.cursors.DictCursor) as cursori:
sql = f"SELECT * FROM {self.table_name} WHERE rel=%s AND gene=%s"
sql = f"SELECT * FROM {self.search_table_name} WHERE rel=%s AND gene=%s"
cursori.execute(sql, [self.release, gene])
result = [{"gene_data": data} for data in cursori.fetchall()]
finally:
Expand Down