|
21 | 21 | # use `bound` to upper-bound UTADatabase or child classes |
22 | 22 | UTADatabaseType = TypeVar("UTADatabaseType", bound="UTADatabase") |
23 | 23 |
|
| 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 | + |
24 | 28 |
|
25 | 29 | class UTADatabase: |
26 | 30 | """Class for connecting and querying UTA database.""" |
27 | 31 |
|
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: |
29 | 39 | """Initialize DB class. Downstream libraries should use the create() |
30 | 40 | method to construct a new instance: await UTADatabase.create() |
31 | 41 |
|
32 | | - :param str db_url: PostgreSQL connection URL |
| 42 | + :param db_url: PostgreSQL connection URL |
33 | 43 | 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 |
35 | 53 | """ |
36 | 54 | self.schema = None |
37 | 55 | self.db_url = db_url |
38 | 56 | self.db_pwd = db_pwd |
39 | 57 | self._connection_pool = None |
40 | 58 | 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") |
43 | 71 |
|
44 | 72 | @staticmethod |
45 | 73 | def _update_db_url(db_pwd: str, db_url: str) -> str: |
|
0 commit comments