Metadata-Version: 2.4
Name: EvoAnn
Version: 1.1.0
Summary: A high-performance, GFF-based variant annotation and sequence processing suite tailored for evolutionary genomics.
License-Expression: MIT
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: biopython>=1.87
Requires-Dist: cyvcf2>=0.32.1
Dynamic: license-file

# EvoAnn

**English** · [简体中文](README.zh-CN.md)

EvoAnn (Evolutionary Annotation Toolkit) annotates SNPs against gene models and extracts reference coding sequences, individual consensus sequences and phased haplotypes. Use `all-ann` for a genome-wide report or run a standalone annotator for CDS, introns, UTRs, transcript flanks or intergenic regions.

## Installation

To install EvoAnn 1.1.0 directly from GitHub in a Linux Python environment, run

```bash
python -m pip install "https://github.com/zhaozihao796/EvoAnn/archive/refs/tags/v1.1.0.tar.gz"
evoann --help
```

To run the bundled examples, open a Linux Bash shell in the extracted release directory containing `pyproject.toml`, `src/` and `test_data/`. On Windows, use Ubuntu under WSL2. The following commands create the study environment and install EvoAnn from this directory.

```bash
conda env create -f environment.yaml
conda activate EvoAnn
python -m pip install .
evoann --help
```

EvoAnn 1.1.0 requires Python 3.10 or later, Biopython 1.87 or later and cyvcf2 0.32.1 or later. The Conda environment specifies Python 3.11, NumPy 2.4.4, Biopython 1.87, cyvcf2 0.32.1 and HTSlib 1.23. HTSlib supplies `bgzip` and `tabix`. For an editable installation, use `python -m pip install -e .` from the source directory. [Package metadata](pyproject.toml) · [Conda environment](environment.yaml)

