e6d1189bea4cc541396f842b65a3392c33c8e734
max
  Wed Sep 2 02:55:03 2026 -0700
hprc2annot: put the collection in git and fix the QA findings

The HPRC Release 2 GenArk contributed track collection (7 tracks x 462
assemblies) had only its one-line betaGenArk.txt enable checked in. Add the
makeDoc, the build scripts, the seven track description pages and the trackDb
stanzas, and fix the problems QA found.

Data fixes, both rebuilt across all 462 assemblies:

- liftoff: gff3ToGenePred was naming each genePred after the gene, so every
transcript of a gene shared one name, the RefSeq accession was lost and the
transcript_biotype lookup never matched (type empty on 99.8% of rows). Pass
-rnaNameAttr=ID. Duplicate (chrom,start,end,name) tuples go from 24,969 to 0
and type is now empty on 2,132 of 82,973,730 rows. The same flag is a no-op
on the CAT GFF3 (byte-identical output), so both gene tracks now share one
code path and CAT needs no rebuild.

- segdups: the build read SEDEF column 6, strand1, which is "+" by construction
on every row, so every inverted duplication rendered forward. Use column 14,
strand2, the orientation of the paralogous copy: 13.8M + and 13.8M - across
the collection. Also translate the paralog partner out of PanSN through the
GenArk chromAlias, since the browser does not translate a plain text field,
and store identity as a percentage so the mouseover can read it.

hprc2annotFixBed.sh is not idempotent for pclai: a second run re-parses an
already-parsed name and blanks the values. It now refuses to touch a converted
file. GCA_041900255.1 was damaged that way and is rebuilt from source.

Provenance, all from the QA report:

- stats.tsv is appended to rather than truncated on every run, and each run
regenerates log/summary.tsv, a per-track roll-up over the collection.
- dataVersion on all seven tracks.
- Rows are now dropped for exactly two reasons and both are counted: past the
end of the sequence, or a sequence name absent from the assembly, which also
warns with example names. Only GCA_018472765.3 trips the second, the known
upstream contig-version mismatch. genePredToBigGenePred failure is checked
and an empty conversion result is a failure, not a valid empty bigBed.

Description pages: fix a raw UTF-8 character, rewrite the segdups and pclai
display conventions which still described the data before the name field was
blanked, add a color legend checked against the data, add the pcLAI preprint
(from the Crossref record, since it has no PMID), and correct the stated reason
liftoff drops transcripts.

Display: title case on the short labels, "Active centromeres" shortened to fit
the 17-character limit, pcLAI to pack since it has no readable dense state,
liftoff and segdups to dense, and a filter on the segdups original flag.

refs #35415

diff --git src/hg/makeDb/scripts/hprc2annot/hprc2annotMakeTrackDb.py src/hg/makeDb/scripts/hprc2annot/hprc2annotMakeTrackDb.py
new file mode 100755
index 00000000000..a3bbd1a95b8
--- /dev/null
+++ src/hg/makeDb/scripts/hprc2annot/hprc2annotMakeTrackDb.py
@@ -0,0 +1,114 @@
+#!/usr/bin/env python3
+"""Generate genomes.txt and per-assembly trackDb.txt for the hprc2annot hub.
+
+The stanzas live in the kent source tree, not in this script:
+    kent/src/hg/makeDb/trackDb/contrib/hprc2annot/hprc2annot.trackDb.txt
+together with the seven track description pages. This script reads that file,
+walks the hub directory, and for every GCA_* assembly dir writes a trackDb.txt
+holding only the stanzas whose data file is actually present.
+
+It also refreshes the hub's docs/ directory so the description pages served to
+users are the ones in git. The kent copy is the master; docs/ holds real copies
+rather than symlinks, because the hub files are served by apache and pushed to
+hgdownload and must not depend on a developer's home directory. Run --check to
+report what is out of date without writing anything.
+"""
+import filecmp
+import os
+import shutil
+import sys
+
+HUB = "/hive/data/genomes/asmHubs/contrib/hprc2annot"
+TDB = os.path.expanduser(
+    "~/kent/src/hg/makeDb/trackDb/contrib/hprc2annot")
+TEMPLATE = f"{TDB}/hprc2annot.trackDb.txt"
+
+
+def readStanzas(path):
+    """Parse the stanza template into a list of (dataFileName, stanzaText).
+
+    Stanzas are separated by blank lines; lines starting with # are comments.
+    The data file name comes from the stanza's bigDataUrl.
+    """
+    stanzas = []
+    cur = []
+    def flush():
+        if not cur:
+            return
+        text = "\n".join(cur)
+        fn = None
+        for line in cur:
+            if line.startswith("bigDataUrl "):
+                fn = line.split(None, 1)[1].strip()
+        if fn is None:
+            raise Exception(f"stanza without bigDataUrl in {path}:\n{text}")
+        stanzas.append((fn, text))
+        del cur[:]
+
+    with open(path) as f:
+        for line in f:
+            line = line.rstrip("\n")
+            if line.startswith("#"):
+                continue
+            if not line.strip():
+                flush()
+                continue
+            cur.append(line)
+    flush()
+    if not stanzas:
+        raise Exception(f"no stanzas found in {path}")
+    return stanzas
+
+
+def copyDocs(check):
+    """Refresh hub docs/<track>.html from the kent tree copy."""
+    docs = f"{HUB}/docs"
+    if not check:
+        os.makedirs(docs, exist_ok=True)
+    stale = 0
+    for name in sorted(os.listdir(TDB)):
+        if not name.endswith(".html"):
+            continue
+        src = f"{TDB}/{name}"
+        dst = f"{docs}/{name}"
+        if os.path.exists(dst) and filecmp.cmp(src, dst, shallow=False):
+            continue
+        stale += 1
+        if check:
+            print(f"docs/{name} differs from the kent tree")
+        else:
+            shutil.copyfile(src, dst)
+    return stale
+
+
+def main():
+    check = "--check" in sys.argv[1:]
+    stanzas = readStanzas(TEMPLATE)
+    stale = copyDocs(check)
+
+    accs = sorted(d for d in os.listdir(HUB)
+                  if d.startswith("GCA_") and os.path.isdir(f"{HUB}/{d}"))
+    genomes = []
+    for acc in accs:
+        adir = f"{HUB}/{acc}"
+        present = [st for fn, st in stanzas if os.path.exists(f"{adir}/{fn}")]
+        if not present:
+            continue
+        text = "\n\n".join(st.rstrip() for st in present) + "\n"
+        if not check:
+            with open(f"{adir}/trackDb.txt", "w") as out:
+                out.write(text)
+        genomes.append(f"genome {acc}\ntrackDb {acc}/trackDb.txt\n")
+
+    if not check:
+        with open(f"{HUB}/genomes.txt", "w") as g:
+            g.write("\n".join(genomes))
+    verb = "would write" if check else "wrote"
+    print(f"{verb} {len(genomes)} trackDb.txt files and genomes.txt "
+          f"from {len(stanzas)} stanzas; {stale} description pages "
+          f"{'out of date' if check else 'refreshed'}")
+    return 1 if (check and stale) else 0
+
+
+if __name__ == "__main__":
+    sys.exit(main())