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

mf-from-google-sheet

Package Overview
Dependencies
Maintainers
1
Versions
94
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mf-from-google-sheet - npm Package Compare versions

Comparing version 0.9.1 to 0.12.0

11

package.json

@@ -6,3 +6,3 @@ {

},
"version": "0.9.1",
"version": "0.12.0",
"description": "Retrieve and format molecular formula from google sheet",

@@ -25,9 +25,10 @@ "main": "src/index.js",

"dependencies": {
"mf-generator": "^0.9.1",
"mf-parser": "^0.9.1",
"mf-utilities": "^0.9.1",
"mf-generator": "^0.12.0",
"mf-parser": "^0.12.0",
"mf-utilities": "^0.12.0",
"papaparse": "^4.3.6",
"request": "^2.83.0",
"request-promise-native": "^1.0.5"
}
},
"gitHead": "aa2e6571c5f7121dda616b7d6920b7a653a8f9c7"
}
'use strict';
var mfFromGoogleSheet = require('..');
let mfFromGoogleSheet = require('..');
// The original document is on: https://docs.google.com/spreadsheets/d/15Kuc5MeOhvm4oeTMvEuP1rWdRFiVWosxXhYwAmuf3Uo/edit#gid=0
test('Test getReferenceList with existing', async () => {
var result = await mfFromGoogleSheet(
let result = await mfFromGoogleSheet(
'https://googledocs.cheminfo.org/spreadsheets/d/15Kuc5MeOhvm4oeTMvEuP1rWdRFiVWosxXhYwAmuf3Uo/export?format=tsv'

@@ -17,3 +17,4 @@ );

test('Test getReferenceList with non existing document', () => {
expect(
// eslint-disable-next-line jest/no-test-return-statement
return expect(
mfFromGoogleSheet(

@@ -20,0 +21,0 @@ 'https://googledocs.cheminfo.org/spreadsheets/d/15Kuc5MeOhvm4xxxVWosxXhYwAmuf3Uo/export?format=tsv'

'use strict';
var Papa = require('papaparse');
var generateMFs = require('mf-generator');
var MF = require('mf-parser/src/MF');
let Papa = require('papaparse');
let generateMFs = require('mf-generator');
let MF = require('mf-parser/src/MF');

@@ -10,11 +10,6 @@ const fetchText = require('./util/fetchText');

async function mfFromGoogleSheet(url, options = {}) {
let {
urlReferences
} = options;
let { urlReferences } = options;
if (urlReferences) {
let results = await Promise.all([
fetchText(url),
fetchText(urlReferences)
]);
let results = await Promise.all([fetchText(url), fetchText(urlReferences)]);
return parse(results[0], results[1]);

@@ -27,39 +22,33 @@ } else {

function parse(tsv, tsvReferences) {
var parsed = Papa.parse(tsv,
{
delimiter: '\t',
header: true
}
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),
);
var fields = parsed.meta.fields;
var infoFields = fields.filter((a) => !['mf', 'modif', 'ESI', 'MALDI', 'positive', 'negative'].includes(a));
var formulas = parsed.data;
let formulas = parsed.data;
if (tsvReferences) {
var referencesArray = Papa.parse(tsvReferences,
{
delimiter: '\t',
header: true
}
).data;
let referencesArray = Papa.parse(tsvReferences, {
delimiter: '\t',
header: true,
}).data;
var references = {};
referencesArray.forEach(
function (r) {
references[r.label] = r;
}
);
referencesArray.forEach(function (r) {
references[r.label] = r;
});
}
var results = [];
for (var formula of formulas) {
let results = [];
for (let formula of formulas) {
if (tsvReferences) {
// we add references
var refs = formula.references.split(/[ ,]+/);
let refs = formula.references.split(/[ ,]+/);
formula.references = [];
for (let ref of refs) {
formula.references.push(
references[ref]
);
formula.references.push(references[ref]);
}

@@ -69,4 +58,4 @@ }

try {
var mfs = generateMFs([formula.mf], { ionizations: formula.modif });
for (var mf of mfs) {
let mfs = generateMFs([formula.mf], { ionizations: formula.modif });
for (let mf of mfs) {
mf.info = {};

@@ -76,3 +65,8 @@ for (let infoField of infoFields) {

}
if (!formula.ESI && !formula.MALDI && !formula.positive && !formula.negative) {
if (
!formula.ESI &&
!formula.MALDI &&
!formula.positive &&
!formula.negative
) {
mf.filter = {

@@ -82,3 +76,3 @@ ESI: true,

positive: true,
negative: true
negative: true,
};

@@ -90,6 +84,6 @@ } else {

positive: formula.positive === 'X' ? true : false,
negative: formula.negative === 'X' ? true : false
negative: formula.negative === 'X' ? true : false,
};
}
mf.mf = (new MF(mf.mf)).toMF();
mf.mf = new MF(mf.mf).toMF();
results.push(mf);

@@ -99,3 +93,8 @@ }

// eslint-disable-next-line no-console
console.warn('Non parsable molecular formula: ', formula.mf, formula.modif, e.toString());
console.warn(
'Non parsable molecular formula: ',
formula.mf,
formula.modif,
e.toString(),
);
}

@@ -112,5 +111,4 @@ }

var uniqueResults = [results[0]];
for (var i = 1; i < results.length; i++) {
let uniqueResults = [results[0]];
for (let i = 1; i < results.length; i++) {
if (results[i - 1].ms.em !== results[i].ms.em) {

@@ -126,2 +124,1 @@ uniqueResults.push(results[i]);

module.exports = mfFromGoogleSheet;
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