UNPKG

sequaljs

Version:

JavaScript/TypeScript library for parsing and manipulating ProForma peptide sequence notation

207 lines 7.63 kB
import { BaseBlock } from './base_block'; import { GlobalModification, Modification } from './modification'; import { AminoAcid } from "./amino_acid"; import { SequenceAmbiguity } from "./proforma"; /** * Count unique elements in a sequence. * * @param seq - The sequence of blocks to count elements from. Each element should * have a `value` attribute and optionally a `mods` attribute. * @returns Dictionary where keys are element values and values are their counts. */ export declare function countUniqueElements<T extends BaseBlock>(seq: Iterable<T>): Record<string, number>; /** * Generate all possible position combinations for modifications. * * This function creates all possible subsets of positions, including * the empty set and the full set. * * @param positions - List of positions where modifications could be applied. * @yields Each possible combination of positions. */ export declare function variablePositionPlacementGenerator(positions: number[]): Generator<number[]>; /** * Serialize a dictionary of positions with consistent ordering. * * @param positions - Dictionary mapping positions to modifications or other data. * @returns JSON string with sorted keys for consistent serialization. * @throws Error if the dictionary contains values that cannot be serialized to JSON. */ export declare function orderedSerializePositionDict(positions: Record<number, any>): string; export declare class Sequence<T extends BaseBlock = AminoAcid> { private static _MOD_PATTERN; private static _MOD_ENCLOSURE_START; private static _MOD_ENCLOSURE_END; encoder: new (value: string, position?: number) => T; parserIgnore: string[]; seq: T[]; chains: Sequence[]; isMultiChain: boolean; mods: Map<number, Modification[]>; globalMods: GlobalModification[]; sequenceAmbiguities: SequenceAmbiguity[]; seqLength: number; charge: number | null; ionicSpecies: string | null; isChimeric: boolean; peptidoforms: Sequence[]; private currentIterCount; /** * Create a sequence object. */ constructor(seq: string | any[] | Sequence, encoder?: new (value: string, position?: number) => T, mods?: Record<number, Modification | Modification[]>, parse?: boolean, parserIgnore?: string[], modPosition?: 'left' | 'right', chains?: Sequence[], globalMods?: GlobalModification[], sequenceAmbiguities?: SequenceAmbiguity[], charge?: number | null, ionicSpecies?: string | null); /** * Create a Sequence object from a ProForma string with multi-chain support. */ static fromProforma(proformaStr: string): Sequence; /** * Parse the input sequence into a list of BaseBlock objects. */ private _parseSequence; /** * Apply modifications to a block. */ private _applyModifications; /** * Extract modification value from a string. */ private _extractModValue; /** * Iterate through sequence elements, identifying blocks and modifications. */ private _sequenceIterator; /** * Deep copy an object or array. */ private deepCopy; /** * Convert the sequence to ProForma format. */ toProforma(): string; /** * Convert a chain to ProForma format. */ private _chainToProforma; /** * Get modifications and add to string. */ getModAndAddToString(aa: AminoAcid, result: string): string; /** * Add info tags to the result string based on the modification. */ private _addInfoTags; /** * Get item or slice from sequence. */ getItem(key: number | [number, number]): BaseBlock | AminoAcid | Sequence; /** * Get length of sequence. */ get length(): number; /** * String representation of sequence. */ toString(): string; /** * Programmatic representation of sequence. */ toRepr(): string; /** * Make the sequence iterable. */ [Symbol.iterator](): Iterator<T>; /** * Check if two sequences are equal. */ equals(other: any): boolean; /** * Add modifications to residues at specified positions. */ addModifications(modDict: Record<number, Modification[]>): void; /** * Return the sequence as a string without any modification annotations. */ toStrippedString(): string; /** * Customize the sequence string with annotations. */ toStringCustomize(data: Record<number, string | string[]>, annotationPlacement?: 'left' | 'right', blockSeparator?: string, annotationEncloseCharacters?: [string, string], individualAnnotationEnclose?: boolean, individualAnnotationEncloseCharacters?: [string, string], individualAnnotationSeparator?: string): string; /** * Format annotation strings. */ private _formatAnnotation; /** * Find positions in the sequence that match a given regex motif. */ findWithRegex(motif: string, ignore?: boolean[]): Iterable<[number, number]>; /** * Identify gaps in the sequence. */ gaps(): boolean[]; /** * Count occurrences of a character in a range. */ count(char: string, start: number, end: number): number; /** * Convert the sequence to a dictionary representation. */ toDict(): Record<string, any>; } /** * Generator for sequences with different modification combinations. * * This class creates all possible modified sequences by applying combinations * of static and variable modifications to a base sequence. */ export declare class ModdedSequenceGenerator { private seq; private staticMods; private variableMods; private usedScenariosSet; private ignorePosition; private staticModPositionDict; private variableMapScenarios; private staticMap?; private variableMap?; /** * Initialize a ModdedSequenceGenerator object. * * @param seq - The base sequence to modify * @param variableMods - List of variable modifications to apply * @param staticMods - List of static modifications to apply * @param usedScenarios - Set of serialized modification scenarios to avoid duplicates * @param parseModPosition - Whether to parse positions using modification regex patterns * @param modPositionDict - Pre-computed positions for modifications * @param ignorePosition - Set of positions to ignore when applying modifications */ constructor(seq: string, variableMods?: Modification[], staticMods?: Modification[], usedScenarios?: Set<string>, parseModPosition?: boolean, modPositionDict?: Record<string, number[]>, ignorePosition?: Set<number>); /** * Generate all possible modification combinations. */ generate(): Generator<Record<number, Modification[]>>; /** * Generate dictionary of positions for static modifications. */ private _generateStaticModPositions; /** * Generate all possible position combinations for variable modifications. */ private _generateVariableModScenarios; /** * Recursively explore all possible modification scenarios. * * @param currentModIdx - Index of the current modification being processed * @param currentScenario - Current scenario being built */ private _exploreScenarios; /** * Create a deep copy of a modification scenario. */ private _deepCopyScenario; /** * Create a deep copy of a modification. */ private _deepCopyModification; } export declare function splitChimericProforma(proformaStr: string): string[]; //# sourceMappingURL=sequence.d.ts.map