mass-fragmentation
Advanced tools
Comparing version 0.5.0 to 0.6.0
255
lib/index.js
@@ -7,3 +7,8 @@ 'use strict'; | ||
var openchemlibUtils = require('openchemlib-utils'); | ||
var OCL = require('openchemlib'); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var OCL__default = /*#__PURE__*/_interopDefaultLegacy(OCL); | ||
/** | ||
@@ -492,48 +497,4 @@ * The function performs the fragmentation of all single linear bonds | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eF`BLGtX!eF``fLGt\\#Qd Qd#!R@FL]Rgp !R@FL]vgp', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eM`BN`~b@!eM``fN`~c@#Q[ Q[#!R@AM?DquRo@ !R@AM?Dqtzo@', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'gCh@AGj@`!gChA@Icu@_PP#qTq qTq#!RbOvw?_x@GYK| !RbOvw?_x@GWk|', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: | ||
'gCa@@dmPFtwhHcMCAlp!eMH`eIhOhp#Qv@ Qv#!R@AL@[@@SGSH| !R@Fp@Dqwz``', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eFB@HcA}D@!eFB`HIcA}F@#QX QX#!R_vp]bgp !R_vp]vgp', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eMB@HchH!eMB`HIchOh`#Q[ Q[#!R@AM?Dqtbo@ !R@AM?Dquz@`', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eMHAIXMicLLG~r!eFH`fJGtP#QX QX#!R@AL@[AtbO@ !R@AL]nkp', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eMHBN``!eMH`fN`~b@#Qg Qg#!R@FL?XqtJ_@ !R@FL?XqwZ_@', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eFB@HcA}D@!eFB`HIcA}F@#QX QX#!R_vp]bgp !R_vp]vgp', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eFHBLGtP!eFH`fLGtX#QX QX#!R@AL]Pmp !R@AL]^gp', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eM`BN`~b@!eM``fN`~bOza@#Qg Qg#!R@Fq?[AuJ?@ !R@FM?Dqvz_@', | ||
}, | ||
{ | ||
Label: 'Oxonium Resonance', | ||
@@ -658,6 +619,69 @@ rxnCode: 'eFH`fJGtP!eFHbfLGtP#QX QX#!R@Fp]rgp !R@FL]Nkp', | ||
}; | ||
const ei = { | ||
positive: [], | ||
negative: [], | ||
}; | ||
const esi = { | ||
positive: [ | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eF`BLGtX!eF``fLGt\\#Qd Qd#!R@FL]Rgp !R@FL]vgp', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eM`BN`~b@!eM``fN`~c@#Q[ Q[#!R@AM?DquRo@ !R@AM?Dqtzo@', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'gCh@AGj@`!gChA@Icu@_PP#qTq qTq#!RbOvw?_x@GYK| !RbOvw?_x@GWk|', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: | ||
'gCa@@dmPFtwhHcMCAlp!eMH`eIhOhp#Qv@ Qv#!R@AL@[@@SGSH| !R@Fp@Dqwz``', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eFB@HcA}D@!eFB`HIcA}F@#QX QX#!R_vp]bgp !R_vp]vgp', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eMB@HchH!eMB`HIchOh`#Q[ Q[#!R@AM?Dqtbo@ !R@AM?Dquz@`', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eMHAIXMicLLG~r!eFH`fJGtP#QX QX#!R@AL@[AtbO@ !R@AL]nkp', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eMHBN``!eMH`fN`~b@#Qg Qg#!R@FL?XqtJ_@ !R@FL?XqwZ_@', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eFB@HcA}D@!eFB`HIcA}F@#QX QX#!R_vp]bgp !R_vp]vgp', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eFHBLGtP!eFH`fLGtX#QX QX#!R@AL]Pmp !R@AL]^gp', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eM`BN`~b@!eM``fN`~bOza@#Qg Qg#!R@Fq?[AuJ?@ !R@FM?Dqvz_@', | ||
}, | ||
], | ||
negative: [], | ||
}; | ||
/** | ||
* @description get fragmentation databases based on the technique used | ||
* @param {string} databaseName "cid", "ei" or "esi" | ||
* @returns {object} object containing the fragmentation database | ||
*/ | ||
function getDatabase(databaseName) { | ||
if (databaseName === 'cid') { | ||
return cid; | ||
switch (databaseName) { | ||
case 'cid': | ||
return cid; | ||
case 'ei': | ||
return ei; | ||
default: | ||
return esi; | ||
} | ||
@@ -667,3 +691,3 @@ } | ||
/** | ||
* @description Recursively insert monoisotopic mass information into the fragmentation trees, products and get array of monoisotopic masses | ||
* @description get array of mz from fragmentation trees | ||
* @param {Array} trees Fragmentation trees | ||
@@ -673,17 +697,11 @@ * @param {Array} products Fragmentation trees grouped by product idCode | ||
* - masses: array of monoisotopic masses | ||
* - trees: array of fragmentation trees with monoisotopic mass | ||
* - products: array of trees grouped by product idCode with monoisotopic mass | ||
* - trees: array of fragmentation trees | ||
* - products: array of trees grouped by product idCode | ||
*/ | ||
function insertMfInfoFragments(trees, products) { | ||
function getMasses(trees, products) { | ||
let masses = {}; | ||
for (let tree of trees) { | ||
mfInfoFragments(tree, masses); | ||
} | ||
for (let product of products) { | ||
const productMF = new mfParser.MF(product.mf); | ||
product.monoisotopicMass = | ||
Math.round( | ||
(productMF.getInfo().observedMonoisotopicMass ?? | ||
productMF.getInfo().monoisotopicMass) * 10000, | ||
) / 10000; | ||
if (Math.abs(product.charge) > 0) { | ||
masses[product.mz] = true; | ||
} | ||
} | ||
@@ -698,36 +716,2 @@ return { | ||
/** | ||
* @description Recursively insert monoisotopic mass information into the fragmentation trees and get array of monoisotopic masses | ||
* @param {*} reaction Fragmentation trees | ||
* @param {*} masses Object with monoisotopic masses | ||
*/ | ||
function mfInfoFragments(reaction, masses) { | ||
if (reaction?.reactant) { | ||
const reactantMF = new mfParser.MF(reaction.reactant.mf); | ||
reaction.reactant.monoisotopicMass = | ||
Math.round( | ||
(reactantMF.getInfo().observedMonoisotopicMass ?? | ||
reactantMF.getInfo().monoisotopicMass) * 10000, | ||
) / 10000; | ||
masses[reaction.reactant.monoisotopicMass] = true; | ||
} | ||
if (reaction?.products?.length > 0) { | ||
for (const product of reaction.products) { | ||
const productMF = new mfParser.MF(product.mf); | ||
product.monoisotopicMass = | ||
Math.round( | ||
(productMF.getInfo().observedMonoisotopicMass ?? | ||
productMF.getInfo().monoisotopicMass) * 10000, | ||
) / 10000; | ||
masses[product.monoisotopicMass] = true; | ||
if (product.children?.length > 0) { | ||
for (const child of product.children) { | ||
mfInfoFragments(child, masses); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
/** | ||
* @description Fragment a molecule by applying reactions from a custom database of reactions | ||
@@ -739,2 +723,9 @@ * @param {import('openchemlib').Molecule} molecule - The OCL molecule to be fragmented | ||
* @param {number} [options.maxDepth=5] - The maximum depth of the fragmentation tree | ||
* @param {number} [options.maxIonizationDepth=1] - The maximum depth of the ionization tree | ||
* @param {Object} [options.customDatabase={}] - A custom database of reactions | ||
* @param {Array} [options.customDatabase.positive] - A custom database of reactions for positive mode | ||
* @param {Array} [options.customDatabase.negative] - A custom database of reactions for negative mode | ||
* @param {Object} [options.customDatabase.ionization] - A custom database ionization reactions | ||
* @param {Array} [options.customDatabase.ionization.positive] - A custom database of ionization reactions for positive mode | ||
* @param {Array} [options.customDatabase.ionization.negative] - A custom database of ionization reactions for negative mode | ||
* @returns {object} In-Silico fragmentation results with the following properties: | ||
@@ -746,17 +737,50 @@ * - masses: array of monoisotopic masses | ||
function reactionFragmentation(molecule, options = {}) { | ||
let { databaseName = 'cid', mode = 'positive', maxDepth = 5 } = options; | ||
let database = getDatabase(databaseName); | ||
let { | ||
databaseName = 'cid', | ||
mode = 'positive', | ||
maxDepth = 3, | ||
maxIonizationDepth = 1, | ||
customDatabase = {}, | ||
} = options; | ||
let database; | ||
let IonizationDb; | ||
if (customDatabase[mode] && customDatabase[mode].length > 0) { | ||
database = customDatabase; | ||
} else { | ||
database = getDatabase(databaseName); | ||
} | ||
if (!database) { | ||
throw new Error(`Database ${databaseName} not found`); | ||
} | ||
if (databaseName === 'cid') { | ||
if ( | ||
customDatabase.ionization && | ||
customDatabase.ionization[mode].length > 0 | ||
) { | ||
IonizationDb = customDatabase.ionization[mode]; | ||
} else { | ||
IonizationDb = getDatabase('')[mode]; | ||
} | ||
} | ||
let results = {}; | ||
const reactions = database[mode]; | ||
let fragments = openchemlibUtils.applyReactions([molecule], reactions, { | ||
maxDepth, | ||
}); | ||
if (IonizationDb) { | ||
let ionizationFragments = openchemlibUtils.applyReactions([molecule], IonizationDb, { | ||
maxDepth: maxIonizationDepth, | ||
}); | ||
let { masses, trees, products } = insertMfInfoFragments( | ||
fragments.trees, | ||
fragments.products, | ||
); | ||
for (let tree of ionizationFragments.trees) { | ||
getMoleculesToFragment(tree, reactions, maxDepth); | ||
} | ||
ionizationFragments.products = openchemlibUtils.groupTreesByProducts( | ||
ionizationFragments.trees, | ||
); | ||
results = ionizationFragments; | ||
} else { | ||
results = openchemlibUtils.applyReactions([molecule], reactions, { | ||
maxDepth, | ||
}); | ||
} | ||
let { masses, trees, products } = getMasses(results.trees, results.products); | ||
return { | ||
@@ -769,3 +793,24 @@ masses, | ||
function getMoleculesToFragment(tree, reactions, maxDepth) { | ||
for (let product of tree.products) { | ||
if (product.children.length === 0) { | ||
if (product.charge !== 0) { | ||
let molecule = OCL__default["default"].Molecule.fromIDCode(product.idCode); | ||
let fragments = openchemlibUtils.applyReactions([molecule], reactions, { | ||
maxDepth, | ||
}); | ||
product.children = fragments.trees; | ||
} | ||
} else { | ||
for (let child of product.children) { | ||
getMoleculesToFragment(child, reactions, maxDepth); | ||
} | ||
} | ||
} | ||
} | ||
exports.cid = cid; | ||
exports.ei = ei; | ||
exports.esi = esi; | ||
exports.fragment = fragment; | ||
exports.reactionFragmentation = reactionFragmentation; |
{ | ||
"name": "mass-fragmentation", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "Code to fragment molecules", | ||
@@ -24,9 +24,9 @@ "main": "lib/index.js", | ||
"mf-parser": "^2.3.0", | ||
"openchemlib-utils": "^2.7.0" | ||
"openchemlib-utils": "^5.0.2" | ||
}, | ||
"devDependencies": { | ||
"openchemlib": "^8.3.0", | ||
"react-tree-svg": "^0.1.0" | ||
"openchemlib": "^8.5.0", | ||
"react-tree-svg": "^0.3.0" | ||
}, | ||
"gitHead": "c697f5fab6e34146c16194f54cead9ddd1c8465f" | ||
"gitHead": "a288cfad35ed88e24f17546841389ef0b7fdcbc7" | ||
} |
@@ -12,2 +12,3 @@ import OCL from 'openchemlib'; | ||
maxDepth: 20, | ||
maxIonizationDepth: 2, | ||
}; | ||
@@ -23,9 +24,11 @@ const { masses, trees, products } = reactionFragmentation( | ||
"mf", | ||
"em", | ||
"mz", | ||
"charge", | ||
"trees", | ||
"reactions", | ||
"minSteps", | ||
"monoisotopicMass", | ||
] | ||
`); | ||
expect(masses).toHaveLength(17); | ||
expect(masses).toHaveLength(4); | ||
expect(trees).toMatchSnapshot(); | ||
@@ -36,3 +39,4 @@ }); | ||
const options = { | ||
maxDepth: 20, | ||
maxDepth: 5, | ||
maxIonizationDepth: 2, | ||
}; | ||
@@ -47,9 +51,11 @@ const { masses, trees, products } = reactionFragmentation( | ||
"mf", | ||
"em", | ||
"mz", | ||
"charge", | ||
"trees", | ||
"reactions", | ||
"minSteps", | ||
"monoisotopicMass", | ||
] | ||
`); | ||
expect(masses).toHaveLength(7); | ||
expect(masses).toHaveLength(2); | ||
expect(trees).toMatchSnapshot(); | ||
@@ -66,23 +72,8 @@ }); | ||
[ | ||
193.1103, | ||
194.1176, | ||
31.0422, | ||
32.0495, | ||
163.0754, | ||
135.0441, | ||
68.0257, | ||
45.6862, | ||
30.047, | ||
28.0313, | ||
82.0413, | ||
55.03, | ||
97.5624, | ||
65.3774, | ||
65.0414, | ||
68.5296, | ||
97.0585, | ||
58.0651, | ||
136.0519, | ||
193.1097, | ||
135.0446, | ||
194.11810400000002, | ||
163.075905, | ||
135.04460500000002, | ||
105.03404, | ||
193.11027900000002, | ||
58.065674, | ||
] | ||
@@ -92,6 +83,8 @@ `); | ||
{ | ||
"charge": 1, | ||
"em": 194.11810400000002, | ||
"idCode": "dg~DBMBmeJYW]gJxZB@jj@@", | ||
"mf": "C11H16NO2(+)", | ||
"minSteps": 1, | ||
"monoisotopicMass": 194.1176, | ||
"mz": 194.11810400000002, | ||
"reactions": [ | ||
@@ -104,3 +97,5 @@ "eM\`BN\`~b@!eM\`\`fN\`~c@#Q[ Q[#!R@AM?DquRo@ !R@AM?Dqtzo@", | ||
{ | ||
"charge": 1, | ||
"children": [], | ||
"em": 194.11810400000002, | ||
"flag": true, | ||
@@ -145,5 +140,8 @@ "idCode": "dg~DBMBmeJYW]gJxZB@jj@@", | ||
", | ||
"mz": 194.11810400000002, | ||
}, | ||
], | ||
"reactant": { | ||
"charge": 0, | ||
"em": 193.11027900000002, | ||
"idCode": "dg~D@MBdie]v\\\\kahHBjh@@", | ||
@@ -186,2 +184,3 @@ "mf": "C11H15NO2", | ||
", | ||
"mz": 193.11027900000002, | ||
}, | ||
@@ -198,2 +197,120 @@ "reaction": { | ||
}); | ||
it('Full fragmentation: MDMA with custom database', async () => { | ||
const molecule = Molecule.fromSmiles('CC(CC1=CC2=C(C=C1)OCO2)NC'); | ||
const customDatabase = { | ||
positive: [ | ||
{ | ||
Label: 'Alpha cleavage', | ||
rxnCode: | ||
'gCa@@duPGtF@!fI@Gu` eM@bXzB#qbq a` qQp#!RtEJHC^h@GPhB !RGUi| !R@FN?Dquz_@', | ||
}, | ||
{ | ||
Label: 'Alpha cleavage', | ||
rxnCode: | ||
'gJPI@DBTijhCzB@!gK`I@DJTcj`OhH@#qbqh qfUH#!Rmwwp_[]|_g|]lcp !R?`BE@[_|b@H]vgp', | ||
}, | ||
{ | ||
Label: 'Alpha cleavage', | ||
rxnCode: | ||
'gJPa@eJSKTA}E@!eMH`eIxH eFHBLGtP#qbqh qbH qu#!Rw`BH?J_|bMt]|hH !Rwpq?Dquz?@ !R?`@]vgp', | ||
}, | ||
{ | ||
Label: 'Alpha cleavage', | ||
rxnCode: | ||
'gJQIL@`ReMS@_PP!eMH`eIxH eFB@HcA}D@#qbqh qJh Ql#!Rm?wpwXE?y{p]lmp !Rwxq?Dquz?@ !R@NL]vgp', | ||
}, | ||
{ | ||
Label: 'Alpha cleavage', | ||
rxnCode: | ||
'gJXA@IRij`OhH@!gKhAAirPFhB#qbuH qfjH#!RM{upoPD@Mwp]lgp !R@BL?x~WAwrp]Vgp', | ||
}, | ||
{ | ||
Label: 'Alpha cleavage', | ||
rxnCode: | ||
'gJYADEJSKTA}E`!eMH`eIxH eF`BLGtX#qbqh qbH qu#!RO`BH?C_|bGt]|hH !Rwtq?Dquz_@ !R?`@]vgp', | ||
}, | ||
{ | ||
Label: 'Alpha cleavage', | ||
rxnCode: | ||
'gC`AAJTu@P!eF@bXpP eF@HpP#qTq qa Q\\#!R@AM?DpAlGTJB !R@DQCrip !R_sL}Nmp', | ||
}, | ||
{ | ||
Label: 'Alpha cleavage', | ||
rxnCode: | ||
'gChA@IRfhCzC@!eF`BLD eF@bXpP#qbq Ql qQ#!R{|L@p~~lG[K| !R@DL]Vgp !R_xp]ngp', | ||
}, | ||
{ | ||
Label: 'Aromatic Indicutive Cleavage', | ||
rxnCode: | ||
'gC`AAJTu@]SP!eF@bXpP eF@HhP#qrL QX qq#!Rgzp@kI}cG]K| !R@BL]vgp !R@BL]~kp', | ||
}, | ||
], | ||
ionization: { | ||
positive: [ | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eF`BLGtX!eF``fLGt\\#Qd Qd#!R@FL]Rgp !R@FL]vgp', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eM`BN`~b@!eM``fN`~c@#Q[ Q[#!R@AM?DquRo@ !R@AM?Dqtzo@', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: | ||
'gCh@AGj@`!gChA@Icu@_PP#qTq qTq#!RbOvw?_x@GYK| !RbOvw?_x@GWk|', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: | ||
'gCa@@dmPFtwhHcMCAlp!eMH`eIhOhp#Qv@ Qv#!R@AL@[@@SGSH| !R@Fp@Dqwz``', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eFB@HcA}D@!eFB`HIcA}F@#QX QX#!R_vp]bgp !R_vp]vgp', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eMB@HchH!eMB`HIchOh`#Q[ Q[#!R@AM?Dqtbo@ !R@AM?Dquz@`', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eMHAIXMicLLG~r!eFH`fJGtP#QX QX#!R@AL@[AtbO@ !R@AL]nkp', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eMHBN``!eMH`fN`~b@#Qg Qg#!R@FL?XqtJ_@ !R@FL?XqwZ_@', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eFB@HcA}D@!eFB`HIcA}F@#QX QX#!R_vp]bgp !R_vp]vgp', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eFHBLGtP!eFH`fLGtX#QX QX#!R@AL]Pmp !R@AL]^gp', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eM`BN`~b@!eM``fN`~bOza@#Qg Qg#!R@Fq?[AuJ?@ !R@FM?Dqvz_@', | ||
}, | ||
], | ||
}, | ||
}; | ||
const options = { | ||
maxDepth: 5, | ||
customDatabase, | ||
}; | ||
let { masses, trees, products } = reactionFragmentation(molecule, options); | ||
expect(masses).toMatchInlineSnapshot(` | ||
[ | ||
194.11810400000002, | ||
163.075905, | ||
135.04460500000002, | ||
193.11027900000002, | ||
] | ||
`); | ||
expect(products[0].mf).toMatchInlineSnapshot('"C11H16NO2(+)"'); | ||
expect(trees).toMatchSnapshot(); | ||
}); | ||
}); |
@@ -163,48 +163,4 @@ export const cid = { | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eF`BLGtX!eF``fLGt\\#Qd Qd#!R@FL]Rgp !R@FL]vgp', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eM`BN`~b@!eM``fN`~c@#Q[ Q[#!R@AM?DquRo@ !R@AM?Dqtzo@', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'gCh@AGj@`!gChA@Icu@_PP#qTq qTq#!RbOvw?_x@GYK| !RbOvw?_x@GWk|', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: | ||
'gCa@@dmPFtwhHcMCAlp!eMH`eIhOhp#Qv@ Qv#!R@AL@[@@SGSH| !R@Fp@Dqwz``', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eFB@HcA}D@!eFB`HIcA}F@#QX QX#!R_vp]bgp !R_vp]vgp', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eMB@HchH!eMB`HIchOh`#Q[ Q[#!R@AM?Dqtbo@ !R@AM?Dquz@`', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eMHAIXMicLLG~r!eFH`fJGtP#QX QX#!R@AL@[AtbO@ !R@AL]nkp', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eMHBN``!eMH`fN`~b@#Qg Qg#!R@FL?XqtJ_@ !R@FL?XqwZ_@', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eFB@HcA}D@!eFB`HIcA}F@#QX QX#!R_vp]bgp !R_vp]vgp', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eFHBLGtP!eFH`fLGtX#QX QX#!R@AL]Pmp !R@AL]^gp', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eM`BN`~b@!eM``fN`~bOza@#Qg Qg#!R@Fq?[AuJ?@ !R@FM?Dqvz_@', | ||
}, | ||
{ | ||
Label: 'Oxonium Resonance', | ||
@@ -329,7 +285,70 @@ rxnCode: 'eFH`fJGtP!eFHbfLGtP#QX QX#!R@Fp]rgp !R@FL]Nkp', | ||
}; | ||
export const ei = { | ||
positive: [], | ||
negative: [], | ||
}; | ||
export const esi = { | ||
positive: [ | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eF`BLGtX!eF``fLGt\\#Qd Qd#!R@FL]Rgp !R@FL]vgp', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eM`BN`~b@!eM``fN`~c@#Q[ Q[#!R@AM?DquRo@ !R@AM?Dqtzo@', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'gCh@AGj@`!gChA@Icu@_PP#qTq qTq#!RbOvw?_x@GYK| !RbOvw?_x@GWk|', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: | ||
'gCa@@dmPFtwhHcMCAlp!eMH`eIhOhp#Qv@ Qv#!R@AL@[@@SGSH| !R@Fp@Dqwz``', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eFB@HcA}D@!eFB`HIcA}F@#QX QX#!R_vp]bgp !R_vp]vgp', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eMB@HchH!eMB`HIchOh`#Q[ Q[#!R@AM?Dqtbo@ !R@AM?Dquz@`', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eMHAIXMicLLG~r!eFH`fJGtP#QX QX#!R@AL@[AtbO@ !R@AL]nkp', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eMHBN``!eMH`fN`~b@#Qg Qg#!R@FL?XqtJ_@ !R@FL?XqwZ_@', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eFB@HcA}D@!eFB`HIcA}F@#QX QX#!R_vp]bgp !R_vp]vgp', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eFHBLGtP!eFH`fLGtX#QX QX#!R@AL]Pmp !R@AL]^gp', | ||
}, | ||
{ | ||
Label: 'Ionization', | ||
rxnCode: 'eM`BN`~b@!eM``fN`~bOza@#Qg Qg#!R@Fq?[AuJ?@ !R@FM?Dqvz_@', | ||
}, | ||
], | ||
negative: [], | ||
}; | ||
/** | ||
* @description get fragmentation databases based on the technique used | ||
* @param {string} databaseName "cid", "ei" or "esi" | ||
* @returns {object} object containing the fragmentation database | ||
*/ | ||
export default function getDatabase(databaseName) { | ||
if (databaseName === 'cid') { | ||
return cid; | ||
switch (databaseName) { | ||
case 'cid': | ||
return cid; | ||
case 'ei': | ||
return ei; | ||
default: | ||
return esi; | ||
} | ||
} |
export * from './fragment.js'; | ||
export * from './reactionFragmentation.js'; | ||
export * from './database/getDatabase.js'; |
@@ -1,6 +0,6 @@ | ||
import { applyReactions } from 'openchemlib-utils'; | ||
import OCL from 'openchemlib'; | ||
import { applyReactions, groupTreesByProducts } from 'openchemlib-utils'; | ||
import getDatabase from './database/getDatabase'; | ||
import { insertMfInfoFragments } from './utils/insertMfInfoFragments'; | ||
import { getMasses } from './utils/getMasses'; | ||
/** | ||
@@ -13,2 +13,9 @@ * @description Fragment a molecule by applying reactions from a custom database of reactions | ||
* @param {number} [options.maxDepth=5] - The maximum depth of the fragmentation tree | ||
* @param {number} [options.maxIonizationDepth=1] - The maximum depth of the ionization tree | ||
* @param {Object} [options.customDatabase={}] - A custom database of reactions | ||
* @param {Array} [options.customDatabase.positive] - A custom database of reactions for positive mode | ||
* @param {Array} [options.customDatabase.negative] - A custom database of reactions for negative mode | ||
* @param {Object} [options.customDatabase.ionization] - A custom database ionization reactions | ||
* @param {Array} [options.customDatabase.ionization.positive] - A custom database of ionization reactions for positive mode | ||
* @param {Array} [options.customDatabase.ionization.negative] - A custom database of ionization reactions for negative mode | ||
* @returns {object} In-Silico fragmentation results with the following properties: | ||
@@ -20,17 +27,50 @@ * - masses: array of monoisotopic masses | ||
export function reactionFragmentation(molecule, options = {}) { | ||
let { databaseName = 'cid', mode = 'positive', maxDepth = 5 } = options; | ||
let database = getDatabase(databaseName); | ||
let { | ||
databaseName = 'cid', | ||
mode = 'positive', | ||
maxDepth = 3, | ||
maxIonizationDepth = 1, | ||
customDatabase = {}, | ||
} = options; | ||
let database; | ||
let IonizationDb; | ||
if (customDatabase[mode] && customDatabase[mode].length > 0) { | ||
database = customDatabase; | ||
} else { | ||
database = getDatabase(databaseName); | ||
} | ||
if (!database) { | ||
throw new Error(`Database ${databaseName} not found`); | ||
} | ||
if (databaseName === 'cid') { | ||
if ( | ||
customDatabase.ionization && | ||
customDatabase.ionization[mode].length > 0 | ||
) { | ||
IonizationDb = customDatabase.ionization[mode]; | ||
} else { | ||
IonizationDb = getDatabase('')[mode]; | ||
} | ||
} | ||
let results = {}; | ||
const reactions = database[mode]; | ||
let fragments = applyReactions([molecule], reactions, { | ||
maxDepth, | ||
}); | ||
if (IonizationDb) { | ||
let ionizationFragments = applyReactions([molecule], IonizationDb, { | ||
maxDepth: maxIonizationDepth, | ||
}); | ||
let { masses, trees, products } = insertMfInfoFragments( | ||
fragments.trees, | ||
fragments.products, | ||
); | ||
for (let tree of ionizationFragments.trees) { | ||
getMoleculesToFragment(tree, reactions, maxDepth); | ||
} | ||
ionizationFragments.products = groupTreesByProducts( | ||
ionizationFragments.trees, | ||
); | ||
results = ionizationFragments; | ||
} else { | ||
results = applyReactions([molecule], reactions, { | ||
maxDepth, | ||
}); | ||
} | ||
let { masses, trees, products } = getMasses(results.trees, results.products); | ||
return { | ||
@@ -42,1 +82,19 @@ masses, | ||
} | ||
function getMoleculesToFragment(tree, reactions, maxDepth) { | ||
for (let product of tree.products) { | ||
if (product.children.length === 0) { | ||
if (product.charge !== 0) { | ||
let molecule = OCL.Molecule.fromIDCode(product.idCode); | ||
let fragments = applyReactions([molecule], reactions, { | ||
maxDepth, | ||
}); | ||
product.children = fragments.trees; | ||
} | ||
} else { | ||
for (let child of product.children) { | ||
getMoleculesToFragment(child, reactions, maxDepth); | ||
} | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
3248
779285
+ Added@lukeed/csprng@1.1.0(transitive)
+ Added@lukeed/uuid@2.0.1(transitive)
+ Addedopenchemlib-utils@5.21.1(transitive)
- Removedopenchemlib-utils@2.9.0(transitive)
Updatedopenchemlib-utils@^5.0.2