Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nucleotide

Package Overview
Dependencies
Maintainers
0
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nucleotide - npm Package Compare versions

Comparing version 3.0.3 to 3.1.0

lib/addFiveTerm.d.ts

478

lib/index.js

@@ -1,462 +0,20 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var chemicalGroups = require('chemical-groups');
var mfUtilities = require('mf-utilities');
/**
* Ensure that the sequence is in uppercase taking into account possible modifications
* @param {string} [options.circular=false]
*/
function ensureUppercaseSequence(sequence) {
let parenthesisCounter = 0;
let parts = [];
let part = '';
for (let i = 0; i < sequence.length; i++) {
let currentSymbol = sequence[i];
if (currentSymbol === '(' && parenthesisCounter === 0 && part) {
parts.push(part);
part = currentSymbol;
} else if (currentSymbol === ')' && parenthesisCounter === 0) {
part += currentSymbol;
parts.push(part);
part = '';
} else {
part += currentSymbol;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
}
if (part) parts.push(part);
for (let i = 0; i < parts.length; i++) {
if (!parts[i].startsWith('(') && parts[i].match(/^[a-z]+$/)) {
parts[i] = parts[i].toUpperCase();
}
}
return parts.join('');
}
/**
* Convert a nucleic sequence to a MF
* @param {String} sequence
* @param {object} [options={}]
* @param {string} [options.kind] - rna, ds-dna or dna. Default if contains U: rna, otherwise ds-dna
* @param {string} [options.fivePrime=monophosphate] - alcohol, monophosphate, diphosphate, triphosphate
* @param {string} [options.circular=false]
*/
function sequenceToMF(sequence, options = {}) {
let fivePrimeTerminal = 'HO';
let threePrimeTerminal = 'H';
sequence = sequence.replace(/^HO/, '');
sequence = sequence.replace(/H$/, '');
sequence = sequence.trim();
if (sequence === '') return '';
sequence = ensureUppercaseSequence(sequence);
// if the sequence is in lowercase but the parenthesis we should convert it to uppercase
if (sequence.match(/^[a-z]+$/)) {
sequence = sequence.toUpperCase();
}
let { kind, circular, fivePrime = 'monophosphate' } = options;
fivePrime = fivePrime.replace(/[^a-zA-Z]/g, '').toLowerCase();
if (!kind) {
if (sequence.includes('U')) {
kind = 'rna';
} else {
kind = 'ds-dna';
}
}
kind = kind.replace(/[^A-Za-z]/g, '').toLowerCase();
if (sequence.includes('(') && kind === 'dsdna') {
throw new Error(
'Nucleotide sequenceToMF: modifications not allowed for ds-DNA',
);
}
let results = [[]];
if (kind === 'dsdna') results.push([]);
let parenthesisCounter = 0;
for (let i = 0; i < sequence.length; i++) {
let currentSymbol = sequence[i];
while (sequence[i + 1] && sequence[i + 1].match(/[a-z]/)) {
i++;
currentSymbol += sequence[i];
}
if (currentSymbol.length > 1) {
results[0].push(currentSymbol);
continue;
}
if (
currentSymbol === '(' ||
currentSymbol === ')' ||
parenthesisCounter > 0
) {
if (currentSymbol === '(') {
parenthesisCounter++;
if (i === 0) fivePrimeTerminal = '';
}
if (currentSymbol === ')') {
parenthesisCounter--;
if (i === sequence.length - 1) threePrimeTerminal = '';
}
switch (kind) {
case 'dna':
case 'rna':
results[0].push(currentSymbol);
break;
default:
// eslint-disable-next-line no-console
console.warn(
`Nucleotide sequenceToMF with modification: unknown kind: ${kind}`,
);
}
continue;
}
let nucleotideType = i === 0 ? fivePrime : 'monophosphate';
currentSymbol = currentSymbol.replace(/[ \t\r\n]/, '');
if (!currentSymbol) continue;
switch (kind) {
case 'dna':
results[0].push(desoxyNucleotides[nucleotideType][currentSymbol]);
break;
case 'rna':
results[0].push(oxyNucleotides[nucleotideType][currentSymbol]);
break;
case 'dsdna':
results[0].push(desoxyNucleotides[nucleotideType][currentSymbol]);
results[1].unshift(
desoxyNucleotides[nucleotideType][complementary[currentSymbol]],
);
break;
default:
// eslint-disable-next-line no-console
console.warn(`Nucleotide sequenceToMF: unknown kind: ${kind}`);
}
}
if (!circular) {
results.forEach((result) => result.unshift(fivePrimeTerminal));
results.forEach((result) => result.push(threePrimeTerminal));
}
return results.map((result) => result.join('')).join('.');
}
const complementary = {
A: 'T',
T: 'A',
C: 'G',
G: 'C',
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
const desoxyNucleotides = {
alcohol: {},
monophosphate: {},
diphosphate: {},
triphosphate: {},
};
chemicalGroups.groups
.filter((group) => group.kind === 'DNA')
.forEach((group) => {
if (group.oneLetter) {
desoxyNucleotides.alcohol[group.oneLetter] = group.symbol;
}
});
chemicalGroups.groups
.filter((group) => group.kind === 'DNAp')
.forEach((group) => {
if (group.oneLetter) {
desoxyNucleotides.monophosphate[group.oneLetter] = group.symbol;
}
});
chemicalGroups.groups
.filter((group) => group.kind === 'NucleotideP')
.forEach((group) => {
if (group.oneLetter) {
desoxyNucleotides.monophosphate[group.oneLetter] = group.symbol;
}
});
chemicalGroups.groups
.filter((group) => group.kind === 'DNApp')
.forEach((group) => {
if (group.oneLetter) {
desoxyNucleotides.diphosphate[group.oneLetter] = group.symbol;
}
});
chemicalGroups.groups
.filter((group) => group.kind === 'DNAppp')
.forEach((group) => {
if (group.oneLetter) {
desoxyNucleotides.triphosphate[group.oneLetter] = group.symbol;
}
});
const oxyNucleotides = {
alcohol: {},
monophosphate: {},
diphosphate: {},
triphosphate: {},
};
chemicalGroups.groups
.filter((group) => group.kind === 'RNA')
.forEach((group) => {
if (group.oneLetter) {
oxyNucleotides.alcohol[group.oneLetter] = group.symbol;
}
});
chemicalGroups.groups
.filter((group) => group.kind === 'RNAp')
.forEach((group) => {
if (group.oneLetter) {
oxyNucleotides.monophosphate[group.oneLetter] = group.symbol;
}
});
chemicalGroups.groups
.filter((group) => group.kind === 'NucleotideP')
.forEach((group) => {
if (group.oneLetter) {
oxyNucleotides.monophosphate[group.oneLetter] = group.symbol;
}
});
chemicalGroups.groups
.filter((group) => group.kind === 'RNApp')
.forEach((group) => {
if (group.oneLetter) {
oxyNucleotides.diphosphate[group.oneLetter] = group.symbol;
}
});
chemicalGroups.groups
.filter((group) => group.kind === 'RNAppp')
.forEach((group) => {
if (group.oneLetter) {
oxyNucleotides.triphosphate[group.oneLetter] = group.symbol;
}
});
function furanThreeTerm(nucleotide) {
// last residue should become a furan
let parts = nucleotide
.replace(/ /g, '')
.replace(/([a-z)0-9])([A-Z][a-z](?=[a-z]))/g, '$1 $2')
.split(/ /);
let last = parts.pop();
if (!last.match(/D[atcg]mp(.*)$/)) {
// eslint-disable-next-line no-console
console.warn(
`furanThreeTerm can not remove a non monophosphate nucleic acid: ${last}`,
);
return parts.join('') + last;
}
return parts.join('') + last.replace(/D[atcg]mp(.*)$/, 'Furp');
}
function addFiveTerm(mfs, fiveTerm, i, options) {
if (options.a) mfs.push(`${fiveTerm}O-1H-1$a${i}`); // neutral ok
if (options.ab && i > 1) mfs.push(`${furanThreeTerm(fiveTerm)}$a${i}-B`); // A minus base
if (options.b) mfs.push(`${fiveTerm}H$b${i}`); // need to add an hydrogen, see: https://books.google.ch/books?id=B57e37bJjqAC&pg=PA172&lpg=PA172&dq=oligonucleotide+b+fragmentation&source=bl&ots=mRr29Pexx2&sig=1NUQcWV-wuj6o9q81my86AVoRto&hl=fr&sa=X&ved=2ahUKEwjI5M3yn-7fAhUJMewKHQR6Bcs4ChDoATADegQIBhAB#v=onepage&q&f=true
if (options.c) mfs.push(`${fiveTerm}PO2$c${i}`); // neutral ok
if (options.d) mfs.push(`${fiveTerm}PO3H2$d${i}`);
if (options.dh2o) mfs.push(`${fiveTerm}PO2$d${i}-H2O`);
}
const mfLosses = {};
['Amp', 'Tmp', 'Cmp', 'Gmp', 'Ump'].forEach((nucleotide) => {
mfLosses[nucleotide] = {
code: nucleotide.charAt(0),
diff: mfUtilities.mfDiff('Rmp', nucleotide),
};
});
['Damp', 'Dtmp', 'Dcmp', 'Dgmp', 'Dump'].forEach((nucleotide) => {
mfLosses[nucleotide] = {
code: nucleotide.charAt(1).toUpperCase(),
diff: mfUtilities.mfDiff('Drmp', nucleotide),
};
});
function baseLoss(nucleotide) {
// any residue can loose a base
let results = [];
for (let key in mfLosses) {
const base = mfLosses[key];
if (nucleotide.includes(key)) {
results.push(`${nucleotide}(${base.diff})$${base.code}*`);
}
}
return results;
}
function addFiveTermBaseLoss(mfs, fiveTerm, i, options) {
if (!options.abcdBaseLoss) return;
let loss = baseLoss(fiveTerm);
loss.forEach((mf) => {
if (options.a) {
mfs.push(`${mf}`.replace('$', `O-1H-1$a${i} `));
}
if (options.b) {
mfs.push(`${mf}`.replace('$', `H-1$b${i} `));
}
if (options.c) {
mfs.push(`${mf}`.replace('$', `PO2$c${i} `));
}
if (options.d) {
mfs.push(`${mf}`.replace('$', `PO3H2$d${i} `));
}
});
}
// https://books.google.ch/books?id=B57e37bJjqAC&pg=PA172&lpg=PA172&dq=oligonucleotide+b+fragmentation&source=bl&ots=mRr29Pexx2&sig=1NUQcWV-wuj6o9q81my86AVoRto&hl=fr&sa=X&ved=2ahUKEwjI5M3yn-7fAhUJMewKHQR6Bcs4ChDoATADegQIBhAB#v=onepage&q=oligonucleotide%20b%20fragmentation&f=false
function addInternalTerm(mfs, internal, ter3, ter5, options = {}) {
if (options.aw) {
// without base loss
mfs.push(`HO${internal}O-1H-1$w${ter3}:a${ter5}`); // A W
}
if (options.bw) {
// without base loss
mfs.push(`HO${internal}H$w${ter3}:b${ter5}`); // B W
}
if (options.abw) {
// with base loss
let fragment = furanThreeTerm(internal);
mfs.push(`HO${fragment}$w${ter3}:a${ter5}-B`); // A minus base - W
}
if (options.aby) {
// with base loss
let fragment = furanThreeTerm(internal);
mfs.push(`O-2P-1${fragment}$y${ter3}:a${ter5}-B`); // A minus base - Y
}
}
function addThreeTerm(mfs, threeTerm, i, options) {
if (options.w) mfs.push(`HO${threeTerm}$w${i}`); // neutral ok
if (options.x) mfs.push(`H-1${threeTerm}$x${i}`); // neutral ok
if (options.y) mfs.push(`O-2P-1${threeTerm}$y${i}`); // neutral ok
if (options.z) mfs.push(`O-3H-2P-1${threeTerm}$z${i}`); // neutral ok
if (options.zch2) mfs.push(`O-3H-4C-1P-1${threeTerm}$z${i}-CH2`); // TODO to confirm
}
function addThreeTermBaseLoss(mfs, threeTerm, i, options) {
if (!options.wxyzBaseLoss) return;
let loss = baseLoss(threeTerm);
loss.forEach((mf) => {
if (options.w) {
mfs.push(`HO${mf}`.replace('$', `$w${i} `));
}
if (options.x) {
mfs.push(`H-1${mf}`.replace('$', `$x${i} `));
}
if (options.y) {
mfs.push(`O-2P-1${mf}`.replace('$', `$y${i} `));
}
if (options.z) {
mfs.push(`O-3H-1P-1(+)${mf}`.replace('$', `$z${i} `));
}
});
}
function generateFragments(mf, options) {
if (options === undefined) {
options = {
a: false,
ab: false,
b: false,
c: false,
d: false,
dh2o: false,
w: false,
x: false,
y: false,
z: false,
zch2: false,
aw: false,
bw: false,
abw: false,
aby: false,
abcdBaseLoss: false,
wxyzBaseLoss: false,
};
}
let mfs = [];
// need to allow 0-9 to deal with neutral loss
let mfparts = mf
.replace(/([a-z)0-9])([A-Z][a-z](?=[a-z]))/g, '$1 $2')
.split(/ /);
let fiveTerm = '';
let threeTerm = '';
if (mfparts[0].startsWith('(')) {
fiveTerm += mfparts[0];
mfparts = mfparts.splice(1);
}
if (mfparts[mfparts.length - 1].includes('(')) {
threeTerm += mfparts[mfparts.length - 1].replace(/^[^()]*/, '');
mfparts[mfparts.length - 1] = mfparts[mfparts.length - 1].replace(
/\(.*/,
'',
);
}
for (let ter5 = 1; ter5 < mfparts.length; ter5++) {
fiveTerm += mfparts[ter5 - 1];
threeTerm = mfparts[mfparts.length - ter5] + threeTerm;
addFiveTerm(mfs, fiveTerm, ter5, options);
addFiveTermBaseLoss(mfs, fiveTerm, ter5, options);
addThreeTerm(mfs, threeTerm, ter5, options);
addThreeTermBaseLoss(mfs, threeTerm, ter5, options);
}
for (let i = 1; i < mfparts.length - 1; i++) {
let internal = '';
for (let j = i; j < mfparts.length - 1; j++) {
internal += mfparts[j];
if (j > i) {
addInternalTerm(mfs, internal, mfparts.length - i, j + 1, options);
}
}
}
return mfs;
}
exports.baseLoss = baseLoss;
exports.furanThreeTerm = furanThreeTerm;
exports.generateFragments = generateFragments;
exports.sequenceToMF = sequenceToMF;
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./sequenceToMF.js"), exports);
__exportStar(require("./generateFragments.js"), exports);
__exportStar(require("./furanThreeTerm.js"), exports);
__exportStar(require("./baseLoss.js"), exports);

@@ -25,11 +25,11 @@ {

},
"version": "3.0.3",
"version": "3.1.0",
"devDependencies": {
"mf-parser": "^3.1.1"
"mf-parser": "^3.2.0"
},
"dependencies": {
"chemical-groups": "^2.1.1",
"mf-utilities": "^3.1.1"
"chemical-groups": "^2.2.0",
"mf-utilities": "^3.2.0"
},
"gitHead": "b9f99ec6f05ce6b0034d35f4ae0452ae653f90c2"
"gitHead": "28dae91d3b42556a23097ee08acfe4061f276ed0"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc