Skip to content

Commit

Permalink
refactor: change variables and functions names
Browse files Browse the repository at this point in the history
Change nmrPeakDetection by getRanges
Change nmrPeakDetection2D by getZones

Change variables names from signals to ranges or zones to make the code more comprensible. #7
  • Loading branch information
andcastillo committed Nov 17, 2016
1 parent ef31fd4 commit d0ad3a4
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 36 deletions.
8 changes: 4 additions & 4 deletions dist/spectra-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -4700,7 +4700,7 @@ return /******/ (function(modules) { // webpackBootstrap


/**
* @function nmrPeakDetection(parameters);
* @function getRanges(parameters);
* This function process the given spectraData and tries to determine the NMR signals. Returns an NMRSignal1D array containing all the detected 1D-NMR Signals
* @param parameters A JSONObject containing the optional parameters:
* @option fromX: Lower limit.
Expand All @@ -4709,7 +4709,7 @@ return /******/ (function(modules) { // webpackBootstrap
* @option stdev: Number of standard deviation of the noise for the threshold calculation if a threshold is not specified.
* @returns {*}
*/
NMR.prototype.nmrPeakDetection=function(parameters) {
NMR.prototype.getRanges=function(parameters) {
return peakPicking(this, parameters);
}

Expand Down Expand Up @@ -16379,14 +16379,14 @@ return /******/ (function(modules) { // webpackBootstrap
}

/**
* @function nmrPeakDetection2D(options)
* @function getZones(options)
* This function process the given spectraData and tries to determine the NMR signals.
+ Returns an NMRSignal2D array containing all the detected 2D-NMR Signals
* @param options:+Object Object containing the options
* @option thresholdFactor:number A factor to scale the automatically determined noise threshold.
* @returns [*] set of NMRSignal2D
*/
NMR2D.prototype.nmrPeakDetection2D=function(options){
NMR2D.prototype.getZones=function(options){
options = options||{};
if(!options.thresholdFactor)
options.thresholdFactor=1;
Expand Down
2 changes: 1 addition & 1 deletion examples/main1D.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ for (var i = 0; i < xy[0].length; i++) {
if (true) {
var d = new Date();
var n = d.getTime();
var peakPicking = spectrum.nmrPeakDetection({nH: 10, realTop: true, thresholdFactor: 1, clean: true, compile: true,
var peakPicking = spectrum.getRanges({nH: 10, realTop: true, thresholdFactor: 1, clean: true, compile: true,
gsdOptions: {minMaxRatio: 0.03, broadRatio: 0.0025, smoothY: true, nL: 4}
});
d = new Date();
Expand Down
4 changes: 2 additions & 2 deletions src/NMR.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ class NMR extends SD {


/**
* @function nmrPeakDetection(parameters);
* @function getRanges(parameters);
* This function process the given spectraData and tries to determine the NMR signals. Returns an NMRSignal1D array containing all the detected 1D-NMR Signals
* @param parameters A JSONObject containing the optional parameters:
* @option fromX: Lower limit.
Expand All @@ -352,7 +352,7 @@ class NMR extends SD {
* @option stdev: Number of standard deviation of the noise for the threshold calculation if a threshold is not specified.
* @returns {*}
*/
nmrPeakDetection(parameters) {
getRanges(parameters) {
return peakPicking(this, parameters);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/NMR2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ class NMR2D extends SD {
}

/**
* @function nmrPeakDetection2D(options)
* @function getZones(options)
* This function process the given spectraData and tries to determine the NMR signals.
+ Returns an NMRSignal2D array containing all the detected 2D-NMR Signals
* @param options:+Object Object containing the options
* @option thresholdFactor:number A factor to scale the automatically determined noise threshold.
* @returns [*] set of NMRSignal2D
*/
nmrPeakDetection2D(options) {
getZones(options) {
options = options || {};
if (!options.thresholdFactor) {
options.thresholdFactor = 1;
Expand All @@ -164,10 +164,10 @@ class NMR2D extends SD {
}

if (options.format === 'new') {
var newSignals = new Array(peakList.length);
var zones = new Array(peakList.length);
for (var k = peakList.length - 1; k >= 0; k--) {
var signal = peakList[k];
newSignals[k] = {
zones[k] = {
fromTo: signal.fromTo,
integral: signal.intensity || 1,
remark: '',
Expand All @@ -179,7 +179,7 @@ class NMR2D extends SD {
signalID: signal.signalID,
};
}
peakList = newSignals;
peakList = zones;
}


Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/NMR.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ describe('spectra-data examples ethylvinylether/1h.jdx', function () {
});

it('Check peak-picking in the new format', function () {
var peakPicking = spectrum.nmrPeakDetection({'nH': 8, realTop: true, thresholdFactor: 1, clean: true, compile: true, idPrefix: '1H', format: 'new'});
var peakPicking = spectrum.getRanges({'nH': 8, realTop: true, thresholdFactor: 1, clean: true, compile: true, idPrefix: '1H', format: 'new'});
//console.log(peakPicking[0]);
peakPicking[0].signal[0].peak.length.should.equal(4);
});

it('Check peak-picking in zone', function () {
var peakPicking = spectrum.nmrPeakDetection({'nH': 8, realTop: true, thresholdFactor: 1, clean: true, compile: true, idPrefix: '1H', format: 'new', from: 1, to: 2});
var peakPicking = spectrum.getRanges({'nH': 8, realTop: true, thresholdFactor: 1, clean: true, compile: true, idPrefix: '1H', format: 'new', from: 1, to: 2});
//console.log(peakPicking[0]);
peakPicking.length.should.eql(1);
peakPicking[0].signal[0].multiplicity.should.eql('t');
Expand All @@ -86,7 +86,7 @@ describe('spectra-data examples ethylvinylether/1h.jdx', function () {

it('updateIntegrals', function () {
var nH = 8;
var ranges = spectrum.nmrPeakDetection({'nH': nH, realTop: true, thresholdFactor: 1, clean: true, compile: true, idPrefix: '1H', format: 'new'});
var ranges = spectrum.getRanges({'nH': nH, realTop: true, thresholdFactor: 1, clean: true, compile: true, idPrefix: '1H', format: 'new'});
ranges[0].to = 6.47;
var integral0 = ranges[0].integral;
spectrum.updateIntegrals(ranges, {nH: nH});
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/NMR2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('spectra-data examples indometacin/hmbc.dx', function () {
});

it('Peak picking 2D', function () {
var signals2D = spectrum.nmrPeakDetection2D(
var signals2D = spectrum.getZones(
{'thresholdFactor': 1,
'idPrefix': 'hmbc_',
'format': 'new'
Expand Down
16 changes: 8 additions & 8 deletions src/peakPicking/PeakPicking.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ module.exports = function (spectrum, optionsEx) {
for (j = peaksO.length - 1; j >= 0; j--) {
peaks1.push(peaksO[j]);
}
let newSignals = detectSignals(peaks1, spectrum, nHi, options.integralFn, options.frequencyCluster);
let ranges = detectSignals(peaks1, spectrum, nHi, options.integralFn, options.frequencyCluster);

for (j = 0; j < newSignals.length; j++) {
signals.push(newSignals[j]);
for (j = 0; j < ranges.length; j++) {
signals.push(ranges[j]);
}
}
}
Expand Down Expand Up @@ -137,10 +137,10 @@ module.exports = function (spectrum, optionsEx) {
//removeImpurities(signals, spectrum.getSolventName(),options.nH);

if (options.format === 'new') {
let newSignals = new Array(signals.length);
let ranges = new Array(signals.length);
for (i = 0; i < signals.length; i++) {
var signal = signals[i];
newSignals[i] = {
ranges[i] = {
from: signal.integralData.from,
to: signal.integralData.to,
integral: signal.integralData.value,
Expand All @@ -157,13 +157,13 @@ module.exports = function (spectrum, optionsEx) {

};
if (signal.nmrJs) {
newSignals[i].signal[0].j = signal.nmrJs;
ranges[i].signal[0].j = signal.nmrJs;
}
if (!signal.asymmetric || signal.multiplicity === 'm') {
newSignals[i].signal[0].delta = signal.delta1;
ranges[i].signal[0].delta = signal.delta1;
}
}
signals = newSignals;
signals = ranges;
}

return signals;
Expand Down
6 changes: 3 additions & 3 deletions src/peakPicking/__tests__/ImpurityRemover.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ function createSpectraData(filename, label, data) {
}


describe('spectra-data examples nmrPeakDetection', function () {
describe('spectra-data examples getRanges', function () {
it.skip('number of peaks', function () {
var spectrum = createSpectraData('/../../../data-test/indometacin/1h.dx');
//console.log(spectrum.nmrPeakDetection);
var peakPicking = spectrum.nmrPeakDetection({
//console.log(spectrum.getRanges);
var peakPicking = spectrum.getRanges({
'nH': 16,
realTop: true,
thresholdFactor: 1,
Expand Down
4 changes: 2 additions & 2 deletions src/peakPicking/__tests__/ranges2ACS.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function createSpectraData(filename, label, data) {

describe('spectra-data examples peak picking in ACS format', function () {
var spectrum = createSpectraData('/../../../data-test/ethylbenzene/h1_0.jdx');
var peakPicking = spectrum.nmrPeakDetection({'nH': 10, realTop: true, thresholdFactor: 0.8, clean: true, compile: true});
var peakPicking2 = spectrum.nmrPeakDetection({'nH': 10, realTop: true, thresholdFactor: 0.8, clean: true, compile: true, format: 'new'});
var peakPicking = spectrum.getRanges({'nH': 10, realTop: true, thresholdFactor: 0.8, clean: true, compile: true});
var peakPicking2 = spectrum.getRanges({'nH': 10, realTop: true, thresholdFactor: 0.8, clean: true, compile: true, format: 'new'});
it('format ACS', function () {
var acs = Data.formatter.toACS(peakPicking, {rangeForMultiplet: true});
acs.should.equal('<sup>1</sup>H NMR (400 MHz) δ 7.26-7.32 (m, 2 H), 7.15-7.23 (m, 3 H), 2.60 (q, 2 H, <i>J</i> = 7.6 Hz), 1.19 (t, 3 H, <i>J</i> = 7.6 Hz).');
Expand Down
2 changes: 1 addition & 1 deletion src/peakPicking/__tests__/rangesWithJCouplings.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function createSpectraData(filename, label, data) {
describe('spectra-data examples peak picking', function () {
var nH = 8;
var spectrum = createSpectraData('/../../../data-test/ethylvinylether/1h.jdx');
var peakPicking = spectrum.nmrPeakDetection({'nH': nH, realTop: true, thresholdFactor: 1, clean: true, compile: true, idPrefix: '1H'});
var peakPicking = spectrum.getRanges({'nH': nH, realTop: true, thresholdFactor: 1, clean: true, compile: true, idPrefix: '1H'});
//console.log(Data.ACS.formater.toACS(peakPicking,{solvent:spectrum.getSolventName()}));
//console.log(peakPicking);
it('Known patterns for ethylvinylether', function () {
Expand Down
12 changes: 6 additions & 6 deletions src/visualizer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
var options1D = {type: 'rect', line: 0, lineLabel: 1, labelColor: 'red', strokeColor: 'red', strokeWidth: '1px', fillColor: 'green', width: 0.05, height: 10, toFixed: 1};
var options2D = {type: 'rect', labelColor: 'red', strokeColor: 'red', strokeWidth: '1px', fillColor: 'green', width: '6px', height: '6px'};

function annotations1D(signals, optionsG) {
function annotations1D(ranges, optionsG) {
var options = Object.assign({}, options1D, optionsG);
var height = options.height;
var annotations = [];
for (var i = 0; i < signals.length; i++) {
var prediction = signals[i];
for (var i = 0; i < ranges.length; i++) {
var prediction = ranges[i];
var annotation = {};

annotations.push(annotation);
Expand Down Expand Up @@ -59,11 +59,11 @@ function annotations1D(signals, optionsG) {
return annotations;
}

function annotations2D(signals2D, optionsG) {
function annotations2D(zones, optionsG) {
var options = Object.assign({}, options2D, optionsG);
var annotations = [];
for (var k = signals2D.length - 1; k >= 0; k--) {
var signal = signals2D[k];
for (var k = zones.length - 1; k >= 0; k--) {
var signal = zones[k];
var annotation = {};
annotation.type = options.type;
annotation._highlight = signal._highlight;//["cosy"+k];
Expand Down

0 comments on commit d0ad3a4

Please sign in to comment.