carbon-a-release / access.js
lvwerra's picture
lvwerra HF Staff
Freeze clicked strands until outside release and add verified assembly downloads
c5eee7b verified
Raw History Blame Contribute Delete
2.96 kB
// Paths come from downloaded assembly metadata, never a guessed repository URL.
function annotationPath(a){return D.loci.paths[a.accession]||null}
function updateDataAccess(a){
const path=annotationPath(a),known=!!path;
$('#sel-files').hidden=!known;$('#sel-files').href=known?'https://huggingface.co/buckets/'+D.loci.bucket+'/tree/'+path:'';
$('#sel-download').textContent=known?'Download code':'Check annotation files ↗';
$('#sel-availability').textContent=known?'GFF3 · coding sequences · proteins':'Gene files are not recorded in this snapshot.';
}
function annotationCode(a){
const bucket=D.loci.bucket,path=annotationPath(a);
const setup=`from pathlib import Path\nfrom huggingface_hub import HfApi\n\napi = HfApi() # uses your saved Hugging Face login\nbucket = ${JSON.stringify(bucket)}\naccession = ${JSON.stringify(a.accession)}\n`;
const lookup=path?`prefix = ${JSON.stringify(path)}\n`:`divisions = [\n "fungi", "invertebrate", "plant", "protozoa",\n "vertebrate_mammalian", "vertebrate_other",\n]\nmetadata = list(api.get_bucket_paths_info(\n bucket, [f"cds/{d}/{accession}/metadata.json" for d in divisions]\n))\nif not metadata:\n raise FileNotFoundError(\n f"No published gene files found for {accession}."\n )\nprefix = metadata[0].path.rsplit("/", 1)[0]\n`;
return setup+lookup+`\noutput = Path(accession)\noutput.mkdir(parents=True, exist_ok=True)\nfiles = [\n "annotations.gff3.gz", # predicted gene / CDS coordinates\n "cds.fna.gz", # coding nucleotide sequences\n "proteins.faa.gz", # predicted protein sequences\n "metadata.json", # counts and pipeline provenance\n]\napi.download_bucket_files(\n bucket,\n [(f"{prefix}/{name}", output / name) for name in files],\n raise_on_missing_files=True,\n)\n`;
}
function showDataAccess(a){
if(!a)return;stopSweep();selectAssembly(a);
const path=annotationPath(a);
$('#data-assembly').textContent=a.name+' · '+a.accession;
$('#data-description').textContent=path?'Download the published predictions for this assembly, with pipeline provenance.':'This snapshot has no published gene-file path for this assembly. The code below checks the current bucket and downloads the files if available.';
$('#data-browse').href='https://huggingface.co/buckets/'+D.loci.bucket+'/tree/'+(path||'cds');
$('#data-browse').textContent=path?'Browse this assembly’s files ↗':'Browse published gene files ↗';
$('#data-code').textContent=annotationCode(a);$('#copy-status').textContent='';$('#data-dialog').showModal();
}
async function copyDataCode(){
const code=$('#data-code').textContent;
try{await navigator.clipboard.writeText(code);$('#copy-status').textContent='Copied'}
catch{const range=document.createRange();range.selectNodeContents($('#data-code'));const selection=window.getSelection();selection.removeAllRanges();selection.addRange(range);$('#copy-status').textContent='Code selected — press Ctrl/Cmd+C'}
}