Skip to content
Permalink
main
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
executable file 46 lines (32 sloc) 1.21 KB
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)))