Spectrum

Class dealing with mass spectra and peak picking

new Spectrum(data: any, options: object)
Parameters
data (any = defaultData)
options (object = {})
Instance Members
peaks
getSelectedPeaksWithCharge(selectedPeaks, options)
getFragmentPeaksFct(mf, options)
getMassRemainderFct(mass, options)

getFragmentPeaks

Filter the array of peaks

getFragmentPeaks(peaks: array, mf: string, options: object): array
Parameters
peaks (array) array of all the peaks
mf (string) Molecular formula of the parent molecule
options (object = {})
Name Description
options.from number? min X value of the window to consider
options.to number? max X value of the window to consider
options.threshold number (default 0.01) minimal intensity compare to base peak
options.limit number (default undefined) maximal number of peaks (based on intensity)
options.ionizations string?
options.precision number?
Returns
array: copy of peaks with 'close' annotation

getMassRemainder

Remove an integer number of time the specifiedd monoisotopic mass Mass remainder analysis (MARA): https://doi.org/10.1021/acs.analchem.7b04730

getMassRemainder(spectrum: object, mass: number, options: any, object: any)
Parameters
spectrum (object)
mass (number)
options (any = {})
object (any)

NEUTRON_MASS

NEUTRON_MASS

Type: number

Parameters
options (object = {})
Name Description
options.minCharge number (default 1)
options.maxCharge number (default 10)
options.similarity object (default {})
options.similarity.widthBottom number?
options.similarity.widthTop number?
options.similarity.widthFunction object? function called with mass that should return an object width containing top and bottom
options.similarity.zone object (default {})
options.similarity.zone.low number (default -0.5) window shift based on observed monoisotopic mass
options.similarity.zone.high number (default 2.5) to value for the comparison window
options.similarity.common string?

getPeaksWithCharge

getPeaksWithCharge(selectedPeaks: Array, allPeaks: Array, options: object)
Parameters
selectedPeaks (Array)
allPeaks (Array)
options (object = {})
Name Description
options.min number (default 1)
options.max number (default 10)
options.low number (default -1)
options.high number (default 1)
options.precision number (default 30)

isContinuous

When a spectrum is continous ?

  • has more than 100 points
  • deltaX change can not be more than a factor 2
  • deltaX may not be larger than 0.1
  • if y is zero it does not count
isContinuous(spectrum: object, options: object)
Parameters
spectrum (object)
options (object = {})
Name Description
options.minLength number (default 100)
options.relativeHeightThreshold number (default 0.001) // Under this value the
options.maxDeltaRatio number (default 3)

peakPicking

Filter the array of peaks

peakPicking(spectrum: any): array
Parameters
spectrum (any)
Returns
array:

getPeaks

Filter the array of peaks

getPeaks(peaks: array, options: object): array
Parameters
peaks (array) array of all the peaks
options (object = {})
Name Description
options.from number? min X value of the window to consider
options.to number? max X value of the window to consider
options.threshold number (default 0.01) minimal intensity compare to base peak
options.limit number (default undefined) maximal number of peaks (based on intensity)
options.sumValue number? // if sumValue is defined, maxValue is ignored
Returns
array: copy of peaks with 'close' annotation

getBestPeaks

Filter the array by taking the higher peaks and only keep one per slot. There are 2 different slots, the smallest one will have the extra annotation close to true

getBestPeaks(peaks: array, options: object): array
Parameters
peaks (array) array of all the peaks
options (object = {})
Name Description
options.from number? min X value of the window to consider
options.to number? max X value of the window to consider
options.searchMonoisotopicRatio number (default 0) search previous peaks with at least ratio height
options.limit number (default 20) max number of peaks
options.threshold number (default 0.01) minimal intensity compare to base peak
options.numberSlots number (default 10) define the number of slots and indirectly the slot width
options.numberCloseSlots number (default 50)
Returns
array: copy of peaks with 'close' annotation

constructor

Create a class that will be able to get the similarity between 2 spectra The similarity is based on 'cosine' similarity. The goal is 2 prepare 2 vectors on which the similarity is calculated. The vectors are created by taking the mass and the intensity of the peaks.

constructor(options: object)
Parameters
options (object = {})
Name Description
options.nbPeaks number? Before comparing spectra how many peaks should be kept
options.minNbCommonPeaks number? Minimum number of peaks in common to consider any similarity
options.minIntensity number? What is the minimal relative intensity to keep a peak
options.massPower number (default 3) High power will give more weight to the mass. If you would prefer to observe fragments you should use a number less than 1
options.intensityPower number (default 0.6) How important is the intensity. By default we don't give to much importance to it
options.selectedMasses Array<number>? List of allowed masses.
options.delta (number | Function) (default 0.1) Tolerance in Da (u) to consider 2 peaks as aligned. If a function is provided it will be called with the mass of the peak

getSimilarityToMasses

Get the similarity between a spectrum and a list of masses. The main issue is that we don't have the intensity of the peaks. So we will use the intensity of the closest peak.

getSimilarityToMasses(dataXY: any, masses: Array<number>)
Parameters
dataXY (any)
masses (Array<number>)

getSimilarity

getSimilarity(dataXY1: any, dataXY2: any)
Parameters
dataXY1 (any)
dataXY2 (any)

normalizeAndCacheData

normalizeAndCacheData(cache: WeakMap, dataXY: any, options: object)
Parameters
cache (WeakMap)
dataXY (any)
options (object = {})
Name Description
options.nbPeaks number?
options.minIntensity number?

returnSimilarity

returnSimilarity(aligned: any, options: object)
Parameters
aligned (any)
options (object = {})
Name Description
options.massPower number?
options.intensityPower number?
options.minNbCommonPeaks number?

cosineSimilarity

Returns the average of cosine distances between vectors a and b Copied from https://github.com/mljs/distance/blob/0b15acd6476413f4111cb4852ca1bec9edaa2805/src/similarities/cosine.ts

cosineSimilarity(a: any, b: any): number
Parameters
a (any) {import('cheminfo-types').NumberArray} - first vector
b (any) {import('cheminfo-types').NumberArray} - second vector
Returns
number: cosine similarity

getPeaksAnnotation

getPeaksAnnotation(bestPeaks: array, options: object): Promise
Parameters
bestPeaks (array)
options (object = {})
Name Description
options.numberDigits number (default 5)
options.numberMFs number (default 0)
options.showMF boolean (default false)
options.mfColors array (default {})
options.charge number (default 1)
options.shift number (default 0)
options.mfPrefs object?
options.displayCharge number (default true)
options.displayProperties number (default []) Array of properties name to display
Returns
Promise: