From 7d78e6cca866ae299ae9b046368e776c43edbe4b Mon Sep 17 00:00:00 2001 From: Kori Kuzma Date: Tue, 4 Apr 2023 08:54:48 -0700 Subject: [PATCH] refactor: add back UTADatabase.liftover_38_to_37 (#143) --- cool_seq_tool/data_sources/uta_database.py | 16 +++++++++++++++- cool_seq_tool/version.py | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/cool_seq_tool/data_sources/uta_database.py b/cool_seq_tool/data_sources/uta_database.py index a4b1c7b9..089b0a3e 100644 --- a/cool_seq_tool/data_sources/uta_database.py +++ b/cool_seq_tool/data_sources/uta_database.py @@ -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: @@ -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() @@ -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 @@ -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. @@ -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 diff --git a/cool_seq_tool/version.py b/cool_seq_tool/version.py index 569b1212..0c5c3007 100644 --- a/cool_seq_tool/version.py +++ b/cool_seq_tool/version.py @@ -1 +1 @@ -__version__ = "0.1.10" +__version__ = "0.1.11"