UNPKG

sequaljs

Version:

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

328 lines 12.6 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; /** * Represents a sequence of amino acids. * * @template T - The type of the blocks in the sequence. */ 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; peptidoformName: string | null; peptidoformIonName: string | null; compoundIonName: string | null; /** * Initializes a Sequence object. * * @param seq - The sequence string or an array of blocks. * @param encoder - The encoder to use for creating new blocks. * @param mods - The modifications to apply to the sequence. * @param parse - Whether to parse the sequence. * @param parserIgnore - The characters to ignore during parsing. * @param modPosition - The position of the modifications. * @param chains - The chains of the sequence. * @param globalMods - The global modifications of the sequence. * @param sequenceAmbiguities - The sequence ambiguities of the sequence. * @param charge - The charge of the sequence. * @param ionicSpecies - The ionic species of the sequence. */ 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); /** * Creates a Sequence object from a ProForma string. * * @param proformaStr - The ProForma string to parse. * @returns The parsed sequence. */ static fromProforma(proformaStr: string): Sequence; /** * Parses the input sequence into a list of BaseBlock objects. * * @param seq - The sequence string or an array of blocks. * @param modPosition - The position of the modifications. * @private */ private _parseSequence; /** * Applies modifications to a block. * * @param block - The block to apply the modifications to. * @param position - The position of the block. * @param pendingMods - The pending modifications to apply. * @private */ private _applyModifications; /** * Extracts the modification value from a string. * * @param modStr - The modification string. * @returns The modification value. * @private */ private _extractModValue; /** * Iterates through the sequence elements, identifying blocks and modifications. * * @param seq - The sequence string or an array of blocks. * @yields A tuple containing the block and a boolean indicating if it is a modification. * @private */ private _sequenceIterator; /** * Deep copies an object or array. * * @param obj - The object or array to deep copy. * @returns The deep copied object or array. * @private */ private deepCopy; /** * Converts the sequence to a ProForma string. * * @returns The ProForma string. */ toProforma(): string; /** * Converts a chain to a ProForma string. * * @param chain - The chain to convert. * @returns The ProForma string. * @private */ private _chainToProforma; /** * Gets the modifications of an amino acid and adds them to the result string. * * @param aa - The amino acid. * @param result - The result string. * @returns The result string with the modifications. */ getModAndAddToString(aa: AminoAcid, result: string): string; /** * Adds info tags to the result string based on the modification. * * @param result - The result string. * @param mod - The modification. * @returns The result string with the info tags. * @private */ private _addInfoTags; /** * Gets an item or a slice from the sequence. * * @param key - The index or the slice range. * @returns The item or the new sequence. */ getItem(key: number | [number, number]): BaseBlock | AminoAcid | Sequence; /** * Gets the length of the sequence. */ get length(): number; /** * Returns a string representation of the sequence. * @returns The string representation. */ toString(): string; /** * Returns a detailed string representation of the sequence. * @returns The detailed string representation. */ toRepr(): string; /** * Makes the sequence iterable. */ [Symbol.iterator](): Iterator<T>; /** * Checks if two sequences are equal. * * @param other - The other sequence to compare with. * @returns True if the sequences are equal, false otherwise. */ equals(other: any): boolean; /** * Adds modifications to the sequence. * * @param modDict - A dictionary of modifications to add. */ addModifications(modDict: Record<number, Modification[]>): void; /** * Returns the sequence as a string without any modification annotations. * @returns The stripped sequence string. */ toStrippedString(): string; /** * Customizes the sequence string with annotations. * * @param data - The data to use for annotation. * @param annotationPlacement - The placement of the annotations. * @param blockSeparator - The separator to use between blocks. * @param annotationEncloseCharacters - The characters to use for enclosing annotations. * @param individualAnnotationEnclose - Whether to enclose individual annotations. * @param individualAnnotationEncloseCharacters - The characters to use for enclosing individual annotations. * @param individualAnnotationSeparator - The separator to use between individual annotations. * @returns The customized sequence string. */ toStringCustomize(data: Record<number, string | string[]>, annotationPlacement?: 'left' | 'right', blockSeparator?: string, annotationEncloseCharacters?: [string, string], individualAnnotationEnclose?: boolean, individualAnnotationEncloseCharacters?: [string, string], individualAnnotationSeparator?: string): string; /** * Formats an annotation string. * * @param annotations - The annotations to format. * @param individualEnclose - Whether to enclose individual annotations. * @param individualEncloseChars - The characters to use for enclosing individual annotations. * @param separator - The separator to use between annotations. * @param groupEncloseChars - The characters to use for enclosing the group of annotations. * @returns The formatted annotation string. * @private */ private _formatAnnotation; /** * Finds positions in the sequence that match a given regex motif. * * @param motif - The regex motif to search for. * @param ignore - An array of booleans indicating which positions to ignore. * @yields The start and end positions of the matches. */ findWithRegex(motif: string, ignore?: boolean[]): Iterable<[number, number]>; /** * Identifies gaps in the sequence. * * @returns An array of booleans indicating which positions are gaps. */ gaps(): boolean[]; /** * Counts the occurrences of a character in a range. * * @param char - The character to count. * @param start - The start of the range. * @param end - The end of the range. * @returns The number of occurrences. */ count(char: string, start: number, end: number): number; /** * Converts the sequence to a dictionary representation. * @returns A dictionary containing the sequence's attributes. */ toDict(): Record<string, any>; } /** * A 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?; /** * Initializes a ModdedSequenceGenerator object. * * @param seq - The base sequence to modify. * @param variableMods - The variable modifications to apply. * @param staticMods - The static modifications to apply. * @param usedScenarios - The set of used scenarios. * @param parseModPosition - Whether to parse the modification positions. * @param modPositionDict - A dictionary of modification positions. * @param ignorePosition - The positions to ignore. */ constructor(seq: string, variableMods?: Modification[], staticMods?: Modification[], usedScenarios?: Set<string>, parseModPosition?: boolean, modPositionDict?: Record<string, number[]>, ignorePosition?: Set<number>); /** * Generates all possible modification combinations. * * @yields A dictionary of modification positions. */ generate(): Generator<Record<number, Modification[]>>; /** * Generates a dictionary of positions for static modifications. * * @returns A dictionary of modification positions. * @private */ private _generateStaticModPositions; /** * Generates all possible position combinations for variable modifications. * @private */ private _generateVariableModScenarios; /** * Recursively explores all possible modification scenarios. * * @param currentModIdx - The index of the current modification being processed. * @param currentScenario - The current scenario being built. * @yields A dictionary of modification positions. * @private */ private _exploreScenarios; /** * Creates a deep copy of a modification scenario. * * @param scenario - The scenario to deep copy. * @returns The deep copied scenario. * @private */ private _deepCopyScenario; /** * Creates a deep copy of a modification. * * @param mod - The modification to deep copy. * @returns The deep copied modification. * @private */ private _deepCopyModification; } /** * Splits a chimeric ProForma string into its constituent parts. * * @param proformaStr - The chimeric ProForma string to split. * @returns An array of ProForma strings. */ export declare function splitChimericProforma(proformaStr: string): string[]; //# sourceMappingURL=sequence.d.ts.map