Menu ▾ ▴

GenBankVault_Scientific_Methods

Bryan P White

← Back to GenBankVault Overview

GenBankVault Scientific Methods & Algorithms

Package: ncbi-genome-vault v1.1.0
License: GPL-3.0-or-later
Reference Validation: 12/12 automated integration checks passing (tests/integration_tests.rs)

This document specifies the mathematical transformations, biological coordinate conventions, sequence statistics, genetic code mappings, and upstream database invariants implemented in GenBankVault.


1. Five-Gate Semantic Routing & Accession Classification

GenBankVault enforces modality separation across five NcbiDataType gates to prevent whole-genome assemblies, linear megabase chromosomes, short transcripts/CDSs, circular organellar/prokaryotic replicons, and amino-acid entries from mixing in incompatible coordinate frames.

Accession Prefix Inference (parsers::infer_gate_for_accession)

Case-normalized accession prefixes resolve deterministically:

  • Protein: NP_*, XP_*, WP_*, YP_*, P0*, Q9* -> NcbiDataType::Protein
  • Linear Genome Assembly: GCF_*, GCA_* -> NcbiDataType::LinearGenome
  • Circular Replicon / Organelle: NC_012920*, J01415*, NC_000909*, NC_013967*, NC_001732*, NC_001733*, NZ_CP*, or INSDC CP[0-9]* -> NcbiDataType::CircularGenome
  • Linear Chromosome: NC_0000*, NC_0723*, CM0006* -> NcbiDataType::LinearChromosome
  • Nucleotide (default mRNA / locus): all remaining NM_*, NR_*, XM_*, or gene-scoped accessions -> NcbiDataType::Nucleotide

Entrez Boolean Operator Grouping (query_router)

To avoid ambiguous operator precedence in NCBI Entrez ESearch queries mixing AND and OR, nucleotide queries explicitly parenthesize both disjunction arms:

term = "((" + q + ") AND biomol_mrna[PROP]) OR ((" + q + ") AND linear[Topology] NOT \"complete genome\"[Title])"

2. GenBank Flatfile & GFF3 Feature Parsing

Multi-Line Header & Feature Location Assembly (parsers::parse_genbank_flatfile)

  1. Multi-Line DEFINITION: Indented continuation lines following DEFINITION (raw_line.starts_with(' ')) are concatenated with single spaces until the next top-level column-0 keyword (ACCESSION, VERSION, DBLINK, KEYWORDS, SOURCE, etc.).
  2. Taxon ID Preservation: A unified finalize_genbank_feature handler inspects every source feature's /db_xref="taxon:<id>" qualifier at feature transitions, FEATURES -> ORIGIN, and EOF (metadata-only records), assigning VaultRecord::tax_id while excluding source rows from VaultRecord::annotations.
  3. Multi-Exon join(...) Intervals (parse_genbank_location_intervals):
    Comma-delimited spans inside join(...), order(...), and complement(join(...)) (including multi-line wrapped locations) are parsed into ordered 1-based (start, end) exon intervals in AnnotationFeature::exons. Reverse-strand descending listings such as join(complement(b1..b2), complement(a1..a2)) with b1 > a2 are sorted into ascending genomic coordinate order for consistent exon rendering and export.

3. Circular Origin-Wrap & Reverse-Strand Coordinate Remapping

Let a reference record of length N >= 1 contain a feature interval [fs, fe] (or spliced exons {[e_i_s, e_i_e]}), and let an exported slice cover 1-based endpoints [start, end]:

Forward Slice Mapping (exporter::remap_feature_for_slice)

  1. Linear Window (start <= end, or non-circular topology):
    Extracted sequence length is L = end - start + 1. An interval [ps, pe] overlapping [start, end] clips to [cs, ce] = [max(ps, start), min(pe, end)] and maps to 1-based slice coordinates:

text a = cs - start + 1 b = ce - start + 1 (1 <= a <= b <= L)

  1. Circular Origin-Wrapping Window (topology_circular && start > end):
    The slice concatenates the pre-origin tail [start..=N] of length L_pre = N - start + 1 with the post-origin head [1..=end] of length end, giving total slice length L = L_pre + end:

text Pre-origin overlap [start..=N] : a = cs - start + 1, b = ce - start + 1 Post-origin overlap [1..=end] : a = L_pre + cs, b = L_pre + ce

Features that themselves span the origin (fs > fe) are decomposed into [fs..=N] and [1..=fe] before clipping. Contiguous mapped segments separated by <= 1 bp across the origin seam (a_{k+1} <= b_k + 1) merge cleanly into a single continuous slice interval.

Reverse-Complement Reflection (Strand::Reverse)

When exporting nucleotide records on Strand::Reverse, the output sequence is replaced by its base-wise reverse complement S'[i] = comp(S[L - i + 1]). Every mapped slice interval [a, b] transforms symmetrically under reflection across L:

a_rev = L - b + 1
b_rev = L - a + 1      (with interval ordering re-sorted ascending)

and the feature's relative strand flips (Forward <-> Reverse, leaving Unstranded unchanged).

GFF3 ##FASTA Seqid Consistency

