Skip to content

Commit

Permalink
refactor: add back UTADatabase.liftover_38_to_37 (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
korikuzma authored Apr 4, 2023
1 parent c8126d9 commit 7d78e6c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion cool_seq_tool/data_sources/uta_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

# Environment variables for paths to chain files for pyliftover
LIFTOVER_CHAIN_37_TO_38 = environ.get("LIFTOVER_CHAIN_37_TO_38")
LIFTOVER_CHAIN_38_TO_37 = environ.get("LIFTOVER_CHAIN_38_TO_37")


class UTADatabase:
Expand All @@ -32,7 +33,8 @@ def __init__(
self,
db_url: str = UTA_DB_URL,
db_pwd: str = "",
chain_file_37_to_38: Optional[str] = None
chain_file_37_to_38: Optional[str] = None,
chain_file_38_to_37: Optional[str] = None
) -> None:
"""Initialize DB class. Downstream libraries should use the create()
method to construct a new instance: await UTADatabase.create()
Expand All @@ -44,6 +46,10 @@ def __init__(
This is used for pyliftover. If this is not provided, will check to see if
LIFTOVER_CHAIN_37_TO_38 env var is set. If neither is provided, will allow
pyliftover to download a chain file from UCSC
:param chain_file_38_to_37: Optional path to chain file for 38 to 37 assembly.
This is used for pyliftover. If this is not provided, will check to see if
LIFTOVER_CHAIN_38_TO_37 env var is set. If neither is provided, will allow
pyliftover to download a chain file from UCSC
"""
self.schema = None
self.db_url = db_url
Expand All @@ -57,6 +63,12 @@ def __init__(
else:
self.liftover_37_to_38 = LiftOver("hg19", "hg38")

chain_file_38_to_37 = chain_file_38_to_37 or LIFTOVER_CHAIN_38_TO_37
if chain_file_38_to_37:
self.liftover_38_to_37 = LiftOver(chain_file_38_to_37)
else:
self.liftover_38_to_37 = LiftOver("hg38", "hg19")

@staticmethod
def _update_db_url(db_pwd: str, db_url: str) -> str:
"""Return new db_url containing password.
Expand Down Expand Up @@ -1010,6 +1022,8 @@ def get_liftover(self, chromosome: str, pos: int,

if liftover_to_assembly == Assembly.GRCH38:
liftover = self.liftover_37_to_38.convert_coordinate(chromosome, pos)
elif liftover_to_assembly == Assembly.GRCH37:
liftover = self.liftover_38_to_37.convert_coordinate(chromosome, pos)
else:
logger.warning(f"{liftover_to_assembly} assembly not supported")
liftover = None
Expand Down
2 changes: 1 addition & 1 deletion cool_seq_tool/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.10"
__version__ = "0.1.11"

0 comments on commit 7d78e6c

Please sign in to comment.