# Reviewing a gene prediction (Tiberius)

:::caution JBrowse v5 beta

The tutorials target the JBrowse v5 beta, and the v4.3.0 release
on the [download page](https://jbrowse.org/jb2/download/) lacks some of what they show. To install the
beta of JBrowse Web, run `npm install -g @jbrowse/cli@next`, then
`jbrowse create jbrowse2 --branch v5.0.0-beta.21`. Desktop beta builds for Linux and
macOS are on the [releases page](https://github.com/GMOD/jbrowse-components/releases);
the Windows build waits on code signing.

:::

A gene finder run on a genome returns thousands of gene models, and most of them
agree with the existing annotation. A person has to look at each model that
disagrees, such as two genes predicted as one, a gene with different exons, or a
gene where nothing was annotated. We compare the predictions of Tiberius, a
deep-learning gene finder, with GENCODE on human chr22, and turn the
disagreements into a review page that links each one back into JBrowse. We:

- load the predictions and GENCODE as two gene tracks over a model that merges
  two genes
- sort every model against GENCODE into classes with the review pipeline
- build the static review page, with a JBrowse capture and an **Open in
  JBrowse** link per model
- review the cards, and read the Disagreements track the pipeline adds under
  each prediction

The pipeline is
[cmdcolin/gene-review-portal](https://github.com/cmdcolin/gene-review-portal),
and its README documents every option.

## Prerequisites

- an existing annotation of the genome, to compare the predictions against
- to build a portal over your own genome: Node 23.6 or newer, pnpm, htslib
  (`bgzip`, `tabix`), `samtools`, and the JBrowse CLI

<!-- BEGIN GENERATED TUTORIAL_INSTALL samtools,htslib,node,jbrowse-cli -->

```bash
# Debian/Ubuntu
sudo apt install samtools tabix nodejs
# or conda, which has every tool above
conda install -c bioconda -c conda-forge samtools htslib nodejs
# any platform
npm install -g @jbrowse/cli@next
```

<!-- END GENERATED TUTORIAL_INSTALL samtools,htslib,node,jbrowse-cli -->

## The data

Tiberius predictions over GRCh38
([Gabriel et al. 2024](https://doi.org/10.1093/bioinformatics/btae685)), read
against GENCODE 47 and the hg38 reference.

Nothing to download: the track configs and commands below read these files by
URL.
[Building the review portal](#building-the-review-portal-with-make-portalmjs)
takes your own prediction, annotation and genome in their place.

<details>
<summary>The files</summary>

| What it is                          | File                                                                                                                                                                |
| ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Tiberius gene predictions           | [tiberius_grch38.gff.gz](https://jbrowse.org/genomes/GRCh38/tiberius_grch38.gff.gz)                                                                                 |
| GENCODE 47 comprehensive annotation | [gencode.v47.chr_patch_hapl_scaff.annotation.sorted.gff3.gz](https://jbrowse.org/genomes/GRCh38/gencode/gencode.v47.chr_patch_hapl_scaff.annotation.sorted.gff3.gz) |
| Hg38 reference sequence             | [hg38.prefix.fa.gz](https://jbrowse.org/genomes/GRCh38/fasta/hg38.prefix.fa.gz)                                                                                     |

</details>

## A Tiberius model that merges IL17REL and TTLL8

We'll load the GRCh38 sequence the predictions were made on, then the two
annotations. Each annotation is a GFF3 that is bgzipped, sorted and
tabix-indexed with its `.tbi` beside it
([prep](https://jbrowse.org/jb2/docs/quickstart_web#gff3-and-gtf)), and uses the assembly's refNames.

```json
{
  "name": "hg38",
  "uri": "https://jbrowse.org/genomes/GRCh38/fasta/hg38.prefix.fa.gz",
  "refNameAliases": {
    "uri": "https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/hg38_aliases.txt"
  },
  "cytobands": "https://jbrowse.org/genomes/GRCh38/cytoBand.txt"
}
```

CLI:

```bash
jbrowse add-assembly https://jbrowse.org/genomes/GRCh38/fasta/hg38.prefix.fa.gz \
  --name hg38 \
  --refNameAliases https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/hg38_aliases.txt \
  --config '{"cytobands":"https://jbrowse.org/genomes/GRCh38/cytoBand.txt"}'
```

```json
{
  "trackId": "tiberius_grch38",
  "name": "Tiberius gene predictions",
  "uri": "https://jbrowse.org/genomes/GRCh38/tiberius_grch38.gff.gz",
  "assemblyNames": ["hg38"]
}
```

CLI:

```bash
jbrowse add-track https://jbrowse.org/genomes/GRCh38/tiberius_grch38.gff.gz \
  --trackId tiberius_grch38 \
  --name "Tiberius gene predictions" \
  --assemblyNames hg38
```

Opens on config <https://jbrowse.org/ucsc/hg38/config.json> at `chr22:49,987,402-50,067,759`

GENCODE's GFF3 also has region features that would draw as a bar above the
genes, so the `geneLike` filter keeps the genes and their transcripts:

```json
{
  "trackId": "gencode_47",
  "name": "Gencode v47",
  "uri": "https://jbrowse.org/genomes/GRCh38/gencode/gencode.v47.chr_patch_hapl_scaff.annotation.sorted.gff3.gz",
  "assemblyNames": ["hg38"],
  "displayDefaults": { "filter": ["geneLike"] }
}
```

CLI:

```bash
jbrowse add-track https://jbrowse.org/genomes/GRCh38/gencode/gencode.v47.chr_patch_hapl_scaff.annotation.sorted.gff3.gz \
  --trackId gencode_47 \
  --name "Gencode v47" \
  --assemblyNames hg38 \
  --displayDefaults '{"filter":["geneLike"]}'
```

Opens on config <https://jbrowse.org/ucsc/hg38/config.json> at `chr22:49,987,402-50,067,759`

Open the two annotations together at `chr22:49,987,402-50,067,759`. Tiberius
draws one model, `g14001.t1`, across most of the window, where GENCODE has two
genes with a gap between them. GENCODE's gene features have `gene_name` and no
`Name`, so the track labels them by accession, `ENSG00000188263` for _IL17REL_
and `ENSG00000138892` for _TTLL8_.

<Figure src="/img/gene_prediction_merge.png" caption="One Tiberius model spans IL17REL and TTLL8, which GENCODE annotates as two genes." />

Session spec, on config <https://jbrowse.org/code/jb2/main/test_data/config_demo.json>:

```json
{
  "views": [
    {
      "type": "LinearGenomeView",
      "assembly": "hg38",
      "loc": "chr22:49,987,402-50,067,759",
      "tracks": [
        {
          "trackId": "tiberius_grch38",
          "height": 90
        },
        {
          "trackId": "gencode_47",
          "filter": [
            "geneLike"
          ],
          "height": 150
        }
      ]
    }
  ]
}
```

## Sorting Tiberius models into five classes against GENCODE

The merge above is one kind of disagreement. The portal compares each Tiberius
model on chr22 with GENCODE and puts it in one of five classes: Agrees and four
classes of disagreement. Only the four disagreement classes get a card.

| Class              | What it means                                                     | On chr22                                                   | What an annotator does   |
| ------------------ | ----------------------------------------------------------------- | ---------------------------------------------------------- | ------------------------ |
| Agrees             | shares splice junctions with a reference gene                     | 424<!--m:tiberius-chr22-classes.agrees.models-->           | nothing                  |
| Merged model       | one prediction covers two separate reference genes                | 1<!--m:tiberius-chr22-classes.merged-model.models-->       | split into two models    |
| Structure conflict | covers one gene but shares none of its splice junctions           | 3<!--m:tiberius-chr22-classes.structure-conflict.models--> | check the exon structure |
| Novel locus        | predicted where the reference annotates nothing                   | 12<!--m:tiberius-chr22-classes.novel-locus.models-->       | assess, then create      |
| Novel coding       | predicted coding where the reference has only non-coding features | 119<!--m:tiberius-chr22-classes.novel-coding.models-->     | assess coding potential  |

The portal applies these rules, and the _PI4KA_ control exercises them:

- **A shared junction** is an intron of one of the gene's transcripts.
- **Exons are compared** with genes on the same strand.
- **A merge** counts only when the genes it joins do not overlap each other.
  _PI4KA_ is on the minus strand with _SERPIND1_ inside one of its introns on
  the plus strand; Tiberius predicts _PI4KA_ correctly, and the portal leaves it
  off the list.
- **GENCODE readthrough genes** (one transcript spanning two neighbours) such as
  `CHKB-CPT1B` overlap the genes they join, so the portal skips them.

## Building the review portal with make-portal.mjs

Clone the pipeline and install it:

```bash
git clone https://github.com/cmdcolin/gene-review-portal
cd gene-review-portal
pnpm install
```

`make-portal.mjs` reads the two annotations, classifies every model, captures a
JBrowse view at each candidate and writes the page. Each input is a local path
or a URL; for the chr22 example, pass the three URLs from the data table:

```bash
# --prediction: the gene finder's GFF3; --reference: the annotation to compare
#   it with; --fasta: the genome both annotate
# --assembly: the name the page's JBrowse config gives that genome
# --region: scan one chromosome, fetching the annotations with tabix
# --max: candidates kept per class
# --with-app: bundle JBrowse, so the output needs no network
# add --aliases <file> when the annotations and the FASTA name chromosomes
#   differently (chr22 against 22)
node bin/make-portal.mjs \
  --prediction predictions.gff3.gz \
  --reference reference.gff3.gz \
  --fasta genome.fa.gz \
  --assembly hg38 --region chr22 --max 3 \
  --with-app --out ./portal
```

The output directory holds the page, a JBrowse config, one PNG per candidate
and, with `--with-app`, a copy of JBrowse. Copy it to any web server to publish.

`--rnaseq reads.bam` adds an alignment track under every model, in the captures
and in the links; repeat it for more BAMs, and label each with `--rnaseq-name`.
Reads across the exons of a novel locus support it as a gene.

The [example portal](https://jbrowse.org/demos/tiberius_review/) is this build
run against the hg38 hub's GENCODE 49, with `--rnaseq` on Human Brain Reference
and Universal Human Reference BAMs from the
[Griffith lab's RNA-seq course data](https://genomedata.org/rnaseq-tutorial/results/alignments/hisat/).

## Using the review page: cards, filters and verdicts

Open the [example portal](https://jbrowse.org/demos/tiberius_review/), or
`npx serve ./portal` for your own build. It has one card per model:

- **Card** shows the class, the reference genes, the locus and a capture of the
  two annotations
- **Filter chips** narrow the list to one class
- **Verdict buttons** record what you decide
- **Open in JBrowse** opens the same view live

The page keeps verdicts in your browser. **Export** writes them out as TSV, and
**Import** reads that TSV back on another browser. Building with
`--apollo <url>` adds a second link to every card that opens the same window in
[Apollo](https://github.com/GMOD/Apollo3), the annotation editor, and an
`apollo_url` column to the exported TSV.

## The Disagreements track: junctions that differ from GENCODE

Every capture and live link has a **Disagreements** track under the prediction,
with one box per junction that differs from the reference, labelled with what
moved:

```text
g13605.t1:donor-1048
```

`g13605.t1` covers _CCDC116_ with two exons. Its acceptor matches GENCODE, and
its donor is 1,048 bp from any _CCDC116_ donor.

The track reads `data/conflicts.bed`, plain BED6 that `bedtools` also reads. The
file also lists junction edits in models filed as Agrees (a model sharing four
of its five junctions, say), which get no card.

```text
chr22  21636314  21636431  g13605.t1:donor-1048     0  +
chr22  23977067  23977386  g13682.t1:donor+3025     0  -
chr22  50012765  50018574  g14001.t1:split          0  -
```

## See also

- **Tutorial:** [RNA-seq visualization](https://jbrowse.org/jb2/docs/tutorials/rnaseq)
- **Tutorial:** [Protein domains on gene models](https://jbrowse.org/jb2/docs/tutorials/protein_domains)
- **Config guide:** [Supported file types](https://jbrowse.org/jb2/docs/config_guides/file_types)
- **Docs:** [Capturing a JBrowse view from a script](https://jbrowse.org/jb2/docs/agents_capture)

## Citations

- Gabriel et al. (2024).
  [Tiberius: end-to-end deep learning with an HMM for gene prediction](https://doi.org/10.1093/bioinformatics/btae685)
- Frankish et al. (2023).
  [GENCODE: reference annotation for the human and mouse genomes in 2023](https://doi.org/10.1093/nar/gkac1071)