For ExportFormat::Gff3, seqid is resolved once (chromosome.unwrap_or(accession)) and applied identically to ##sequence-region <seqid> <start> <end>, column 1 of every GFF3 annotation line, and the embedded ##FASTA sequence identifier (><seqid> ...).


4. Genetic Code Translation Tables (parsers::translate_dna_frame_with_table)

For reading frame f in {0, 1, 2} (representing +1, +2, +3) over normalized DNA (U -> T), codons C_k = b[f + 3k .. f + 3k + 3] are translated using either NCBI Table 1 or NCBI Table 2:

Codon Standard (GeneticCode::Standard, Table 1) Vertebrate Mitochondrial (GeneticCode::VertebrateMitochondrial, Table 2)
ATA I (Ile) M (Met / Start)
TGA * (Stop) W (Trp)
AGA, AGG R (Arg) * (Stop)
Remaining 60 codons Identical across Table 1 and Table 2 Identical across Table 1 and Table 2

GenBankVault automatically selects GeneticCode::VertebrateMitochondrial when opening mitochondrial accessions (NC_012920*, transl_table=2, MT locus features, or "mitochondri" titles) while allowing interactive switching in the viewer toolbar.


5. Windowed Sequence & Hydropathy Metrics

GC Content & GC-Skew

Over any sequence window containing counts (N_A, N_C, N_G, N_T, N_U):

N_AT = N_A + N_T + N_U
N_GC = N_G + N_C

GC%     = 100 * N_GC / max(N_AT + N_GC, 1)
GC_skew = (N_G - N_C) / (N_G + N_C)    if (N_G + N_C) > 0, else 0.0

In draw_nucleotide_track, GC% bins are computed exclusively over the active zoomed slice [win_s..win_e] (offset by VaultRecord::sequence_offset) and plotted against explicit 0%, 50%, and 100% horizontal gridlines.

In exporter::build_multifasta_report, records with empty locally cached sequence (rec.sequence.is_empty(), e.g., metadata-only assembly maps) strictly emit ambig_count = 0 and gc_percent = None rather than synthesizing placeholder 'N' characters into quality-assurance counts.

Kyte-Doolittle Hydropathy & +1.6 Transmembrane Threshold

For a protein sequence of length M and sliding window size w (default w = 9 centered around position i, half-width h = (w - 1) / 2):

KD_avg(i) = (1 / |W_i|) * SUM_{j = max(0, i-h) .. min(M-1, i+h)} KD_scale(aa_j)

where KD_scale(aa) follows the Kyte & Doolittle (1982) hydropathy index (I=+4.5, V=+4.2, L=+3.8, F=+2.8, C=+2.5, M=+1.9, A=+1.8, G=-0.4, ..., R=-4.5). Following standard Kyte-Doolittle transmembrane segment criteria for 9–19 aa windows, the protein viewer overlays a horizontal +1.6 TM threshold line above 0.0 alongside -4.5 and +4.5 reference ticks.


6. Chromosome Fetch Window Clamping & Centromere Reporting

Entrez Window Clamping (ncbi_client::clamp_chromosome_fetch_window)

Given actual chromosome sequence length N_chr = slen queried from Entrez esummary:

  • If requested = Some((s, e)): clamp to [max(1, s), min(e, N_chr)] when s <= N_chr, or else shift a bounded span [N_chr - min(e - s, 100_000), N_chr] safely inside [1, N_chr].
  • If requested = None:
  • N_chr <= 100_000: return (1, N_chr).
  • N_chr >= 11_830_000: preserve classic Human Chr 1 MTHFR window (11_780_000, 11_830_000).
  • 100_000 < N_chr < 11_830_000: center a 50 kb window [N_chr/2 - 25_000, N_chr/2 + 25_000].

Centromere Provenance

Live NCBI Datasets v2 sequence_reports downloads populate ChromosomeSummary::centromere_bp = None whenever upstream metadata omits centromeric coordinates, rather than fabricating length_bp / 2. Curated reference assemblies (build_verified_seed_catalog) retain published GRCh38.p14 and SGD R64 centromere coordinates.


7. Cryptographic Provenance & Rate Limiting

  • Record Digest: SHA-256 computed over <accession>|<len>|<ann_len>|<sequence> (parsers::compute_record_sha256).
  • Entrez Token-Bucket Rate Limiting: Enforces minimum inter-request intervals of 340 ms (<= 3 req/s unauthenticated) or 105 ms (<= 10 req/s with NCBI_API_KEY).

References

  1. Kyte, J., & Doolittle, R. F. (1982). A simple method for displaying the hydropathic character of a protein. Journal of Molecular Biology, 157(1), 105–132.
  2. Andrews, R. M., et al. (1999). Reanalysis and revision of the Cambridge reference sequence for human mitochondrial DNA (NC_012920.1). Nature Genetics, 23(2), 147.
  3. Schneider, V. A., et al. (2017). Evaluation of GRCh38 and de novo haploid genome assemblies demonstrates the enduring quality of the reference assembly. Genome Research, 27(5), 849–864.
  4. NCBI Entrez E-utilities & NCBI Datasets v2 Documentation (eutils.ncbi.nlm.nih.gov, api.ncbi.nlm.nih.gov/datasets/v2).

Related

Wiki: GenBankVault