2323
2424# Environment variables for paths to chain files for pyliftover
2525LIFTOVER_CHAIN_37_TO_38 = environ .get ("LIFTOVER_CHAIN_37_TO_38" )
26+ LIFTOVER_CHAIN_38_TO_37 = environ .get ("LIFTOVER_CHAIN_38_TO_37" )
2627
2728
2829class UTADatabase :
@@ -32,7 +33,8 @@ def __init__(
3233 self ,
3334 db_url : str = UTA_DB_URL ,
3435 db_pwd : str = "" ,
35- chain_file_37_to_38 : Optional [str ] = None
36+ chain_file_37_to_38 : Optional [str ] = None ,
37+ chain_file_38_to_37 : Optional [str ] = None
3638 ) -> None :
3739 """Initialize DB class. Downstream libraries should use the create()
3840 method to construct a new instance: await UTADatabase.create()
@@ -44,6 +46,10 @@ def __init__(
4446 This is used for pyliftover. If this is not provided, will check to see if
4547 LIFTOVER_CHAIN_37_TO_38 env var is set. If neither is provided, will allow
4648 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
4753 """
4854 self .schema = None
4955 self .db_url = db_url
@@ -57,6 +63,12 @@ def __init__(
5763 else :
5864 self .liftover_37_to_38 = LiftOver ("hg19" , "hg38" )
5965
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" )
71+
6072 @staticmethod
6173 def _update_db_url (db_pwd : str , db_url : str ) -> str :
6274 """Return new db_url containing password.
@@ -1010,6 +1022,8 @@ def get_liftover(self, chromosome: str, pos: int,
10101022
10111023 if liftover_to_assembly == Assembly .GRCH38 :
10121024 liftover = self .liftover_37_to_38 .convert_coordinate (chromosome , pos )
1025+ elif liftover_to_assembly == Assembly .GRCH37 :
1026+ liftover = self .liftover_38_to_37 .convert_coordinate (chromosome , pos )
10131027 else :
10141028 logger .warning (f"{ liftover_to_assembly } assembly not supported" )
10151029 liftover = None
0 commit comments