computeSimilarities

src/computeSimilarities.js

Test the similarity with predictions for many experiments and return data computed on the matchIndexes

computeSimilarities(experimentsPath: string, predictionsPath: string, options: object): Stats
Parameters
experimentsPath (string) path to the experiments JSON file
predictionsPath (string) path to the predictions JSON file
options (object = {})
Name Description
options.numExperiments number (default undefined) Number of experiments for which the similarity should be computed ( slice of the input experimental data). Should be undefined if all data must be used.
options.loadData object (default {})
options.loadData.mergeSpan number (default 0.05) How close consecutive x values of a spectrum must be to be merged
options.loadData.pathType string (default "relative") Allows to define wether the path to the JSON is "relative" or "absolute"
options.loadData.norm bool (default true) If true , the spectra data are normalized before merging too close x values.
options.numberMaxPeaks number (default undefined) If not undefined, defines the number of max. intensity peaks to keep. This removes some of the spectrum noise.
options.similarity object (default {})
options.similarity.algorithm function (default intersection) Algorithm used to calculate the similarity between the spectra. Default is cosine similarity.
options.similarity.alignDelta number (default 0.05) Two values of a experiment and prediction which difference is smaller than alignDelta will be put in the same X slot (considered as common).
options.similarity.minCommon number (default 6) Minimal number of values that must remain in the spectra after alignment.
options.similarity.norm bool (default false) If true , the spectra data are normalized before being sent to the similarity algorithm.
options.similarity.massWeight function (default defaultMassWeight) Function that weights a y value by a function of x.
options.bestMatch object (default {})
options.bestMatch.threshold number (default 0) Similarity threshold for predicted spectra to be returned
options.bestMatch.numberBestMatch number (default 10) Number of best matching predicted spectra to return in the result ( NaN to return all)
options.bestMatch.massFilter number (default 0.05) If defined, the predictions are filtered based on PEPMASS before computing any similarity. If the mass difference is over massFilter , similarity and common are set to 0.
Returns
Stats: Stats computed on the array of matchIndex
Data

Type: Array<Entry>

dataKeepMaxPeaks

src/loadData.js

Keeps options.numberMaxPeaks values of each spectrum with highest intensities

dataKeepMaxPeaks(spectra: Data, options: object): Data
Parameters
spectra (Data) Parsed json containing spectra to filter
options (object = {})
Name Description
options.numberMaxPeaks number (default 30) Number of peaks to keep
Returns
Data: Input data with spectra filtered

dataWeightedMergeX

src/loadData.js

Makes a weighted merge of the x values of each spectrum too close to each other using ml-array-xy-weighted-merge

dataWeightedMergeX(spectra: Data, options: object): Data
Parameters
spectra (Data) Parsed json containing spectra to merge
options (object = {})
Name Description
options.mergeSpan number (default 1) How close consecutive x values of a spectrum must be to be merged
Returns
Data: Input data with X values of spectra merged

defaultMassWeight

src/similarity.js

Default function used to weight the experimental and predicted spectra: y=y*x^3. The y values are a function of the x values.

defaultMassWeight(x: number, y: number): number
Parameters
x (number) x value
y (number) y value
Returns
number: weighted y value
Entry

Type: object

Properties
kind (string) : Kind of the entries of the data (in general: 'IONS')
meta (object) : Meta-information about the spectrum
data (Spectrum) : The spectrum data

findBestMatches

src/bestMatch.js

Returns a structure with the predicted spectra the most similar to an experimental spectrum

findBestMatches(experiment: Entry, predictions: Data, options: object, similarity: object): Result
Parameters
experiment (Entry) Experimental spectrum
predictions (Data) Predicted spectra database
options (object = {})
Name Description
options.massFilter number (default 0.05) If defined, the predictions are filtered based on PEPMASS before computing any similarity. If the mass difference is over massFilter , similarity and common are set to 0.
options.threshold number (default 0) Similarity threshold for predicted spectra to be returned
options.numberBestMatch number (default 10) Number of best matching predicted spectra to return in the result ( undefined to return all)
similarity (object = {})
Name Description
similarity.algorithm function (default intersection) Algorithm used to calculate the similarity between the spectra. Default is cosine similarity.
similarity.alignDelta number (default 0.05) Two values of a experiment and prediction which difference is smaller than alignDelta will be put in the same X slot (considered as common).
similarity.minCommon number (default 6) Minimal number of values that must remain in the spectra after alignment.
similarity.norm bool (default false) If true , the spectra data are normalized before being sent to the similarity algorithm.
similarity.massWeight function (default defaultMassWeight) Function that weights a y value by a function of x.
Returns
Result: Best matching predicted spectra and meta information

Loads, parses a JSON file. Then makes a weighted merge of the x values of each spectrum too close to each other using ml-array-xy-weighted-merge

loadData(path: string, options: object): Data
Parameters
path (string) Relative path to json file
options (object = {})
Name Description
options.numberMaxPeaks number (default 30) If not undefined, defines the number of max. intensity peaks to keep. This removes some of the spectrum noise.
options.mergeSpan number (default 0.05) How close consecutive x values of a spectrum must be to be merged
options.pathType string (default "relative") Allows to define wether the path to the JSON is "relative" or "absolute"
options.norm bool (default true) If true , the spectra data are normalized before merging too close x values.
Returns
Data: Data loaded, parsed and merged
Match

Type: Object

Properties
similarity (number) : The experiment data
prediction (Entry) : All predictions sorted by similarity with exp
correctMatch (bool) : Is true if prediction is the correct match of exp
Result

Type: Object

Properties
exp (Entry) : The experiment data
matches (array<Match>) : All predictions sorted by similarity with exp
matchIndex (number) : The index of the correct match for exp in matches. It is NaN if the similarity between the experiment and its correct match is zero.
common (number) : Number of values considered common between exp and its correct math by the align algorith
sufficientCommonCount (number) : Number of exp/pred couples that have sufficient common values after aligning (default less than 6)

Returns the similarity between two spectra

similarity(experiment: Entry, prediction: Entry, options: object): SimStats
Parameters
experiment (Entry) First spectrum
prediction (Entry) Second spectrum
options (object = {})
Name Description
options.algorithm function (default intersection) Algorithm used to calculate the similarity between the spectra. Default is cosine similarity.
options.alignDelta number (default 0.05) Two values of a experiment and prediction which difference is smaller than alignDelta will be put in the same X slot (considered as common).
options.minCommon number (default 6) Minimal number of values that must remain in the spectra after alignment.
options.norm bool (default false) If true , the spectra data are normalized before being sent to the similarity algorithm.
options.massWeight function (default defaultMassWeight) Function that weights a y value by a function of x.
Returns
SimStats: Information on the similarity between the 2 spectra
SimStats

Type: object

Properties
similarity (number) : similarity between the two spectra
common (number) : number of entries considered common by the align algorithm
Spectrum

Type: object

Properties
x (Array) : X entries of the spectrum
y (Array) : X entries of the spectrum
Stats

Type: object

Properties
mean (number) : Mean of the array
median (number) : Median of the array
min (number) : Min of the array
max (number) : Max of the array