GL1X · GenesisL1 explorer

GL1X docs · Science

BLAST engine

Every sequence the molecular indexer holds (every chain of every MolNFT record, on chain and on IPFS) is searchable with BLAST: on the BLAST page (/bio/blast), next to every sequence of a MolNFT card (Align here and BLAST), through POST /api/bio/blast, in the molecular search (a pasted sequence is a BLAST search) and through MCP (blast_search). The engine, internal/blast, is a Go implementation that follows NCBI BLAST+ 2.12.0 step by step and gives the same hits, scores, E-values, alignments and order.

This page explains what a search answers, how the engine runs one and with which parameters, how a raw score becomes a bit score and an E-value, how to read the results, and where the method reaches its limits. The numbers in the examples were computed by the engine.

What a BLAST search answers #

A BLAST search asks: which sequences of the database contain a region that aligns with a region of my query better than unrelated sequences would be expected to by chance? The answer is a list of local alignments, called high-scoring segment pairs (HSPs). Each has a raw score (the sum of the substitution scores of its aligned pairs minus its gap costs), a bit score (the same score on a scale that does not depend on the scoring system) and an E-value: the number of alignments at least this good that a search of this size is expected to produce by chance alone.

A small E-value is evidence that the two sequences are homologous, that is, descended from a common ancestor. A shared function or a shared fold is a further inference that the alignment supports but does not prove. BLAST is also a heuristic: it does not score every possible alignment, as the Smith–Waterman algorithm does, but starts from short word matches and extends only the promising ones, so a very short or very divergent similarity can be missed. Its statistics follow Karlin–Altschul theory with BLAST+'s own parameters and corrections, so an E-value from GL1X means what an E-value from BLAST+ means for the same database.

GL1X runs the five standard programs. Iterated profile searches (PSI-BLAST) are not among them; for chains whose sequences have diverged beyond what BLAST detects, structure search compares the 3D structures instead.

Programs and tasks #

ProgramQueryDatabaseTasks
blastpproteinproteinblastp, blastp-short
blastnnucleotidenucleotidemegablast, blastn, blastn-short
blastxnucleotide, translated in six framesproteinblastx
tblastnproteinnucleotide, translated in six framestblastn
tblastxnucleotide, translatednucleotide, translatedtblastx

Every option of the tasks is available with BLAST+'s defaults: E-value threshold, maximum target sequences and HSPs per subject, scoring matrices (BLOSUM45, 50, 62, 80, 90 and PAM30, 70, 250 with their admissible gap costs), match/mismatch scores and gap costs for nucleotides, word size and neighbourhood threshold, composition-based statistics (modes 0 to 3), SEG and DUST filtering, soft masking, ungapped search, query strand, and every NCBI genetic code for the translated programs. Several queries (FASTA) search together.

program auto (the default) picks blastp for protein queries and blastn for nucleotide queries. A query counts as nucleotides when at least 90% of its letters are A, C, G, T, U or N, and all queries of one search must be of the same kind. Without a task, the API runs the program's default task (blastp, or megablast for blastn). The BLAST page and a card's Align here choose the task from the query's length (the shortest query's, when there are several): blastp-short below 30 residues, blastn-short below 50 bases, else the default. The molecular search does the same but runs blastn rather than megablast for nucleotide queries of 50 bases or more.

Task defaults #

When a request leaves an option out, the task's BLAST+ 2.12 default applies:

TaskWordScoringGap costsThreshold TTwo-hit windowFilterComposition-based statisticsSum statistics
blastp3BLOSUM6211/11140nonemode 2off
blastp-short2PAM309/11615nonemode 2off
blastx3BLOSUM6211/11240SEGmode 2on
tblastn3BLOSUM6211/11340SEGmode 2on
tblastx3BLOSUM62ungapped1340SEGnone (ungapped)on
megablast28+1/−2linearexact wordsone hitDUST, soft maskingnoneoff
blastn11+2/−35/2exact wordsone hitDUST, soft maskingnoneoff
blastn-short7+1/−35/2exact wordsone hitDUST, soft maskingnoneoff

Every task has an E-value threshold of 10. The X-drop limits (below) are, in the protein programs, 7 bits without gaps, 15 for the first gapped pass and 25 for the final one, with a gap trigger of 22 bits; in the nucleotide tasks, 20 bits without gaps, 25 (megablast) or 30 for the first gapped pass and 100 for the final one, with a trigger of 27. The API does not take X-drop values, the two-hit window or the gap trigger. BLAST+ keeps 500 target sequences; the API and the BLAST page ask for 100 unless told otherwise (at most GL1X_BLAST_MAX_TARGETS, 5,000), the MCP tool for 25 and a dataset for as many as it has rows.

The matrix sets the threshold, the window and the default gap costs:

MatrixDefault gap costsThreshold TTwo-hit window
BLOSUM4514/21460
BLOSUM5013/21140
BLOSUM6211/11140
BLOSUM8010/11225
BLOSUM9010/11140
PAM309/11615
PAM7010/11420
PAM25014/21140

