# 2026-10-14 Claude atanzer: miRBase 22.1 microRNA precursors, hg38, #36988

# Human microRNA precursors from miRBase release 22.1 (https://mirbase.org/,
# Kozomara et al. 2019, PMID 30423142), shown in the Non-coding RNA collection
# (nonCodingRNAs). Items are the precursor hairpins, with the mature miRNAs
# drawn over them as decorators, and the RNAfold structure of each precursor on
# the details page (detailsScript.rnaStructure, drawn by
# src/hg/js/hgc.rnaStructure.js with the vendored fornac and d3 in js/external).
# Scripts: ~/kent/src/hg/makeDb/scripts/mirBase/

##############################################################################
# miRBase 22.1 (DONE 2026-10-14)
##############################################################################

mkdir -p /hive/data/genomes/hg38/bed/mirBase/download
cd /hive/data/genomes/hg38/bed/mirBase/download

# mirbase.org is often unreachable. The download script fetches
# https://mirbase.org/download/hsa.gff3; on 2026-10-14 the host did not resolve,
# so the file was copied from a download made on 2026-05-20 (534796 bytes):
bash ~/kent/src/hg/makeDb/scripts/mirBase/mirBaseDownload.sh \
    || cp -p /hive/users/atanzer/DATA/miRBase/v22.1/gff/hsa.gff3 .
# The file header says "miRBase v22, date 2018-3-5"; the human annotation is the
# same in releases 22 and 22.1. It was also compared with mirbase.dat of the same
# download: hairpin sequences, mature names, accessions and mature positions agree
# for all 1913 human accessions that have coordinates (mirbase.dat has 4 more,
# hsa-mir-1973, -3713, -378g and -4456, without genome coordinates).

# Notes on the source data, which the conversion script handles:
#   - 1918 precursor loci of 1913 accessions: hsa-mir-10401 is at 4 loci and
#     hsa-mir-4477a and hsa-mir-4477b at 2 each (IDs MI..., MI..._2, ...).
#   - A mature miRNA's Derives_from names the precursor accession, not the locus,
#     so the mature miRNAs of the extra loci are assigned to the locus with that
#     accession that contains them.
#   - 899 mature names have no -5p/-3p suffix; their arm is taken from the half
#     of the precursor they lie in.

cd /hive/data/genomes/hg38/bed/mirBase
# The build takes the sequence of every precursor from hg38, folds it with
# RNAfold -d2 (ViennaRNA 2.7.2, /cluster/bin/x86_64/RNAfold), and writes the
# track bigBed and the mature miRNA decorator bigBed.
# The MFE structure is not a hairpin at some precursors. A precursor counts as
# misfolded when its structure is not one hairpin, i.e. does not match the regular
# expression ^[(.]+\(\.+\)[).]+$ (one stem-loop; bulges and interior loops are
# allowed), or when a mature reaches into the hairpin loop. For these, the
# lowest-energy structure that is one hairpin with all matures in the stem is taken
# from RNAsubopt -d2 -s, searched up to 8 kcal/mol above the MFE. Where there is
# none, the structure is chosen by the hairpin test alone. RNAsubopt is not in
# /cluster/bin; the build uses ViennaRNA 2.7.2 from
# /cluster/home/atanzer/.local/miniforge3/bin/RNAsubopt (RNASUBOPT in
# mirBaseToBed.py). The field foldType says which structure is shown, with its
# energy; the mfe field is always the MFE.
bash ~/kent/src/hg/makeDb/scripts/mirBase/mirBaseBuild.sh
#   1918 precursor sequences
#   1918 precursors, 2883 matures, 1918 folds
#   1918 items, 63 not one hairpin and 77 with an arm in the hairpin loop in the MFE: 0 refolded with the flanks unpaired, 129 as suboptimal hairpins, all with the arms in the stem; 8 with an arm in the loop and 3 with no hairpin within 8 kcal/mol
#   arm in the hairpin loop: MI0001729
#   arm in the hairpin loop: MI0006327
#   arm in the hairpin loop: MI0015833
#   arm in the hairpin loop: MI0015866
#   arm in the hairpin loop: MI0016011
#   arm in the hairpin loop: MI0019310
#   arm in the hairpin loop: MI0021273
#   arm in the hairpin loop: MI0029321
#   no hairpin, MFE kept: MI0021279
#   no hairpin, MFE kept: MI0022631
#   no hairpin, MFE kept: MI0022689
#   structure chosen by hand: MI0021279, -35.10 kcal/mol
#   matures per arm: 3p 1441, 5p 1442

bigBedInfo mirBase.bb | grep itemCount
#   itemCount: 1,918
bigBedInfo mirBaseArms.bb | grep itemCount
#   itemCount: 2,883
# All precursors and mature miRNAs of the GFF are in the track; every mature
# miRNA lies inside exactly one precursor locus on the same strand.

# Checks done on the output:
#   - every folded sequence equals the hg38 sequence at the precursor
#     coordinates (strand-aware), and every armPositions range cuts exactly the
#     mature miRNA's hg38 sequence out of the folded sequence, on both strands
#   - the MFE structures of the 1910 precursors with a unique name are identical to
#     the ones in the earlier track hub

# The build also writes the trix search index mirBase.ix/.ixx (precursor name, MI
# accession, mature names and MIMAT accessions), used by searchTrix; trix searches
# are case-insensitive.

# The 130 suboptimal hairpins are 0 to 7.6 kcal/mol above the MFE (median 1.1).
# Matures still reach into the hairpin loop at 8 precursors, as no single hairpin
# within 8 kcal/mol keeps them in the stem: hsa-mir-451a (MI0001729, processed by
# Ago2, see Hsa-Mir-451 in doc/hg38/mirGeneDb.txt), hsa-mir-1237, -3620, -4302,
# -4326, -548bb, -5703 and -378j (MI0021273, a suboptimal hairpin, the others MFE).
# hsa-mir-6134 (MI0021279), hsa-mir-6786 (MI0022631) and hsa-mir-6843 (MI0022689)
# have no single hairpin within 8 kcal/mol. hsa-mir-6786 and hsa-mir-6843 keep their
# MFE structure; their precursors seem too long on the 5p side, and the region with
# the matures folds into a hairpin. For hsa-mir-6134, all structures within 8
# kcal/mol have a separate hairpin at nt 1-25 and the hairpin loop right next to the
# mature; the suboptimal structure 0.8 kcal/mol above the MFE, in which the mature
# is more helical, was chosen by hand from RNAsubopt -d2 -e 8 -s and is set in
# MANUAL_STRUCTURES in mirBaseToBed.py (energy from RNAeval -d2, same miniforge).
# Centroid (RNAfold -p) and MEA (--MEA) structures were also tried and fixed hardly
# any.
