Skip to content

Commit 294a2e6

Browse files
authored
feat: allow user to provide own chain file for pyliftover (#136) (#137)
- Can set via UTADatabase parameters, environment variables (LIFTOVER_CHAIN_37_TO_38, LIFTOVER_CHAIN_38_TO_37), else will use pyliftover default methods to download from UCSC
1 parent 66ba20a commit 294a2e6

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

cool_seq_tool/data_sources/uta_database.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,53 @@
2121
# use `bound` to upper-bound UTADatabase or child classes
2222
UTADatabaseType = TypeVar("UTADatabaseType", bound="UTADatabase")
2323

24+
# Environment variables for paths to chain files for pyliftover
25+
LIFTOVER_CHAIN_37_TO_38 = environ.get("LIFTOVER_CHAIN_37_TO_38")
26+
LIFTOVER_CHAIN_38_TO_37 = environ.get("LIFTOVER_CHAIN_38_TO_37")
27+
2428

2529
class UTADatabase:
2630
"""Class for connecting and querying UTA database."""
2731

28-
def __init__(self, db_url: str = UTA_DB_URL, db_pwd: str = "") -> None:
32+
def __init__(
33+
self,
34+
db_url: str = UTA_DB_URL,
35+
db_pwd: str = "",
36+
chain_file_37_to_38: Optional[str] = None,
37+
chain_file_38_to_37: Optional[str] = None
38+
) -> None:
2939
"""Initialize DB class. Downstream libraries should use the create()
3040
method to construct a new instance: await UTADatabase.create()
3141
32-
:param str db_url: PostgreSQL connection URL
42+
:param db_url: PostgreSQL connection URL
3343
Format: `driver://user:pass@host/database/schema`
34-
:param str db_pwd: User's password for uta database
44+
:param db_pwd: User's password for uta database
45+
:param chain_file_37_to_38: Optional path to chain file for 37 to 38 assembly.
46+
This is used for pyliftover. If this is not provided, will check to see if
47+
LIFTOVER_CHAIN_37_TO_38 env var is set. If neither is provided, will allow
48+
pyliftover to download a chain file from UCSC
49+
:param chain_file_38_to_37: Optional path to chain file for 38 to 37 assembly.
50+
This is used for pyliftover. If this is not provided, will check to see if
51+
LIFTOVER_CHAIN_38_TO_37 env var is set. If neither is provided, will allow
52+
pyliftover to download a chain file from UCSC
3553
"""
3654
self.schema = None
3755
self.db_url = db_url
3856
self.db_pwd = db_pwd
3957
self._connection_pool = None
4058
self.args = self._get_conn_args()
41-
self.liftover_37_to_38 = LiftOver("hg19", "hg38")
42-
self.liftover_38_to_37 = LiftOver("hg38", "hg19")
59+
60+
chain_file_37_to_38 = chain_file_37_to_38 or LIFTOVER_CHAIN_37_TO_38
61+
if chain_file_37_to_38:
62+
self.liftover_37_to_38 = LiftOver(chain_file_37_to_38)
63+
else:
64+
self.liftover_37_to_38 = LiftOver("hg19", "hg38")
65+
66+
chain_file_38_to_37 = chain_file_38_to_37 or LIFTOVER_CHAIN_38_TO_37
67+
if chain_file_38_to_37:
68+
self.liftover_38_to_37 = LiftOver(chain_file_38_to_37)
69+
else:
70+
self.liftover_38_to_37 = LiftOver("hg38", "hg19")
4371

4472
@staticmethod
4573
def _update_db_url(db_pwd: str, db_url: str) -> str:

cool_seq_tool/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.1.8"
1+
__version__ = "0.1.9"

0 commit comments

Comments
 (0)