UNPKG

sequaljs

Version:

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

112 lines (111 loc) 3.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseBlock = void 0; const utils_1 = require("./utils"); class BaseBlock { constructor(value, position, branch = false, mass) { /** * Initialize a BaseBlock object. * * Parameters * ---------- * value : string * The identifier of the block. * position : number, optional * The position of the block within a chain. * branch : boolean, optional * Indicates whether this block is a branch of another block. * mass : number, optional * The mass of the block in Daltons. */ this._value = value; this._position = position !== null && position !== void 0 ? position : null; this._branch = branch; this._mass = mass !== null && mass !== void 0 ? mass : null; this._extra = undefined; } get value() { /** Get the identifier of the block. */ return this._value; } set value(value) { /** Set the identifier of the block. */ this._value = value; } get position() { var _a; /** Get the position of the block. */ return (_a = this._position) !== null && _a !== void 0 ? _a : null; } set position(position) { /** Set the position of the block. */ this._position = position; } get branch() { /** Check if the block is a branch. */ return this._branch; } get mass() { var _a; /** Get the mass of the block. */ return (_a = this._mass) !== null && _a !== void 0 ? _a : null; } set mass(mass) { /** Set the mass of the block. */ this._mass = mass; } get extra() { /** Get extra information associated with the block. */ return this._extra; } set extra(value) { /** Set extra information for the block. */ this._extra = value; } toDict() { /** * Convert the block to a dictionary representation. * * Returns * ------- * Dictionary containing the block's attributes. */ return { value: this._value, position: this._position, branch: this._branch, mass: this._mass, extra: this._extra, }; } equals(other) { /** Check if two blocks are equal. */ if (!(other instanceof BaseBlock)) { return false; } return (this._value === other.value && this._position === other.position && this._branch === other.branch); } hashCode() { /** Generate a hash for the block. */ const valueHash = (0, utils_1.calculateHashCode)(this._value); const branchHash = this._branch ? 1 : 0; if (this._position === undefined || this._position === null) { return (valueHash !== null && valueHash !== void 0 ? valueHash : 0) ^ branchHash; } else { const positionHash = (0, utils_1.calculateHashCode)(this._position.toString()); return (valueHash !== null && valueHash !== void 0 ? valueHash : 0) ^ (positionHash !== null && positionHash !== void 0 ? positionHash : 0) ^ branchHash; } } toString() { /** Return a string representation of the block. */ return this._value; } toRepr() { /** Return a detailed string representation of the block. */ return `${this.constructor.name}(value='${this._value}', position=${this._position})`; } } exports.BaseBlock = BaseBlock;