UNPKG

cmpstr

Version:

CmpStr is a lightweight, fast and well performing package for calculating string similarity

48 lines (47 loc) 1.85 kB
/** * Needleman-Wunsch Algorithm * src/metric/NeedlemanWunsch.ts * * @see https://en.wikipedia.org/wiki/Needleman%E2%80%93Wunsch_algorithm * * The Needleman-Wunsch algorithm performs global alignment, aligning two strings * entirely, including gaps. It is commonly used in bioinformatics for sequence * alignment. * * @module Metric/NeedlemanWunsch * @author Paul Köhler (komed3) * @license MIT */ import type { MetricInput, MetricOptions, MetricCompute } from '../utils/Types'; import { Metric } from './Metric'; export interface NeedlemanRaw { score: number; denum: number; } /** * NeedlemanWunschDistance class extends the Metric class to implement the Needleman-Wunsch algorithm. */ export declare class NeedlemanWunschDistance extends Metric<NeedlemanRaw> { /** * Constructor for the NeedlemanWunsch class. * * Initializes the Needleman-Wunsch metric with two input strings or * arrays of strings and optional options. * * @param {MetricInput} a - First input string or array of strings * @param {MetricInput} b - Second input string or array of strings * @param {MetricOptions} [opt] - Options for the metric computation */ constructor(a: MetricInput, b: MetricInput, opt?: MetricOptions); /** * Calculates the Needleman-Wunsch global alignment score between two strings. * * @param {string} a - First string * @param {string} b - Second string * @param {number} m - Length of the first string * @param {number} n - Length of the second string * @param {number} maxLen - Maximum length of the strings * @return {MetricCompute<NeedlemanRaw>} - Object containing the similarity result and raw score */ protected compute(a: string, b: string, m: number, n: number, maxLen: number): MetricCompute<NeedlemanRaw>; }