Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
sv-conflict-analysis/liftover.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
46 lines (32 sloc)
1.21 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pathlib import Path | |
import sys | |
from pyliftover import LiftOver | |
from conflict_positions import Region | |
LIFTOVER_DIR = Path("/confidential/tGenVar/ref/liftover") | |
HG38_T2T_v1_0_CHAIN = LIFTOVER_DIR / "hg38_to_t2t/FINAL/merged.over.chain" | |
T2T_v1_0_TO_v1_1_CHAIN = LIFTOVER_DIR / "t2t_v1.0_to_v1.1/t2t_v1.0_to_v1.1.chain" | |
# preload the chain files for better caching | |
lo_1 = LiftOver(str(HG38_T2T_v1_0_CHAIN)) | |
lo_2 = LiftOver(str(T2T_v1_0_TO_v1_1_CHAIN)) | |
def lift(lo, region: Region): | |
chrom, start, end = region.vals() | |
conversions_1 = lo.convert_coordinate(chrom, start) | |
conversions_2 = lo.convert_coordinate(chrom, end) | |
if not conversions_1 or not conversions_2: | |
return None | |
else: | |
return Region(chrom, conversions_1[0][1], conversions_2[0][1]) | |
def lift_hg38_to_t2t_v1_0(region: Region): | |
return lift(lo_1, region) | |
def lift_t2t_v1_0_to_v1_1(region: Region): | |
return lift(lo_2, region) | |
def lift_hg38_to_t2t_v1_1(region: Region): | |
r = lift_hg38_to_t2t_v1_0(region) | |
if r is None: | |
return None | |
else: | |
return lift_t2t_v1_0_to_v1_1(r) | |
if __name__ == "__main__": | |
regions = sys.argv[1:] | |
for r in regions: | |
print(lift_hg38_to_t2t_v1_1(Region.from_str(r))) | |