UNPKG

sequaljs

Version:

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

68 lines (67 loc) 2.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Ion = void 0; const sequence_1 = require("./sequence"); const mass_1 = require("./mass"); const resources_1 = require("./resources"); const modifier = { "b": -18 - 19, }; /** * Represents an ion fragment sequence object, inheriting properties from the Sequence class. * * This class is used to convert a Sequence object into an Ion fragment, with additional properties * such as charge, ion type, and fragment number. It also handles modifications and labile groups * within the sequence. */ class Ion extends sequence_1.Sequence { /** * Initialize an Ion object. * * @param seq - The Sequence object to be converted into an Ion fragment * @param charge - The charge of the ion (default is 1) * @param ion_type - The name of the transition type * @param fragment_number - The number of the transition */ constructor(seq, charge = 1, ion_type = null, fragment_number = null) { super(seq); this.charge = charge; this.ion_type = ion_type; this.fragment_number = fragment_number; this.mods = new Map(); this.has_labile = false; // Iterating through each amino acid position and build a modification list for the ion this.seq.forEach((aa, i) => { var _a; if (aa.mods) { for (const m of aa.mods) { if (!(i in this.mods)) { this.mods.set(i, []); } (_a = this.mods.get(i)) === null || _a === void 0 ? void 0 : _a.push(m); if (m.labile) { this.has_labile = true; } } } }); } /** * Calculate the mass-to-charge ratio (m/z) of the ion. * * @param charge - The charge of the ion. If not specified, the object's charge is used * @param with_water - Whether the mass will be calculated with or without water * @param extra_mass - Extra modification of mass that is not represented within the sequence * @returns The calculated m/z value of the ion */ mzCalculate(charge, with_water = false, extra_mass = 0) { if (!charge) { charge = this.charge; } const m = (0, mass_1.calculateMass)(this.seq, undefined, 0, 0, with_water) + extra_mass; // Charge is calculated with the hardcoded mass of protons const mi = (m + charge * resources_1.proton) / charge; return mi; } } exports.Ion = Ion;