Skip to content

Commit

Permalink
allow cache for calculateForMF and calculateForMass
Browse files Browse the repository at this point in the history
  • Loading branch information
lpatiny committed Sep 5, 2018
1 parent 6fc57eb commit f6fe004
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Chromatogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,19 @@ export class Chromatogram {
* @param {number} targetMass - mass for which to extract the spectrum
* @param {object} [options = {}] - Options object
* @param {string} [options.serieName='ms'+targetMass] - Name of the serie to make calculation
* @param {boolean} [options.cache = false] - Retrieve from cache if exists
* @param {boolean} [options.force = false] - Force replacement of existing serie
* @param {number} [options.error=0.5] - Allowed error around the targetMass
*/
calculateForMass(targetMass, options = {}) {
const { serieName = `ms${targetMass}-${options.error || 0.5}` } = options;
const {
serieName = `ms${targetMass}-${options.error || 0.5}`,
cache = false
} = options;
if (cache && this.hasSerie(serieName)) return this.getSerie(serieName);
let result = calculateForMass(this, targetMass, options);
this.addSerie(serieName, result, options);
return this.getSerie(serieName);
}

/**
Expand All @@ -242,16 +248,20 @@ export class Chromatogram {
* @param {object} [options = {}] - Options object
* @param {string} [options.serieName='ms'+targetMass] - Name of the serie to make calculation
* @param {boolean} [options.force = false] - Force replacement of existing serie
* @param {boolean} [options.cache = false] - Retrieve from cache if exists
* @param {number} [options.error=0.5] - Allowed error around the targetMass
* @param {number} [options.ionizations='H+'] - List of allowed ionisation
*/
calculateForMF(targetMF, options = {}) {
const {
serieName = `ms${targetMF}-${options.ionizations ||
'H+'}-${options.error || 0.5}`
'H+'}-${options.error || 0.5}`,
cache = false
} = options;
if (cache && this.hasSerie(serieName)) return this.getSerie(serieName);
let result = calculateForMF(this, targetMF, options);
this.addSerie(serieName, result, options);
return this.getSerie(serieName);
}

/**
Expand Down

0 comments on commit f6fe004

Please sign in to comment.