The example timings below were measured during development on x86-64 Ubuntu 24.04.3 LTS under WSL2 with Python 3.12.3, NumPy 1.26.4, Biopython 1.83, cyvcf2 0.30.28 and HTSlib 1.19. For the full example, allow **512 MiB of free RAM and 256 MiB of additional disk space** beyond the checkout and environment. All ten commands together took about **3 min 17 s** on one CPU. [Per-command measurements](#expected-results-and-resources) are given below.

## Bundled test data

The three files in `test_data/` cover linkage group 1 of the haplotype A reference of *Ostryopsis davidiana* (虎榛子). Coordinates are 1-based.

| File | Contents |
| --- | --- |
| `test_ref.fa` | One sequence, `OdLG1A`, spanning bases 1–39,534,700. |
| `test_anno.gff3` | 3,910 genes and 4,701 mRNAs on `OdLG1A`, with 27,927 exon and 25,895 CDS features, plus 5′ and 3′ UTR features. |
| `test_pop.vcf.gz` | Sorted, BGZF-compressed VCF 4.2. It contains 587,300 biallelic SNPs at distinct positions from 5,655 to 39,521,133. |

The VCF contains 18 diploid individuals (`Sample1` through `Sample18`). All 10,571,400 `GT` calls are complete and phased. The observed genotypes are `0|0`, `0|1`, `1|0` and `1|1`.

## Run the examples

Run this setup once, then use the same shell for the examples. The VCF is already BGZF-compressed. The working copies keep its index (`test_pop.vcf.gz.tbi`) and the automatically generated `test_anno_fixed.gff3` together under `demo_out/input/`.

```bash
out=demo_out
mkdir -p "$out/input"
cp test_data/test_anno.gff3 test_data/test_pop.vcf.gz "$out/input/"
ref=test_data/test_ref.fa
gff="$out/input/test_anno.gff3"
vcf="$out/input/test_pop.vcf.gz"
gene=Od1AG000004
tabix -f -p vcf "$vcf"
```

### Whole-dataset annotation

```bash
evoann all-ann \
  -v "$vcf" -g "$gff" -f "$ref" \
  --flank 2000 -o "$out/all"
```

Open `demo_out/all/fast_annotation_summary.html` in a browser. EvoAnn embeds the scripts from `src/report_assets/` in the HTML for offline viewing. Keep the annotation tables beside the HTML file to use its download links.

### GFF3 and reference CDS

```bash
evoann correct-gff -g "$gff" -o "$out/checked.gff3"

evoann cds-extract \
  -g "$gff" -f "$ref" \
  --all_transcripts -o "$out/reference_cds"
```

Open `demo_out/checked_repair_report.html` to see how EvoAnn produced `checked.gff3`. Each table shows up to 20 examples, with input line numbers for existing features, transcript IDs and genomic intervals. The **Download full log** button saves every entry as a gzip-compressed TSV. It is embedded in the HTML and works offline. To choose a different report path, add `--report <HTML>` to `correct-gff`.

The report counts exons added, CDS phases corrected, child IDs standardized and shared Parent fields split in the exported GFF3. A separate count lists transcripts whose CDS phases were preserved for manual review. One feature can have several edits. An inferred exon has an empty input line in the log.

Here `cds-extract` writes the full spliced CDS for every coding transcript. Run it before the standalone `cds-ann` example, which takes the resulting FASTA as input.

### Population sequences

```bash
evoann consensus-extract \
  -v "$vcf" -g "$gff" -f "$ref" \
  --gene "$gene" -o "$out/consensus"

evoann phased-extract \
  -v "$vcf" -g "$gff" -f "$ref" \
  --gene "$gene" --cds-only --all-transcripts -o "$out/phased"
```

Both commands select gene `Od1AG000004` (`OdLG1A:76800-82742`). The first extracts its complete genomic interval for each individual. The second extracts the spliced CDS for each of its two transcripts, giving 18 individuals × 2 haplotypes × 2 transcripts.

### Standalone SNP annotation

```bash
evoann cds-ann \
  -v "$vcf" -g "$gff" -c "$out/reference_cds_all.fa" \
  -o "$out/cds.tsv"

evoann intron-ann -v "$vcf" -g "$gff" -o "$out/intron"

evoann utr-ann -v "$vcf" -g "$gff" -o "$out/utr"

evoann flank-ann -v "$vcf" -g "$gff" --flank 2000 -o "$out/flank"

evoann intergenic-ann -v "$vcf" -g "$gff" -o "$out/intergenic.tsv"
```

## Expected results and resources

Paths in the table are relative to `demo_out/`. GNU `time` measured wall time and peak resident memory (RSS) for one sequential run on a single logical CPU of an AMD Ryzen 9 5900HX, using the Linux filesystem. Each measurement includes command startup and output writing. The timings exclude installation, input staging and VCF indexing. The updated `correct-gff` measurement includes the HTML report, using Python 3.13.5, NumPy 2.5.5, Biopython 1.88 and cyvcf2 0.35.0 on the same CPU.

| Command | Output | Check on the bundled data | Wall time (s) | Peak RSS (MiB) |
| --- | --- | --- | ---: | ---: |
| `all-ann` | `all/fast_annotation_summary.html` and seven `all/*.txt` tables | 587,300 input records in the report | 4.69 | 238 |
| `correct-gff` | `checked.gff3`, `checked_repair_report.html` | 73,683 output feature rows, 65,072 child IDs standardized, 0 exons added, 0 CDS phases corrected | 0.89 | 118 |
| `cds-extract` | `reference_cds_all.fa` | 4,701 CDS records, 6,352,512 bp in total | 0.70 | 242 |
| `consensus-extract` | `consensus/Od1AG000004_consensus.fasta` | 18 sequences of 5,943 bp | 0.61 | 234 |
| `phased-extract` | `phased/Od1AG000004_cds_phased.fasta` | 72 sequences. 36 of 1,569 bp and 36 of 1,185 bp | 0.59 | 235 |
| `cds-ann` | `cds.tsv` | 54,870 data rows | 81.10 | 181 |
| `intron-ann` | `intron.fa` | 221,278 data rows | 58.68 | 190 |
| `utr-ann` | `utr.fa` | 44,562 data rows | 1.86 | 171 |
| `flank-ann` | `flank.fa` | 293,875 data rows | 46.52 | 197 |
| `intergenic-ann` | `intergenic.tsv` | 304,485 data rows | 1.75 | 269 |

The working copies, index and outputs used about 171 MiB of disk in total. Treat the counts as installation checks and the resource figures as estimates. On other datasets, `all-ann` holds the reference and gene models in memory while streaming VCF records. The standalone annotators retain variants and hits. Population extraction also depends on sample count, target lengths and the number of transcripts requested.

To reproduce the counts, count table rows after the header, FASTA records by their `>` headers, and GFF3 features by their nine fields.

```bash
for table in "$out"/all/*.txt "$out/cds.tsv" "$out/intron.fa" "$out/utr.fa" \
             "$out/flank.fa" "$out/intergenic.tsv"
do
  awk 'END {print FILENAME, NR - 1}' "$table"
done
grep -c '^>' "$out/reference_cds_all.fa" \
  "$out/consensus/${gene}_consensus.fasta" "$out/phased/${gene}_cds_phased.fasta"
awk -F '\t' 'NF == 9 && $1 !~ /^#/ {n++} END {print FILENAME, n+0}' "$out/checked.gff3"
```

### Annotation tables

Each SNP output is tab-separated and begins with `#CHROM`, `POS`, `REF`, `ALT`, `VARIANT_TYPE`, in that order. `POS` is the 1-based reference position and each row gives one ALT allele and its consequence. The table below lists the remaining columns in file order. The standalone `intron-ann`, `utr-ann` and `flank-ann` writers append `.fa` to the output prefix and write **tab-separated text**.

| File in `demo_out/all/` | Standalone example with the same columns | Demo data rows | Columns after `VARIANT_TYPE` |
| --- | --- | ---: | --- |
| `nonsynonymous_annotation.txt` | `cds.tsv` | 54,870 | `GENE\|MRNA`, `AA_CHANGE` |
| `synonymous_annotation.txt` | — | 53,155 | `GENE\|MRNA` |
| `unresolved_cds_annotation.txt` | — | 0 | `GENE\|MRNA`, `REASON` |
| `intron_annotation.txt` | `intron.fa` | 221,278 | `GENE`, `MRNA`, `INTRON_ID` |
| `utr_annotation.txt` | `utr.fa` | 44,562 | `GENE`, `MRNA` |
| `flank_annotation.txt` | `flank.fa` | 293,875 | `GENE`, `MRNA`, `DISTANCE` |
| `intergenic_annotation.txt` | `intergenic.tsv` | 304,485 | `LEFT_GENE`, `DIST_LEFT`, `RIGHT_GENE`, `DIST_RIGHT` |

`GENE` and `MRNA` are GFF3 identifiers. `GENE|MRNA` stores both in one column. `AA_CHANGE` gives the reference residue, 1-based protein position and alternate residue using one-letter codes (`*` denotes a stop codon). For example, `R26Q` at `OdLG1A:5774` indicates arginine changing to glutamine at residue 26. `REASON` can be `undetermined_reading_frame` or `incomplete_codon`. `INTRON_ID` identifies an interval within a transcript. Intron rows include `splice_donor_variant` and `splice_acceptor_variant` at the strand-specific boundaries.

`DISTANCE` is the distance in bases to the relevant transcript boundary. `DIST_LEFT` and `DIST_RIGHT` measure the distance to the nearest gene boundary on the corresponding genomic side. A dot marks an absent neighbour or distance. At `OdLG1A:33501`, for example, the `T>C` SNP is intergenic and lies 100 bp downstream of `Od1AG000001`. Overlapping regions, transcripts and multiple ALT alleles can each generate additional rows, so regional counts and percentages can sum to more than the input total or 100%.

## Input requirements

**Coordinates and identifiers.** Use the same assembly for the FASTA, GFF3 and VCF. The FASTA identifier (the first word after `>`), GFF3 column 1 and VCF `CHROM` must match exactly, including case and any `chr` prefix. GFF3 start and end are inclusive. VCF `REF` should match the FASTA at `POS` on the genomic forward strand.

**Reference and annotation models.** Supply plain-text FASTA and tab-delimited GFF3. EvoAnn reads both directly without a FASTA or GFF3 index. Use unique `ID` values on `gene` and `mRNA` rows, `Parent=<gene ID>` on each `mRNA`, and `Parent=<mRNA ID>` on its `exon`, `CDS` and UTR features. Put the gene before its mRNAs and each mRNA before its children. The parser recognizes the feature type `mRNA`. Give coding features a strand and a CDS phase (`0`, `1` or `2`, column 8) for protein interpretation. Exon and CDS intervals supply the structure for intron and UTR annotation.

`correct-gff` writes nine GFF3 columns (`seqid`, `source`, `type`, `start`, `end`, `score`, `strand`, `phase`, `attributes`). It exports the gene–mRNA hierarchy and its linked children, supplements missing exons, standardizes child IDs and can expand children shared by several transcripts into per-transcript rows. Use single-parent child rows for population CDS extraction. `all-ann`, `intron-ann` and `utr-ann` run repair internally and write a `*_fixed.gff3` beside a `.gff3` input. Use a writable working copy named `*.gff3` for these commands.

Start with the original annotation when revisiting older repairs. The corrector preserves the **first CDS phase in transcript order**, including valid values of 1 or 2 on either strand, and propagates it through an unambiguous CDS chain. An earlier repair that replaced that value with zero lost the original frame information. `cds-extract` exports the full spliced nucleotides including partial codons. Pass that sequence to `cds-ann`. `all-ann` and `cds-ann` apply the first phase once for translation. Amino acid 1 refers to the first complete codon of the model and can differ from the full protein's numbering at a partial 5′ end.

**VCF for SNP annotation.** `all-ann` and the five standalone annotators accept plain VCF or gzipped VCF without an index. They use the site alleles independently of sample genotypes and ploidy. A one-base REF with several ALT alleles is evaluated separately for each eligible one-base ALT. Indels and spanning-deletion `*` alleles are skipped. Apply any desired `FILTER`, quality or population-frequency thresholds before annotation.

**VCF for individual sequences.** `consensus-extract` and `phased-extract` query intervals in a coordinate-sorted BGZF VCF with a matching `.tbi` or `.csi` beside it. For a sorted plain VCF of your own, `bgzip -c cohort.vcf > cohort.vcf.gz` followed by `tabix -p vcf cohort.vcf.gz` creates this pair.

The extractors read exactly two allele indices per sample and support diploid `FORMAT/GT` calls only. Supply explicit nucleotide alleles at non-overlapping records because extraction advances past the REF bases it has consumed. Keep multi-allelic sites in one record so a genotype such as `1|2` selects the first and second ALT alleles.

- `consensus-extract` accepts phased or unphased diploid calls. It writes the called base for homozygotes and an IUPAC ambiguity code for heterozygous SNPs (e.g. `A/G` gives `R`). A missing allele gives `N` across that site's output width.
- `phased-extract` needs phased heterozygotes (`0|1`, `1|0`, etc.) for interpretable haplotypes. It copies the first and second genotype alleles into `_h1` and `_h2` and relies on the phasing supplied in the VCF. A missing allele gives `N` on the affected haplotype.
- For explicit sequence indels, the extractors pad shorter alleles with `-` to the longest REF/ALT length at that record. For a heterozygous indel, consensus uses the second called allele if it is alternate, otherwise the first. Phased output retains both calls.

## Command syntax and sequence formats

Angle brackets mark values to supply. Square brackets mark optional arguments. `evoann <subcommand> --help` displays the options for that command. The menu labels `fast-ann` and `stream-ann` refer to the registered commands `all-ann` and `flank-ann`, respectively.

```text
evoann all-ann -v <VCF> -g <GFF3> -f <FASTA> -o <DIR> [--flank <BP>]
evoann correct-gff -g <GFF3> [-o <GFF3_OUT>] [--report <HTML>]
evoann cds-extract -g <GFF3> -f <FASTA> [--all_transcripts] [-o <PREFIX>]
evoann consensus-extract -v <VCF> -g <GFF3> -f <FASTA> [--gene <ID> | --gene-file <LIST>] \
  [--cds-only [--all-transcripts]] [-o <DIR>]
evoann phased-extract -v <VCF> -g <GFF3> -f <FASTA> [--gene <ID> | --gene-file <LIST>] \
  [--cds-only [--all-transcripts]] [-o <DIR>]
evoann cds-ann -v <VCF> -g <GFF3> -c <CDS_FASTA> [-o <TSV>]
evoann intron-ann -v <VCF> -g <GFF3> [-o <PREFIX>]
evoann utr-ann -v <VCF> -g <GFF3> [-o <PREFIX>]
evoann flank-ann -v <VCF> -g <GFF3> [--flank <BP>] [-o <PREFIX>]
evoann intergenic-ann -v <VCF> -g <GFF3> [-o <TSV>]
```

- `--flank <BP>` is the strand-aware upstream/downstream distance from the transcript boundaries (default 2,000 bp).
- `cds-extract` takes an output **prefix**. By default it selects the transcript with the longest total CDS per gene and writes `<prefix>.fa`. Its all-transcript flag is `--all_transcripts` (legacy alias `-all`), which writes `<prefix>_all.fa`. Headers have the form `>GENE|MRNA`. `cds-ann` uses these IDs to match models and reports non-synonymous calls.
- The two population extractors use the **hyphenated** `--all-transcripts` with `--cds-only`. `--gene` takes the exact GFF3 gene `ID`. `--gene-file` takes one such ID per line. Omitting both selects all genes. The default gene interval includes introns and follows genomic forward orientation. `--cds-only` splices CDS segments in transcript orientation, reverse-complementing the negative strand, and defaults to the longest total CDS per gene.
- Population output is one FASTA per gene, named `<gene>_consensus.fasta` or `<gene>_phased.fasta`. CDS mode inserts `_cds` after the gene ID. Consensus headers are `>GENE_SAMPLE` or `>GENE_SAMPLE_TRANSCRIPT` in CDS mode. Phased headers also carry `_h1` or `_h2`.
- `utr-ann` processes the eligible transcripts with exon and CDS models. Its current parser also accepts `--all_transcripts` (`-all`), which produces the same transcript selection as the default.

EvoAnn is distributed under the [MIT license](LICENSE).