blastx adds 1 to the threshold, tblastn and tblastx add 2. Other gap costs, and other reward/penalty pairs for blastn, are accepted where BLAST+ has statistics for them (gap_costs and nucleotide_scoring in GET /api/bio/blast; for blastn also gap costs at or above a pair's limit, see below); anything else is refused with the list of what is supported.

Why these values #

Words and thresholds trade speed for sensitivity. A lower threshold T lets more neighbourhood words seed an alignment: more sensitivity, more work. Requiring two seeds on one diagonal (the two-hit method) discards most chance seeds, since a true similarity usually contains several. The short tasks are for queries too short to build up a significant score with the standard settings: blastp-short uses two-letter words and PAM30, whose relative entropy H (the average information of an aligned pair, in nats) is 1.754 against 0.401 for BLOSUM62 (BLAST+'s ungapped values), so each aligned residue of a close match carries more information and fewer are needed to reach a given bit score; blastn-short uses seven-base words. megablast, with 28-base words, is meant for nearly identical sequences, blastn, with 11-base words, for more distant ones.

How a search runs #

  1. Query preparation. Each query becomes one or more contexts: the protein itself, the two strands of a nucleotide query (blastn), or its six translated frames (blastx, tblastx). Low-complexity regions are masked where the task filters: SEG for blastx, tblastn and tblastx (BLAST's parameters window 12, locut 2.2, hicut 2.5), DUST for blastn (symmetric DUST as dustmasker computes it, level 20, window 64, linker 1); blastp leaves SEG off by default and relies on composition-based statistics. With soft masking (the blastn default), masked letters only stop seeds; otherwise they are replaced by X or N for the whole search. Translated programs build the six frames with the chosen genetic code. The ungapped λ, K and H of each context are computed from its own composition.
  2. Lookup. Protein programs build the neighbourhood words of the query (every word of three residues scoring at least the threshold against a query word: 11 for BLOSUM62); nucleotide programs use exact words (28 for megablast, 11 for blastn, 7 for blastn-short).
  3. Seeds and ungapped extension. The database is scanned for words; protein programs require two hits on a diagonal within 40 letters (the two-hit method), then extend without gaps until the score drops more than the X-drop below its best. An extension that reaches the gap trigger goes on to the gapped stage.
  4. Gapped extension. Seeds that score enough are extended with gaps (dynamic programming with an X-drop; greedy extension for megablast), first for the score, then with traceback for the alignment.
  5. Statistics. Scores become bit scores and E-values with Karlin–Altschul statistics: the λ, K and H of the matrix and gap costs from BLAST+'s tables, its length adjustment and effective search space, and Spouge's finite-size correction where BLAST+ applies it. Translated searches combine consistent HSPs with sum statistics, as BLAST+ does by default for blastx, tblastn and tblastx.
  6. Composition-based statistics. For gapped blastp, blastx and tblastn, mode 2 by default: each subject's scores are recomputed with a scoring matrix adjusted to the compositions of the query and the subject (conditional compositional score matrix adjustment), or scaled by composition-based statistics (mode 1), or adjusted unconditionally (mode 3); mode 0 turns it off.
  7. Report. HSPs are pruned for containment as BLAST+ prunes them, hits and HSPs are sorted in its order, and each hit is joined with its MolNFT record.

The details that make the answers identical: the interval tree of HSPs with BLAST+'s common-endpoint rules, the order in which removed HSPs leave the list, the merging of masked regions, the sequence of batches and early termination of composition-based statistics emulated over parallel workers, and the nucleotide database as BLAST+ builds it: ambiguous bases replaced by random bases (seeded with the sequence length, as makeblastdb does) for seeding and extension, the real codes kept on the side and used for the traceback, composition-based statistics, the re-evaluation of ungapped HSPs and the report.

Scoring alignments #

A substitution matrix gives each pair of residues a score. The BLOSUM and PAM matrices are log-odds tables: the score of residues a and b is proportional to ln(q(a,b) / (p(a)·p(b))), where q(a,b) is how often a and b are aligned in related proteins and p(a), p(b) are how common each residue is. A positive score marks a pair seen in true alignments more often than by chance (in BLOSUM62, W–W scores 11, A–A 4, L–I 2), a negative score a pair seen less often (A–W −3). The expected score of two random residues must be negative (−0.95 with BLOSUM62 and BLAST's standard composition), so that a random alignment drifts downwards and only a real similarity builds up a high score.

Gap costs are affine: a gap of k letters costs open + k × extend, so with BLOSUM62's default 11/1 a one-letter gap costs 12 and a three-letter gap 14. Opening a gap is expensive and lengthening it cheap, which reflects that an insertion or deletion is a rare event that often spans several residues.

Nucleotide programs score a match with the reward and a mismatch with the penalty. An ambiguity code scores the average over the bases it may stand for, rounded: with +2/−3, N against A scores −2 and R (A or G) against A −1. Megablast's gap costs 0/0 mean linear costs: each gap position costs reward/2 − penalty, 2.5 with +1/−2.

Protein letters are the 20 standard residues plus B, Z, J, X, U (selenocysteine), O (pyrrolysine) and * (a stop); U and O score as X. Nucleotide letters are the IUPAC codes; U reads as T, and any other letter becomes N.

Seeds: words and the two-hit method #

Full dynamic programming over hundreds of millions of letters would take far too long, so BLAST first looks for short words. A protein query of m residues has m − w + 1 overlapping words of w letters (w = 3 for blastp). For each, the lookup table lists every word that scores at least the threshold T against it, its neighbourhood. With BLOSUM62 and T = 11, the query word LKW (20 against itself) has 175 neighbours and WWW has 187, while AAA (12 against itself) has only itself. The 121 words of the 123-residue α-lactalbumin query of the worked example have 5,323 neighbourhood words in all, about 44 per position (3,750 distinct words). A query word that scores below T against itself is still indexed for its exact matches: with PAM30 and T = 16 (blastp-short), 159 of the 400 two-letter words are in that case, AG for example (6 + 6 = 12).

The scan reads every word of every database sequence and looks it up. A hit is a pair of positions, one in the query and one in the subject, and lies on a diagonal (the subject position minus the query position). Protein programs use the two-hit method of Gapped BLAST: a hit starts an ungapped extension only when an earlier hit lies on the same diagonal at a distance of at least w letters (so the two words do not overlap) and less than the window A (40 with BLOSUM62). Two nearby hits on one diagonal are far more common inside a real similarity than by chance, so this removes most of the work and little of the sensitivity. A window of 0 turns the method into the one-hit method, which the nucleotide tasks use: every exact word outside the stretch already extended on its diagonal is extended.

Extending a seed: the X-drop #

From a seed, BLAST extends the alignment along the diagonal in both directions, adding up pair scores. The running score rises and falls; the extension stops once it has fallen more than X below the best score seen, and the alignment is cut back to that best point. This rule follows a real similarity to its end and stops quickly in unrelated sequence. X is set in bits and converted to raw units with λ: X(raw) = X(bits) × ln 2 / λ. For the α-lactalbumin query (ungapped λ = 0.3210 from its composition, gapped λ = 0.267 from BLAST+'s table):

StageBitsRaw unitsWhat happens
Ungapped extension716from each two-hit seed, without gaps
Gap trigger2241an ungapped alignment scoring this much goes on to the gapped stage
First gapped pass1538scores only, for every triggered seed
Final gapped pass2564with traceback, for the best subjects

The ungapped X-drop is rounded up, the gap trigger is ⌊(22 × ln 2 + ln K) / λ⌋ with the ungapped K, and the gapped X-drops are rounded down (the final one at least the first one). An ungapped alignment also goes on when it reaches the score the E-value threshold requires, if that is lower than the trigger.

In the protein programs a gapped extension starts at the middle of the best-scoring window of 11 residues of the ungapped alignment and runs outward in both directions by dynamic programming, abandoning cells more than X below the best, so that only a band around the seed is computed. The first pass computes scores only. For blastp with an E-value threshold of 10 or less, a query without a strong ungapped alignment (below 0.68 of the cutoff) first gets a cheaper pass that opens gaps only at every tenth column, recomputed exactly when its result falls between 0.68 of the cutoff and the cutoff. An HSP inside a better one already found is not extended again. The final pass realigns the best subjects with traceback and trims gaps from the ends of each alignment. Megablast uses the greedy alignment of Zhang et al. (2000) for both passes: it follows diagonals by number of differences instead of filling a matrix, which suits nearly identical sequences.

Between the passes each query keeps its best subjects, 1,050 of them when composition-based statistics will rescore them and max_target_seqs is 500 or less; in composition-based modes 2 and 3 the first pass also keeps HSPs up to five times the E-value threshold, since the adjusted scores may make them significant.

Low-complexity filtering: SEG and DUST #

Low-complexity regions (runs of one residue, short repeats, strongly biased compositions) align with many unrelated sequences and reach scores the statistics do not expect. Masking them before the search removes these false hits.

SEG (Wootton and Federhen) measures complexity as the Shannon entropy of the composition of a sliding window: H = −Σ fᵢ log₂ fᵢ over the fractions fᵢ of the 20 amino acids in the window (a window with more than two letters outside the 20 is not scored). With BLAST's parameters (window 12, locut 2.2 bits, hicut 2.5 bits), a window at or below 2.2 bits starts a segment, which grows while neighbouring windows stay at or below 2.5 bits and is then trimmed, by up to 50 letters, to its least probable part under SEG's model of random sequence; overlapping segments are merged. Twelve different residues give log₂ 12 = 3.58 bits, a window of six Q, three P and three S 1.50 bits, ten Q and two P 0.65 bits. In a 79-residue test sequence with a polyglutamine and a polyproline tract, SEG masks residues 18 to 67; in hen egg-white lysozyme it masks nothing. The seg option takes yes, no or window locut hicut.

DUST (Morgulis et al.) counts the 64 possible triplets of a DNA stretch. With cₜ the count of triplet t and l the number of triplets, the score is Σ cₜ(cₜ − 1)/2 ÷ (l − 1), which grows when a few triplets repeat. A stretch is low-complexity when 10 × its score exceeds the level (20 by default, so a score above 2), within windows of 64 bases; DUST masks the "perfect" stretches that no stretch inside them outscores, and joins masked regions closer than the linker (1 base). A (CA)₂₀ repeat scores 9.2 and a 40-base stretch of mixed sequence 0.3; inserted into 95 bases of mixed sequence, the repeat's 40 bases are masked and nothing else. The dust option takes yes, no or level window linker (a level of 2 to 64, a window of 8 to 64 and a linker of 1 to 32 take effect).

The answer lists each query's masked regions (masked, 1-based, inclusive). Composition-based statistics apply SEG again, to subjects, with window 10, locut 1.8 and hicut 2.1 (see below).

Translation and genetic codes #

blastx translates the query, tblastn the database sequences, tblastx both, in six reading frames: frames +1, +2 and +3 start at the first, second and third base of the given strand, frames −1 to −3 do the same on the reverse complement. Each codon becomes one residue in the chosen genetic code. A stop codon becomes *, which the matrix scores like any other letter, so an alignment can run through a stop at a cost. A codon with ambiguous bases becomes the amino acid that all the codons it may stand for share, else X: with the standard code, ATG GCN TAA RTG reads M, A, *, X (every GCN codon is alanine; RTG is ATG or GTG). All 25 NCBI genetic codes are available (query_gencode for blastx and tblastx, db_gencode for tblastn and tblastx; 1, the standard code, by default). The vertebrate mitochondrial code (2), for example, reads TGA as W, AGA as a stop and ATA as M, where the standard code reads a stop, R and I. Coordinates in the answer are positions on the nucleotide sequence, with from greater than to on the minus strand. tblastn and tblastx skip database sequences shorter than 3 × word size + 2 bases (11 by default).

Queries are searched in the batches the BLAST+ command line reads them in (10,000 letters for blastp, for example). Within a batch, sum statistics use the average length of its queries for their linking cutoffs, so, as in BLAST+, a translated search of several queries can differ at its weakest hits from searches of each query alone. Each query's hits, masked regions and statistics are reported separately.

Statistics: from a score to an E-value #

Karlin–Altschul statistics #

For local alignments without gaps between random sequences of lengths m and n, the number of distinct alignments scoring at least S follows a Poisson distribution with mean

E = K · m · n · e^(−λ·S)

λ is the positive number that solves Σ pᵢ·pⱼ·e^(λ·sᵢⱼ) = 1 over all residue pairs, where pᵢ, pⱼ are the residue frequencies and sᵢⱼ the matrix scores; it exists when the expected score Σ pᵢ·pⱼ·sᵢⱼ is negative and some score is positive, and it converts raw scores to natural units. The pairs of a true alignment occur with the target frequencies qᵢⱼ = pᵢ·pⱼ·e^(λ·sᵢⱼ), and H = λ·Σ qᵢⱼ·sᵢⱼ is their relative entropy: the average score per aligned pair of a true alignment, in nats. K is a second constant computed from the same score distribution.

GL1X computes λ, K and H with BLAST+'s algorithms (Newton's method for λ, a series for K): for each query context, from its composition against the standard composition (the amino-acid frequencies of Robinson and Robinson for proteins, equal frequencies for nucleotides). A unit test checks that, from the standard composition alone, these computations reproduce BLAST+'s ungapped values for every protein matrix (for BLOSUM62, λ = 0.3176, K = 0.134, H = 0.4012). The ungapped parameters set the X-drop and gap trigger in raw units and give the E-values of ungapped searches.

Gapped alignments have no exact theory. BLAST+ uses tables of λ, K and H estimated for each matrix and pair of gap costs, with the α and β of the length adjustment and the parameters of Spouge's correction, and GL1X uses the same tables (BLOSUM62 with 11/1: λ = 0.267, K = 0.041, H = 0.14, α = 1.9, β = −30). For blastn the row depends on the reward, the penalty and the gap costs; a pair with a common divisor uses the reduced pair's row. For some pairs (2/−3, 2/−5, 2/−7, 3/−4) the parameters hold only for even scores, so gapped E-values are computed from the score rounded down to an even number; gap costs at or above a pair's limit (5/2 with 1/−3, the blastn-short default, for example) make BLAST+ use the ungapped parameters.

Bit scores #

The bit score normalizes a raw score S with the λ and K that apply to it:

S′ = (λ·S − ln K) / ln 2

With BLOSUM62 and gaps 11/1, a raw score of 646 is (0.267 × 646 − ln 0.041) / ln 2 = 253.4 bits. In bits the classical E-value reads E = m′·n′·2^(−S′): each extra bit halves the E-value, and the matrix and gap costs no longer appear. Bit scores therefore compare across matrices and across databases; E-values compare only within one search space.

The search space and the length adjustment #

An alignment that reaches a significant score has a typical length, and one starting near the end of either sequence would run out of sequence first. BLAST+ therefore shortens both lengths by a length adjustment ℓ: the query counts as m′ = m − ℓ letters and the database, of N sequences and n letters, as n′ = n − N·ℓ. ℓ is the largest whole number with

ℓ ≤ (α/λ) · (ln K + ln((m − ℓ)·(n − N·ℓ))) + β     and     K·(m − ℓ)·(n − N·ℓ) ≥ max(m, n)

found by iteration as BLAST_ComputeLengthAdjustment does. The product m′·n′ is the effective search space. Each query context reports both (length_adjustment, eff_search_space in statistics). They give the E-values of blastn, tblastx and ungapped searches and of linked sets of HSPs, and the cutoffs that follow from them.

For a short query against a large database the second condition decides: the search space may not fall below max(m, n)/K. In the database of the worked example below (1,288,423 sequences, 395,873,664 letters), ℓ is 23 for a query of 50 residues, 88 for 123, 121 for 300, 124 for 400 and 132 for 1,000.

Spouge's finite-size correction #

For gapped blastp, blastx and tblastn, BLAST+ 2.12 replaces the fixed length adjustment with Spouge's finite-size correction (Park et al. 2012), and GL1X does the same. An alignment that reaches score y needs a stretch of each sequence whose length grows with y, so a short sequence offers fewer places for a high-scoring chance alignment than m·n suggests. The correction treats the lengths an alignment needs on the two sequences as random, with mean a·y + b, variance α·y + β and covariance σ·y + τ, and replaces m·n by the expected area in which such an alignment can start, computed with the normal distribution:

ℓ    = a·y + b                       mean length an alignment of score y needs
v    = max(2α/λ, α·y + β)            its variance
c    = max(2σ/λ, σ·y + τ)            covariance of the two lengths
f(L) = (L − ℓ)·Φ((L − ℓ)/√v) + √v·φ((L − ℓ)/√v)
area = f(m)·f(n) + c·Φ((m − ℓ)/√v)·Φ((n − ℓ)/√v)
E    = area · K · e^(−λ·y) · D / n

Φ and φ are the standard normal distribution function and density, m the query length, n the subject length and D the letters in the database. The factor D/n scales the expectation for one subject to the whole database, so the same score gets a larger E-value against a longer subject. a is the α of the length adjustment, α and σ come from BLAST+'s table, and b = 2G·(aᵤ − a), β = 2G·(αᵤ − α) and τ = 2G·(αᵤ − σ), where G is the gap open plus extend cost and aᵤ, αᵤ are the ungapped row's values. For BLOSUM62 with 11/1: a = 1.9, b = −26.6, α = 42.6, β = −903.3, σ = 43.6, τ = −928.1. The first stage keeps an HSP when its score reaches the point where this E-value, computed for BLAST+'s assumed shortest subject of 10 residues, crosses the threshold (five times the threshold in composition-based modes 2 and 3, which rescore it later).

For the α-lactalbumin query of the worked example and a subject of 130 residues, the engine's formulas give:

Raw scoreBitsE with Spouge's correctionClassical E (m′·n′)
5023.9911646
6027.74145
8035.40.0710.21
10043.11.0 × 10⁻⁴1.0 × 10⁻³
257103.63.7 × 10⁻²⁸6.4 × 10⁻²²
646253.42.2 × 10⁻⁸⁷5.0 × 10⁻⁶⁷

Near the threshold the two agree closely. For strong hits between short sequences, Spouge's E-values are smaller by many orders of magnitude, since a chance alignment scoring 646 would need about 1,200 residues of each sequence (a·y + b), far more than either has.

A worked example #

A blastp search with the default options, its query human α-lactalbumin (the 123-residue chain of PDB 1A4V, UniProt P00709), against the MolNFT protein database as it stood on 16 October 2026: 1,288,423 sequences of 395,873,664 letters. Its numbers, step by step:

  1. Query statistics. From the query's composition: λ = 0.3210, K = 0.1373, H = 0.4366 (the standard composition gives 0.3176, 0.134, 0.401). The X-drops follow: 16 raw units without gaps, a gap trigger of 41, 38 and 64 with gaps.
  2. Search space. ℓ = 88, so m′ = 123 − 88 = 35 and n′ = 395,873,664 − 1,288,423 × 88 = 282,492,440; m′·n′ = 9,887,235,400, reported as eff_search_space. The first condition alone would allow ℓ = 105, but the search space may not fall below n/K, which caps ℓ at 88.
  3. Hits. 500 hits came back (the search asked for 500 targets). Some of them:
RankHitIdentityColumnsGaps (openings)Raw scoreBitsE-value
1α-lactalbumin, human (PDB 1HML)100%1230646253.43.7 × 10⁻⁸⁷
15α-lactalbumin, baboon (1ALC)93.4%1220598235.04.0 × 10⁻⁸⁰
22α-lactalbumin, goat (1HMK)76.4%1230516203.41.4 × 10⁻⁶⁷
85lysozyme, human, a mutant (1I22)42.0%1195 (3)257103.63.8 × 10⁻²⁸
417lysozyme, hen egg white, a mutant (1IOR)40.9%1154 (3)23795.93.8 × 10⁻²⁵
  1. Reading them. The query's own sequence comes first (in 1HML a 142-residue chain whose residues 20 to 142 align with the 123 of the query). Other species' α-lactalbumins follow, then, from rank 85 to the end, 416 c-type lysozymes at 38–43% identity with E-values between 10⁻²⁸ and 10⁻²⁴: unmistakable homologues despite the modest identity. Their alignments cover residues 1 to 114 of the query (93%) with three gap openings in most cases. The list stops at 500 because of the target limit, not the E-value threshold; many more lysozymes are significant.

The scores here are those of composition-adjusted matrices (see below), and the E-values were computed from the adjusted scores before rounding, so they differ slightly from the table of the previous section (3.8 × 10⁻²⁸ for the score of 257 here, 3.7 × 10⁻²⁸ there).

Sum statistics in translated searches #

A gene's exons, or a protein that a frameshift splits, give several HSPs between one query and one subject, each perhaps too weak to be significant alone. Sum statistics (Karlin and Altschul 1993) assess such a set together; BLAST+ and GL1X apply them by default to blastx, tblastn and tblastx (sum_stats turns them on or off). The HSPs of a set lie in the same order on both sequences. blastx and tblastn link them with uneven gaps, the nucleotide side skipping an intron of up to 122 bases (40 residues); tblastx and ungapped searches use the older even-gap method (gaps up to 40 letters, overlaps up to 9).

For a set of r HSPs, the normalized scores λ·Sᵢ − ln K are summed, the logarithms of the number of ways such a set could be placed and of r! are subtracted, and the result is turned into a probability with Karlin and Altschul's distribution for sums, then into an E-value over the search space. That E-value is divided by (1 − d)·d^(r−1), a penalty for having tried sets of every size, with d = 0.1 in gapped searches and 0.5 otherwise. Every HSP then carries the E-value of the set it ends up in. Even a lone HSP pays the penalty: its E-value is divided by 0.9 in gapped blastx and tblastn, and by 0.5 in tblastx.

Composition-based statistics #

A substitution matrix assumes the background composition of typical proteins. A query or a subject of biased composition, rich in a few residues, scores higher against unrelated sequences of similar bias than the statistics expect. Composition-based statistics correct this subject by subject: BLAST+ 2.12 applies them by default to gapped blastp, blastx and tblastn (comp_based_stats 2), and so does GL1X. They need a gapped search and run during the final pass, on every candidate subject:

  1. Compositions. A protein's composition is that of the whole sequence; a translated sequence's is that of the stretch around each HSP up to the nearest stop codons, in windows of 200 residues on each side.
  2. Masking. The subject is masked with SEG (window 10, locut 1.8, hicut 2.1) unless it is nearly identical to the query (more than 96% identity, tested for an HSP that covers at least min(query length, 50) subject residues at 1.74 bits or more per column).
  3. The adjustment. In mode 2 (conditional adjustment), a sequence longer than 50 residues whose two most frequent residues make up more than 40% of it gets a new matrix; otherwise the compositions are compared: when the distance between query and subject compositions exceeds 0.16, the longer sequence is more than three times the length of the shorter, and the angle between the two compositions seen from the matrix's background exceeds 70°, the matrix is only rescaled; in every other case it is adjusted. The distance is the square root of the Jensen–Shannon divergence; the angle follows from the three distances by the law of cosines.
  4. A new matrix. Adjusting means computing target frequencies qᵢⱼ as close as possible to the matrix's own (in relative entropy) whose row and column sums are the query's and the subject's compositions, each mixed with 20 pseudocounts of the matrix's background (with weight 20 / (n + 20) for a sequence of n amino acids), at a fixed relative entropy of 0.44, and turning them back into scores. Rescaling (mode 1's method, and the fallback when the optimization fails) multiplies the scores by the ratio of the matrix's λ for the two compositions to its standard λ, kept between 0.5 and 1, which brings its λ for the pair back to the standard value.
  5. Realignment. The subject's HSPs are aligned again with traceback in the new matrix, in units 32 times finer than the matrix's (gap costs scaled the same way), with an X-drop of 25 bits. E-values are computed from these scores with λ scaled to match, HSPs above the threshold are dropped, and the scores are divided by 32 and rounded for the report.
  6. Keeping the best. Each query keeps its best max_target_seqs subjects plus every subject with an E-value of 0.002 or less; once every query has its full number of subjects at 0.002 or better, candidates whose first-pass E-value is above 0.01 are skipped. The realignments run in parallel but are taken in BLAST+'s order, so the outcome is that of its single-threaded traceback.
ModeWhat it does
0no composition-based statistics
1rescales the matrix for every subject (Schäffer et al. 2001)
2 (default)adjusts or rescales, depending on the compositions (Yu and Altschul 2005)
3adjusts the matrix for every subject

The effect is visible in the scores: the self-alignment of hen egg-white lysozyme (129 residues) scores 720 with plain BLOSUM62, and 676 after the adjustment.

Reading the results #

The hit list #

Hits come in BLAST+'s order: by best E-value (E-values below 10⁻¹⁸⁰ count as equal), then by the score of the first HSP, then the sequence stored later in the database first. Within a hit, the HSPs come in E-value order. max_target_seqs keeps the best subjects and max_hsps the best HSPs of each. Hits whose E-value exceeds the threshold are not reported.

The numbers of a hit and of an HSP #

FieldMeaning
scoreraw score in the matrix's units (after composition-based adjustment, rounded back to whole units)
bit_score(λ·S − ln K) / ln 2 with the λ and K of the context
evalueexpected number of chance HSPs this good in this search
identity, positiveidentical pairs; identical pairs plus pairs with a positive score (proteins only)
gaps, gap_opensgap columns, and the runs they form
mismatchesalign_len − identity − gaps
align_lenalignment columns, gaps included
percent_identity100 × identity / align_len
qcovhspshare of the query this HSP covers, whole percent
query_from, query_to, hit_from, hit_to1-based, inclusive; on a minus strand or frame, from is greater than to
query_frame, hit_frame, query_strand, hit_strandtranslated frames, or blastn strands
qseq, hseq, midlinethe aligned letters; the midline shows the letter of an identity (| for nucleotides), + for a positive substitution and a space otherwise

For each hit: evalue is its lowest HSP E-value, bit_score its highest HSP bit score, total_bit_score the sum over its HSPs, percent_identity that of its first HSP. query_coverage is the share of the query covered by the union of its HSPs, to one decimal; qcovs is the same in whole percent, rounded as BLAST+ rounds it: half a percent is added below 99% only, so 99.6% reads 99 and only full coverage reads 100. evalue_text and bit_score_text print the values as BLAST+ does (E-values below 10⁻¹⁸⁰ as 0.0; bit scores above 99.9 without decimals, so 263.53 prints 263).

The alignment of hit 85 of the worked example shows the three lines (columns 1 to 60):

KQFTKCELSQLLK--DIDGYGGIALPELICTMFHTSGYDTQAIVEN--NESTEYGLFQIS
K F +CEL++ LK   +DGY GI+L   +C     SGY+T+A   N  + ST+YG+FQI+
KVFERCELARTLKRLGMDGYRGISLANWMCLAKWESGYNTRATNYNAGDRSTDYGIFQIN

Interpreting E-values, scores and identity #

An E-value is a count, not a probability, though below about 0.01 the two nearly coincide. It depends on the size of the search: very nearly proportional to the database's letters (in the example, halving the database halves the E-value of the score of 257, from 3.7 × 10⁻²⁸ to 1.8 × 10⁻²⁸) and growing with the subject's length. The same pair of sequences therefore gets different E-values in databases of different size, and as MolNFT records are minted the database grows. Bit scores do not depend on the database.

With the default threshold of 10, the bottom of a list can hold alignments expected by chance: in a search of unrelated sequences about ten would be expected. For a list of homologues, a strict threshold is the simplest guard (the API example uses 0.001). Identity alone says little about significance: a raw score of 50, about what ten identical residues of average composition score with BLOSUM62 (5.2 per residue), has an E-value near 900 in the example's database, while the human lysozyme hit at 42% identity over 119 columns has 3.8 × 10⁻²⁸. The E-value weighs the length, the composition and the size of the search together.

Coverage matters for annotation. A local alignment may cover one domain of a multi-domain protein: qcovs and the coordinates tell how much of each sequence aligns before a function is carried over.

Pitfalls and limits #

  • The database grows. Keep the answer's database block (sequences, letters, generation) with the results.
  • Many records, one sequence. The PDB holds many entries of the same protein, and MolNFT holds PDB entries in more than one collection. A blastp search of hen egg-white lysozyme returned 500 hits, all identical to the query, from 500 different records; in the worked example 165 of the 500 hits carried the accession of human lysozyme, and some PDB entries appeared twice, once from each PDB collection. The target limit fills with copies: raise max_target_seqs to see further, and see datasets for redundancy in training data.
  • max_target_seqs is not only a display limit. It sizes the list of candidates kept before the final pass and, with composition-based statistics, when rescoring stops early, as in BLAST+; hits near the bottom of a list can differ between two values.
  • Short queries. Below 30 residues, blastp-short is the right task (the BLAST page picks it); below 10 residues, and up to 30 when BLAST finds nothing, the molecular search scans for the sequence as a motif instead.
  • The genetic code. Translated searches of mitochondrial or other non-standard genes need the matching code; with the standard code, their reassigned codons read as stops or as other residues.

Validation #

The engine was compared with NCBI BLAST+ 2.12.0 on 78 configurations: every program and task; other matrices and gap costs; filters on and off with soft and hard masking; ungapped searches; plus and minus strands; composition-based statistics in every mode; sum statistics; random and mutated sequences; and NCBI's own test databases with ambiguity codes and a yeast chromosome. In every configuration the hits, scores, E-values, alignments and their order are identical.

Unit tests guard the parts: the ungapped λ, K and H computed from every protein matrix and the standard composition reproduce BLAST+'s tables (λ within 0.05%, K and H within 0.5%); nucleotide λ solves its defining equation for several reward/penalty pairs, and ambiguity codes score as BLAST+ scores them; the length adjustment stays in range and vanishes for tiny search spaces; every range of every translated frame matches the full translation; removing, merging and compacting database sequences leaves searches unchanged; a fuzz test (GL1X_BLAST_FUZZ) runs random searches with every program, task and odd input and requires that none fails or panics; and, with a test database, identical chains of a record fold into one sequence.

The databases #

The sequences are held in memory as one protein and one nucleotide database, read from PostgreSQL when a web process starts and kept current within seconds as the indexer writes new sequences (GL1X_BLAST_REFRESH, 5 s), and rebuilt every GL1X_BLAST_REBUILD (6 h).

  • Identical chains are one sequence. The identical chains of one record (the eight copies of a homo-octamer, a dimer's A and B) are one database sequence naming them all (chains and sequence_keys in the answer, the representative first), so a search finds the structure once and the statistics count each distinct sequence once. The same letters in two records stay two sequences.
  • Size and speed. 234,592 sequences of 123 million letters load in 1.4 s. On the 2-vCPU test machine, against those 123 million letters, through the API (BLAST+ 2.12.0 with 2 threads on the same machine in brackets):
SearchGL1XBLAST+ 2.12.0
blastp, 400-residue protein1.3 s1.6 s
blastx, 1,500 bases2.1 s2.3 s
tblastx1.2 s1.6 s
tblastn0.6 s0.6 s
blastn0.02 s

A search uses every CPU (GL1X_BLAST_THREADS), so a large server answers in a fraction of that. Identical requests are answered from memory; searches beyond the concurrency wait in a short queue and beyond it get 503 with Retry-After.

How the databases are built and kept:

  • What goes in. Every current sequence row of the index: one per chain or sequence key of every record (molecular_sequences). A row's type decides its database; a row of unknown type counts as nucleotide when at least 90% of its letters are A, C, G, T, U or N.
  • Folding. The rows of one record with the same SHA-256 (and type) become one database sequence. Its representative is the record's primary sequence when that is one of them, else the first in the record's order.
  • Following the index. Every 5 s the rows changed since the last look are read (going back 30 s, since a transaction's rows can become visible after newer ones). Each changed record is read again whole and replaces its sequences; a look that finds 50,000 changed rows or more loads everything again.
  • Snapshots. A search reads an immutable snapshot: a refresh never makes it wait, and it finishes on the database it started with.

The database's letters, and for the length adjustment its number of sequences after folding, enter the statistics. Each answer names the database it searched (database: sequences, letters, generation), and cached answers are keyed by the generation, so a changed database is searched again.

Answers and formats #

POST /api/bio/blast takes a JSON object: query (FASTA or plain), program, task, evalue, max_target_seqs, max_hsps, matrix, gapopen, gapextend, reward, penalty, word_size, threshold, comp_based_stats, seg, dust, soft_masking, sum_stats, ungapped, strand, query_gencode, db_gencode, no_alignments, and format.

A query is ASCII FASTA or a plain sequence: digits, spaces and gap characters are dropped, a final * is removed, and a query without a name is called Query_1, Query_2 and so on. A request holds up to 100 queries of 100,000 letters in all (GL1X_BLAST_MAX_QUERIES, GL1X_BLAST_MAX_QUERY_LETTERS) in a body of up to 2 MB.

FormatWhat it is
json (default)the queries, each with its hits: the subject (contract, token, sequence key, chains, type, length, SHA-256), the record (collection, identifiers, title), links (record page, API, proof), best E-value and bit score, total score, query coverage, identity and every HSP (scores, identities, positives, gaps, coordinates, frames or strands and, unless no_alignments, the aligned letters); the masked regions; the statistics of each query context (λ, K, H, effective search space, length adjustment); the parameters; the database
tsvBLAST tabular output (-outfmt 6): qseqid sseqid pident length mismatch gapopen qstart qend sstart send evalue bitscore; subjects named contract:token:sequence_key
fastathe full sequences of the hits
msathe query-anchored alignment of the best hits (FASTA; for programs whose query is not translated)

In the msa format each hit contributes its first HSP, laid on the query's coordinates (letters it inserts relative to the query are left out). The statistics of a context give the ungapped λ, K and H of its composition and, for gapped searches, the gapped values; params echoes every value the search ran with, defaults included.

GET /api/bio/blast lists what a search accepts (programs, tasks and their defaults, matrices and gap costs, genetic codes, limits) and the state of the databases; GET /api/bio/blast/db the databases alone.

Through MCP, blast_search takes query, program, task, evalue, max_target_seqs (25 by default, at most 500), matrix and alignments (off by default), and blast_database describes the databases.

The page shows the databases, a FASTA editor (examples, files), the program, task and parameters, and the results: a graphic summary of where hits align on the query (coloured by bit score), the table of significant alignments, a query-anchored multiple alignment, every pairwise alignment, downloads (TSV, FASTA, the multiple alignment, JSON) and a dataset builder that turns the hits into a machine-learning dataset with the features of every hit's sequence and structure (datasets). A link from a MolNFT card opens the page with the card's sequence and runs it.

Proofs #

Every hit names its contract, NFT, sequence key and the SHA-256 of the sequence. GET /api/bio/records/{contract}/{token_id}/proof?key=… (the Verify on chain button, MCP molecule_sequence_proof) derives the record's sequences again from the chain at a pinned block and, for MolNFT v1, from IPFS blocks each checked against its CID, and compares their SHA-256 with what was searched. See MolNFT.

A motif such as QEEY is too short for BLAST to score (four residues fall far below any E-value cut-off), so the molecular search scans every indexed sequence for it instead, exactly, in a few hundredths of a second for a hundred million letters (internal/blast/motif.go).

  • Syntax. A word of capital residue letters that matches no title, or a pattern after motif: in PROSITE's notation: x any residue, [QR] one of, {P} none of, x(3) a repeat (ranges such as x(2,4) are not supported), < and > the sequence's ends; [QR]-E-E-Y works too.
  • Certain matches only. A residue matches only when it certainly does: B (D or N) matches [DN] but not D; X matches only x.
  • Results. Each sequence that holds the motif, with the positions, the residues around the first occurrence and, for a pattern with choices, what each occurrence holds; the summary counts occurrences, sequences and records, the variants across all of them (up to 4,096 kinds; a pattern whose occurrences hold more lists none) and how many are in each collection (collection= narrows the results to one). Identical chains are one result.
  • When it is used. Sequences shorter than 10 residues are searched this way, and so are sequences of up to 30 that BLAST finds nothing for. A pattern written in A, C, G, T, U and N only (GATC) is also looked for in nucleotide sequences.

GET /api/bio/search?q=motif:[QR]EEY, MCP molecule_search. Each hit opens its record with the motif marked (?find=…), and Find it in the structures runs the same pattern over the 3D structures (see Structures).

Configuration #

SettingDefaultWhat it does
GL1X_BLASTonthe BLAST databases and searches
GL1X_BLAST_THREADS0 (every CPU)goroutines one search uses
GL1X_BLAST_CONCURRENCYautotune: CPUs ÷ 8 ÷ web processes, 2 to 16searches running at once
GL1X_BLAST_QUEUE, GL1X_BLAST_QUEUE_WAIT4 × concurrency, 20ssearches waiting for a slot, and for how long
GL1X_BLAST_MAX_QUERY_LETTERS, GL1X_BLAST_MAX_QUERIES, GL1X_BLAST_MAX_TARGETS100000, 100, 5000request limits
GL1X_BLAST_TIMEOUT120sone search
GL1X_BLAST_CACHE_MBautotune: RAM/256, 64 MB–1 GBfinished answers kept for identical requests
GL1X_BLAST_REFRESH, GL1X_BLAST_REBUILD5s, 6hhow often the databases follow the index, and are rebuilt

Each client may run 6 searches at once, then one every 2 seconds.

References #

  • Altschul SF, Gish W, Miller W, Myers EW, Lipman DJ (1990) Basic local alignment search tool. J Mol Biol 215:403–410.
  • Altschul SF, Madden TL, Schäffer AA, et al. (1997) Gapped BLAST and PSI-BLAST: a new generation of protein database search programs. Nucleic Acids Res 25:3389–3402.
  • Altschul SF, Wootton JC, Gertz EM, et al. (2005) Protein database searches using compositionally adjusted substitution matrices. FEBS J 272:5101–5109.
  • Camacho C, Coulouris G, Avagyan V, et al. (2009) BLAST+: architecture and applications. BMC Bioinformatics 10:421.
  • Henikoff S, Henikoff JG (1992) Amino acid substitution matrices from protein blocks. Proc Natl Acad Sci USA 89:10915–10919.
  • Karlin S, Altschul SF (1990) Methods for assessing the statistical significance of molecular sequence features by using general scoring schemes. Proc Natl Acad Sci USA 87:2264–2268.
  • Karlin S, Altschul SF (1993) Applications and statistics for multiple high-scoring segments in molecular sequences. Proc Natl Acad Sci USA 90:5873–5877.
  • Morgulis A, Gertz EM, Schäffer AA, Agarwala R (2006) A fast and symmetric DUST implementation to mask low-complexity DNA sequences. J Comput Biol 13:1028–1040.
  • Park Y, Sheetlin S, Ma N, Madden TL, Spouge JL (2012) New finite-size correction for local alignment score distributions. BMC Res Notes 5:286.
  • Robinson AB, Robinson LR (1991) Distribution of glutamine and asparagine residues and their near neighbors in peptides and proteins. Proc Natl Acad Sci USA 88:8880–8884.
  • Schäffer AA, Aravind L, Madden TL, et al. (2001) Improving the accuracy of PSI-BLAST protein database searches with composition-based statistics and other refinements. Nucleic Acids Res 29:2994–3005.
  • Wootton JC, Federhen S (1993) Statistics of local complexity in amino acid sequences and sequence databases. Comput Chem 17:149–163.
  • Yu Y-K, Altschul SF (2005) The construction of amino acid substitution matrices for the comparison of proteins with non-standard compositions. Bioinformatics 21:902–911.
  • Yu Y-K, Wootton JC, Altschul SF (2003) The compositional adjustment of amino acid substitution matrices. Proc Natl Acad Sci USA 100:15688–15693.
  • Zhang Z, Schwartz S, Wagner L, Miller W (2000) A greedy algorithm for aligning DNA sequences. J Comput Biol 7:203–214.

GL1X is a live explorer of the GenesisL1 blockchain. Turn on JavaScript for search, charts and interactive views.