Step 01
Resolve coordinates from an authority, never from memory
Every pharmacogenomic variant has a canonical rsID and a build-specific position. Hardcoding positions is how a PGx pipeline silently produces wrong diplotypes after an assembly change. Two of the twelve coordinates I first wrote from memory were wrong, which is the whole argument for this step.
Code
def resolve_coords(rsids): """GRCh38 coordinates from Ensembl -- never hardcoded from memory.""" req = urllib.request.Request( "https://rest.ensembl.org/variation/homo_sapiens?content-type=application/json", data=json.dumps({"ids": rsids}).encode(), headers={"Content-Type": "application/json", "Accept": "application/json"}) data = json.load(urllib.request.urlopen(req, timeout=120)) out = {} for rs in rsids: v = data.get(rs) # drop patch/alt scaffolds; keep the primary GRCh38 assembly only m = [x for x in v["mappings"] if x["assembly_name"] == "GRCh38" and "_" not in str(x["seq_region_name"])][0] out[rs] = {"chrom": str(m["seq_region_name"]), "pos": int(m["start"])} return out