File size: 4,712 Bytes
765c2b7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | import hashlib, json, os, re, stat, sys, datetime
R="/ibex/project/c2041/hany0c/bench_h2h_20260915/real"
APPROVAL_TEXT="批准,先跑我们的模型,快速的先出一个结果我看看"
APPROVAL={"text": APPROVAL_TEXT, "by": "Larry", "date": "2026-09-15", "relayed_by": "orchestrator (real-data quick-look task prompt)"}
E="https://ftp.1000genomes.ebi.ac.uk/vol1/ftp/data_collections"
VCF=E+"/1000G_2504_high_coverage/working/20220422_3202_phased_SNV_INDEL_SV/1kGP_high_coverage_Illumina.chr2.filtered.SNV_INDEL_SV_phased_panel.vcf.gz"
items=[
("ped", E+"/1000G_2504_high_coverage/20130606_g1k_3202_samples_ped_population.txt","ref",97483,"quick-look approval 2026-09-15"),
("gap","https://hgdownload.soe.ucsc.edu/goldenPath/hg38/database/gap.txt.gz","ref",12368,"T0 (previously approved)"),
("centromeres","https://hgdownload.soe.ucsc.edu/goldenPath/hg38/database/centromeres.txt.gz","ref",1549,"T0 (previously approved)"),
("pilot_mask",E+"/1000_genomes_project/working/20160622_genome_mask_GRCh38/PilotMask/20160622.allChr.pilot_mask.bed","ref",16728941,"T0 (previously approved)"),
("strict_mask",E+"/1000_genomes_project/working/20160622_genome_mask_GRCh38/StrictMask/20160622.allChr.mask.bed","ref",128218530,"T0 (previously approved)"),
("vcf_tbi",VCF+".tbi","raw",None,"quick-look approval 2026-09-15 (tbi named as part of the approval; size taken from HEAD)"),
("vcf",VCF,"raw",2506332497,"quick-look approval 2026-09-15"),
]
log=open(R+"/logs/download.log").read().splitlines()
def logtime(kind,name):
for l in log:
p=l.split()
if len(p)>=3 and p[1]==kind and p[2]==name: return p[0]
def sha(path):
h=hashlib.sha256()
with open(path,"rb") as f:
for b in iter(lambda: f.read(8<<20), b""): h.update(b)
return h.hexdigest()
def hdrs(path):
d={}
for l in open(path, encoding="latin-1"):
l=l.strip()
if l.startswith("HTTP/"): d["status_line"]=l
elif ":" in l:
k,v=l.split(":",1); k=k.strip().lower()
if k in ("content-length","last-modified","etag","content-type","accept-ranges","date","server"): d[k]=v.strip()
return d
out={"schema":"bench_h2h real-data downloads v1","written_utc":datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ"),
"actor":"download","approval":APPROVAL,
"scope_rule":"ONLY these files may be downloaded for the real-data quick look (no other chromosomes, no Ensembl ancestor, no other maps)",
"method":{"host":"login509-02-r (Ibex login node), single stream, sequential",
"head":"curl -sS -I -L --retry 5 --retry-delay 10 URL > headers/<basename>.headers",
"get":"curl -sS -L --fail --retry 20 --retry-delay 15 --retry-connrefused -C - -o <dest> URL",
"checks":"HEAD Content-Length == approved bytes (refuse otherwise; tbi: HEAD only); bytes on disk == Content-Length; sha256sum of the on-disk file; chmod a-w",
"script":"real/scripts/download_real.sh","script_sha256":sha(R+"/scripts/download_real.sh"),"log":"real/logs/download.log","log_sha256":sha(R+"/logs/download.log")},
"files":[]}
for name,url,d,approved,basis in items:
base=os.path.basename(url); f=f"{R}/{d}/{base}"; h=hdrs(f"{R}/headers/{base}.headers")
size=os.stat(f).st_size; s=sha(f); side=open(f+".sha256").read().split()[0]
cl=int(h["content-length"])
assert size==cl and s==side and (approved is None or approved==cl), name
assert not (os.stat(f).st_mode & (stat.S_IWUSR|stat.S_IWGRP|stat.S_IWOTH)), name
out["files"].append({"name":name,"url":url,"path":f"real/{d}/{base}","approval_basis":basis,
"approved_bytes":approved,"head":h,"headers_file":f"real/headers/{base}.headers","bytes":size,
"content_length_match":size==cl,"sha256":s,"sha256_sidecar":f"real/{d}/{base}.sha256",
"head_utc":logtime("HEAD",name),"done_utc":logtime("DONE",name),"mode":oct(os.stat(f).st_mode & 0o777)})
dec=f"{R}/ref/decode2019_avg_hg38.bed"
ds=sha(dec); assert ds==open(dec+".sha256").read().split()[0]
out["copies"]=[{"name":"decode2019_avg_hg38","source":"laptop:/Users/larryivanhan/Desktop/Projects/genomics/DLCoal/maps/recomb_map/output/decode2019_avg_hg38.bed",
"source_sha256":sys.argv[1],"path":"real/ref/decode2019_avg_hg38.bed","bytes":os.stat(dec).st_size,"sha256":ds,
"sha_match":ds==sys.argv[1],"mode":oct(os.stat(dec).st_mode & 0o777),"note":"local copy, not a download; built by maps/recomb_map/build_decode2019.py"}]
tmp=R+"/.DOWNLOADS.partial.json"
with open(tmp,"w") as fh: json.dump(out,fh,indent=1,ensure_ascii=False); fh.write("\n")
os.chmod(tmp,0o444); os.link(tmp,R+"/DOWNLOADS.json"); os.unlink(tmp)
print(sha(R+"/DOWNLOADS.json"))
for x in out["files"]+out["copies"]: print(x["name"],x["bytes"],x["sha256"],x.get("done_utc"))
|