mf-from-google-sheet
Advanced tools
Comparing version 3.1.0 to 3.1.1
{ | ||
"name": "mf-from-google-sheet", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"description": "Retrieve and format molecular formula from google sheet", | ||
"main": "lib/index.js", | ||
"main": "lib/src/index.js", | ||
"module": "src/index.js", | ||
@@ -23,9 +23,8 @@ "files": [ | ||
"dependencies": { | ||
"cross-fetch": "^4.0.0", | ||
"mf-generator": "^3.3.0", | ||
"mf-parser": "^3.2.0", | ||
"mf-utilities": "^3.2.0", | ||
"mf-generator": "^3.3.1", | ||
"mf-parser": "^3.2.1", | ||
"mf-utilities": "^3.2.1", | ||
"papaparse": "^5.4.1" | ||
}, | ||
"gitHead": "28dae91d3b42556a23097ee08acfe4061f276ed0" | ||
"gitHead": "838f98a30846d4b1721b8ed7aa94a55e854d7521" | ||
} |
159
src/index.js
@@ -17,97 +17,96 @@ import { generateMFs } from 'mf-generator'; | ||
} | ||
} | ||
async function parse(tsv, tsvReferences) { | ||
let parsed = Papa.parse(tsv, { | ||
async function parse(tsv, tsvReferences) { | ||
let parsed = Papa.parse(tsv, { | ||
delimiter: '\t', | ||
header: true, | ||
}); | ||
let fields = parsed.meta.fields; | ||
let infoFields = fields.filter( | ||
(a) => !['mf', 'modif', 'ESI', 'MALDI', 'positive', 'negative'].includes(a), | ||
); | ||
let formulas = parsed.data; | ||
let references = {}; | ||
if (tsvReferences) { | ||
let referencesArray = Papa.parse(tsvReferences, { | ||
delimiter: '\t', | ||
header: true, | ||
}); | ||
let fields = parsed.meta.fields; | ||
let infoFields = fields.filter( | ||
(a) => | ||
!['mf', 'modif', 'ESI', 'MALDI', 'positive', 'negative'].includes(a), | ||
); | ||
let formulas = parsed.data; | ||
let references = {}; | ||
if (tsvReferences) { | ||
let referencesArray = Papa.parse(tsvReferences, { | ||
delimiter: '\t', | ||
header: true, | ||
}).data; | ||
}).data; | ||
referencesArray.forEach((r) => { | ||
references[r.label] = r; | ||
}); | ||
for (const r of referencesArray) { | ||
references[r.label] = r; | ||
} | ||
} | ||
let results = []; | ||
for (let formula of formulas) { | ||
if (tsvReferences) { | ||
// we add references | ||
let refs = formula.references.split(/[ ,]+/); | ||
formula.references = []; | ||
for (let ref of refs) { | ||
formula.references.push(references[ref]); | ||
} | ||
let results = []; | ||
for (let formula of formulas) { | ||
if (tsvReferences) { | ||
// we add references | ||
let refs = formula.references.split(/[ ,]+/); | ||
formula.references = []; | ||
for (let ref of refs) { | ||
formula.references.push(references[ref]); | ||
} | ||
// we need to calculate all the possibilities | ||
try { | ||
let mfs = await generateMFs([formula.mf], { | ||
ionizations: formula.modif, | ||
}); | ||
for (let mf of mfs) { | ||
mf.info = {}; | ||
for (let infoField of infoFields) { | ||
mf.info[infoField] = formula[infoField]; | ||
} | ||
if ( | ||
!formula.ESI && | ||
!formula.MALDI && | ||
!formula.positive && | ||
!formula.negative | ||
) { | ||
mf.filter = { | ||
ESI: true, | ||
MALDI: true, | ||
positive: true, | ||
negative: true, | ||
}; | ||
} else { | ||
mf.filter = { | ||
ESI: formula.ESI === 'X', | ||
MALDI: formula.MALDI === 'X', | ||
positive: formula.positive === 'X', | ||
negative: formula.negative === 'X', | ||
}; | ||
} | ||
mf.mf = new MF(mf.mf).toMF(); | ||
results.push(mf); | ||
} | ||
// we need to calculate all the possibilities | ||
try { | ||
let mfs = await generateMFs([formula.mf], { | ||
ionizations: formula.modif, | ||
}); | ||
for (let mf of mfs) { | ||
mf.info = {}; | ||
for (let infoField of infoFields) { | ||
mf.info[infoField] = formula[infoField]; | ||
} | ||
} catch (e) { | ||
// eslint-disable-next-line no-console | ||
console.warn( | ||
'Non parsable molecular formula: ', | ||
formula.mf, | ||
formula.modif, | ||
e.toString(), | ||
); | ||
if ( | ||
!formula.ESI && | ||
!formula.MALDI && | ||
!formula.positive && | ||
!formula.negative | ||
) { | ||
mf.filter = { | ||
ESI: true, | ||
MALDI: true, | ||
positive: true, | ||
negative: true, | ||
}; | ||
} else { | ||
mf.filter = { | ||
ESI: formula.ESI === 'X', | ||
MALDI: formula.MALDI === 'X', | ||
positive: formula.positive === 'X', | ||
negative: formula.negative === 'X', | ||
}; | ||
} | ||
mf.mf = new MF(mf.mf).toMF(); | ||
results.push(mf); | ||
} | ||
} catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.warn( | ||
'Non parsable molecular formula:', | ||
formula.mf, | ||
formula.modif, | ||
error.toString(), | ||
); | ||
} | ||
} | ||
results = results.filter((a) => { | ||
return a.ms.em !== 0; | ||
}); | ||
results = results.filter((a) => { | ||
return a.ms.em !== 0; | ||
}); | ||
results.sort((a, b) => { | ||
return a.ms.em - b.ms.em; | ||
}); | ||
results.sort((a, b) => { | ||
return a.ms.em - b.ms.em; | ||
}); | ||
let uniqueResults = [results[0]]; | ||
for (let i = 1; i < results.length; i++) { | ||
if (results[i - 1].ms.em !== results[i].ms.em) { | ||
uniqueResults.push(results[i]); | ||
} | ||
let uniqueResults = [results[0]]; | ||
for (let i = 1; i < results.length; i++) { | ||
if (results[i - 1].ms.em !== results[i].ms.em) { | ||
uniqueResults.push(results[i]); | ||
} | ||
} | ||
return uniqueResults; | ||
} | ||
return uniqueResults; | ||
} |
@@ -1,5 +0,3 @@ | ||
import crossFetch from 'cross-fetch'; | ||
export async function fetchText(url) { | ||
const result = await crossFetch(url); | ||
const result = await fetch(url); | ||
if (result.status !== 200) { | ||
@@ -6,0 +4,0 @@ throw new Error(String(result.status)); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
40202
4
10
221
4
- Removedcross-fetch@^4.0.0
- Removedcross-fetch@4.1.0(transitive)
- Removednode-fetch@2.7.0(transitive)
- Removedtr46@0.0.3(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)
Updatedmf-generator@^3.3.1
Updatedmf-parser@^3.2.1
Updatedmf-utilities@^3.2.1