Skip to content

Commit 3277314

Browse files
committed
cheminfo-tools version up to 1.3
1 parent fc4b867 commit 3277314

File tree

4 files changed

+75
-90
lines changed

4 files changed

+75
-90
lines changed

dist/ml-gsd.js

Lines changed: 72 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -4859,7 +4859,7 @@ return /******/ (function(modules) { // webpackBootstrap
48594859
};
48604860

48614861

4862-
function gsd(x, y, options){
4862+
function gsd(x, yIn, options){
48634863
//options = extend({}, defaultOptions, options);
48644864
var options=Object.create(options || {});
48654865
if (options.minMaxRatio===undefined) options.minMaxRatio=0.00025;
@@ -4871,152 +4871,143 @@ return /******/ (function(modules) { // webpackBootstrap
48714871
if (options.realTopDetection===undefined) options.realTopDetection=false;
48724872

48734873
var sgOptions = extend({}, sgDefOptions, options.sgOptions);
4874+
const y = [].concat(yIn);
48744875

4875-
//console.log(JSON.stringify(stats.array.minMax(y)));
4876-
if(options.noiseLevel===undefined){
4876+
var i, j, k;
4877+
4878+
if(options.noiseLevel === undefined){
48774879
//We have to know if x is equally spaced
4878-
var maxDx=0, minDx=Number.MAX_VALUE,tmp;
4879-
for(var i=0;i< x.length-1;i++){
4880-
var tmp = Math.abs(x[i+1]-x[i]);
4881-
if(tmp<minDx){
4880+
var maxDx = 0, minDx = Number.MAX_VALUE, tmp;
4881+
for(i = 0;i < x.length - 1; i++) {
4882+
tmp = Math.abs(x[i+1] - x[i]);
4883+
if(tmp < minDx) {
48824884
minDx = tmp;
48834885
}
4884-
if(tmp>maxDx){
4886+
if(tmp > maxDx) {
48854887
maxDx = tmp;
48864888
}
48874889
}
48884890

4889-
if((maxDx-minDx)/maxDx<0.05){
4890-
4891+
if((maxDx-minDx)/maxDx < 0.05) {
48914892
options.noiseLevel = getNoiseLevel(y);
4892-
//console.log(options.noiseLevel+" "+stats.array.median(y));
48934893
}
4894-
else{
4894+
else {
48954895
options.noiseLevel = 0;
48964896
}
48974897
}
4898-
//console.log("options.noiseLevel "+options.noiseLevel);
4899-
y=[].concat(y);
4900-
var yCorrection = {m:1, b:options.noiseLevel};
4901-
if(!options.maxCriteria){
4898+
const yCorrection = {m:1, b:options.noiseLevel};
4899+
if(!options.maxCriteria) {
49024900
yCorrection.m =-1;
49034901
yCorrection.b*=-1;
49044902
}
49054903

4906-
for (var i=0; i<y.length; i++){
4907-
y[i]=yCorrection.m*y[i]-yCorrection.b;
4904+
for (i = 0; i < y.length; i++) {
4905+
y[i] = yCorrection.m*y[i]-yCorrection.b;
49084906
}
49094907

4910-
for (var i=0; i<y.length; i++) {
4908+
for (i = 0; i < y.length; i++) {
49114909
if (y[i] < 0) {
49124910
y[i] = 0;
49134911
}
49144912
}
4915-
49164913
//If the max difference between delta x is less than 5%, then, we can assume it to be equally spaced variable
49174914
var Y = y;
4918-
if((maxDx-minDx)/maxDx<0.05){
4915+
var dY, ddY;
4916+
if((maxDx-minDx)/maxDx < 0.05) {
49194917
if(options.smoothY)
49204918
Y = SG(y, x[1]-x[0], {windowSize:sgOptions.windowSize, polynomial:sgOptions.polynomial,derivative:0});
4921-
var dY = SG(y, x[1]-x[0], {windowSize:sgOptions.windowSize, polynomial:sgOptions.polynomial,derivative:1});
4922-
var ddY = SG(y, x[1]-x[0], {windowSize:sgOptions.windowSize, polynomial:sgOptions.polynomial,derivative:2});
4919+
dY = SG(y, x[1]-x[0], {windowSize:sgOptions.windowSize, polynomial:sgOptions.polynomial,derivative:1});
4920+
ddY = SG(y, x[1]-x[0], {windowSize:sgOptions.windowSize, polynomial:sgOptions.polynomial,derivative:2});
49234921
}
4924-
else{
4922+
else {
49254923
if(options.smoothY)
49264924
Y = SG(y, x, {windowSize:sgOptions.windowSize, polynomial:sgOptions.polynomial,derivative:0});
4927-
var dY = SG(y, x, {windowSize:sgOptions.windowSize, polynomial:sgOptions.polynomial,derivative:1});
4928-
var ddY = SG(y, x, {windowSize:sgOptions.windowSize, polynomial:sgOptions.polynomial,derivative:2});
4925+
dY = SG(y, x, {windowSize:sgOptions.windowSize, polynomial:sgOptions.polynomial,derivative:1});
4926+
ddY = SG(y, x, {windowSize:sgOptions.windowSize, polynomial:sgOptions.polynomial,derivative:2});
49294927
}
49304928

4931-
var X = x;
4932-
var dx = x[1]-x[0];
4933-
var maxDdy=0;
4929+
const X = x;
4930+
const dx = x[1] - x[0];
4931+
var maxDdy = 0;
49344932
var maxY = 0;
4935-
//console.log(Y.length);
4936-
for (var i = 0; i < Y.length ; i++){
4937-
if(Math.abs(ddY[i])>maxDdy){
4933+
for (i = 0; i < Y.length ; i++) {
4934+
if(Math.abs(ddY[i]) > maxDdy) {
49384935
maxDdy = Math.abs(ddY[i]);
49394936
}
4940-
if(Math.abs(Y[i])>maxY){
4937+
if(Math.abs(Y[i]) > maxY) {
49414938
maxY = Math.abs(Y[i]);
49424939
}
49434940
}
4944-
//console.log(maxY+"x"+maxDy+"x"+maxDdy);
49454941

49464942
var minddY = [];
49474943
var intervalL = [];
49484944
var intervalR = [];
49494945
var lastMax = null;
49504946
var lastMin = null;
49514947
var broadMask = new Array();
4952-
//console.log(dx);
49534948
//By the intermediate value theorem We cannot find 2 consecutive maxima or minima
4954-
for (var i = 1; i < Y.length -1 ; i++){
4949+
for (i = 1; i < Y.length -1 ; i++){
49554950
//console.log(dY[i]);
4956-
if ((dY[i] < dY[i-1]) && (dY[i] <= dY[i+1])||
4951+
if ((dY[i] < dY[i-1]) && (dY[i] <= dY[i+1]) ||
49574952
(dY[i] <= dY[i-1]) && (dY[i] < dY[i+1])) {
49584953
lastMin = X[i];
4959-
//console.log("min "+lastMin);
4960-
if(dx>0&&lastMax!=null){
4954+
if(dx > 0 && lastMax != null) {
49614955
intervalL.push(lastMax);
49624956
intervalR.push(lastMin);
49634957

49644958
}
49654959
}
49664960

4967-
if ((dY[i] >= dY[i-1]) && (dY[i] > dY[i+1])||
4961+
if ((dY[i] >= dY[i-1]) && (dY[i] > dY[i+1]) ||
49684962
(dY[i] > dY[i-1]) && (dY[i] >= dY[i+1])) {
49694963
lastMax = X[i];
4970-
//console.log("max "+lastMax);
4971-
if(dx<0&&lastMin!=null){
4964+
if(dx < 0 && lastMin != null) {
49724965
intervalL.push(lastMax);
49734966
intervalR.push(lastMin);
49744967
}
49754968
}
49764969
if ((ddY[i] < ddY[i-1]) && (ddY[i] < ddY[i+1])) {
49774970
minddY.push(i);//( [X[i], Y[i], i] ); // TODO should we change this to have 3 arrays ? Huge overhead creating arrays
4978-
if(Math.abs(ddY[i])>options.broadRatio*maxDdy){ // TODO should this be a parameter =
4971+
if(Math.abs(ddY[i]) > options.broadRatio*maxDdy) { // TODO should this be a parameter =
49794972
broadMask.push(false);
49804973
}
4981-
else{
4974+
else {
49824975
broadMask.push(true);
49834976
}
49844977
}
49854978
}
4986-
//
4987-
//console.log(intervalL.length+" "+minddY.length+" "+broadMask.length);
4979+
49884980
var signals = [];
4989-
var lastK = 0,possible, k, f,frequency, distanceJ, minDistance, gettingCloser;
4990-
for (var j = 0; j < minddY.length; j++){
4991-
frequency = X[minddY[j]];//minddY[j][0];
4981+
var lastK = 0;
4982+
var possible, frequency, distanceJ, minDistance, gettingCloser;
4983+
for (j = 0; j < minddY.length; j++) {
4984+
frequency = X[minddY[j]];
49924985
possible = -1;
4993-
k=lastK+1;
4986+
k = lastK + 1;
49944987
minDistance = Number.MAX_VALUE;
49954988
distanceJ = 0;
49964989
gettingCloser=true;
4997-
while(possible==-1&&k<intervalL.length&&gettingCloser){
4990+
while(possible == -1 && k < intervalL.length && gettingCloser) {
49984991
distanceJ = Math.abs(frequency-(intervalL[k]+intervalR[k])/2);
49994992
//Still getting closer?
5000-
if(distanceJ<minDistance){
4993+
if(distanceJ < minDistance) {
50014994
minDistance = distanceJ;
50024995
}
50034996
else{
50044997
gettingCloser = false;
50054998
}
5006-
if( distanceJ <Math.abs(intervalL[k]-intervalR[k])/2){
5007-
possible=k;
4999+
if( distanceJ < Math.abs(intervalL[k]-intervalR[k])/2) {
5000+
possible = k;
50085001
lastK = k;
50095002
}
50105003
k++;
50115004
}
5012-
//console.log(lastK+" "+intervalL.length+" possible "+k);
5013-
if (possible!=-1){
5014-
//console.log(height);
5005+
if (possible != -1) {
50155006
if (Math.abs(Y[minddY[j]]) > options.minMaxRatio*maxY) {
50165007
signals.push({
50175008
i:minddY[j],
50185009
x: frequency,
5019-
y: (Y[minddY[j]]-yCorrection.b)/yCorrection.m,
5010+
y: (Y[minddY[j]]+yCorrection.b)/yCorrection.m,
50205011
width:Math.abs(intervalR[possible] - intervalL[possible]),//widthCorrection
50215012
soft:broadMask[j]
50225013
})
@@ -5025,13 +5016,13 @@ return /******/ (function(modules) { // webpackBootstrap
50255016
}
50265017

50275018

5028-
if(options.realTopDetection){
5019+
if(options.realTopDetection) {
50295020
realTopDetection(signals,X,Y);
50305021
}
50315022

50325023
//Correct the values to fit the original spectra data
5033-
for(var j=0;j<signals.length;j++){
5034-
signals[j].base=options.noiseLevel;
5024+
for(j = 0;j < signals.length; j++) {
5025+
signals[j].base = options.noiseLevel;
50355026
}
50365027

50375028
signals.sort(function (a, b) {
@@ -5042,11 +5033,11 @@ return /******/ (function(modules) { // webpackBootstrap
50425033

50435034
}
50445035

5045-
function getNoiseLevel(y){
5046-
var mean = 0,stddev=0;
5047-
var length = y.length,i=0;
5048-
for(i = 0; i < length; i++){
5049-
mean+=y[i];
5036+
function getNoiseLevel(y) {
5037+
var mean = 0, stddev = 0;
5038+
var length = y.length, i = 0;
5039+
for(i = 0; i < length; i++) {
5040+
mean += y[i];
50505041
}
50515042
mean/=length;
50525043
var averageDeviations = new Array(length);
@@ -5062,41 +5053,36 @@ return /******/ (function(modules) { // webpackBootstrap
50625053
return stddev;
50635054
}
50645055

5065-
function realTopDetection(peakList, x, y){
5066-
//console.log(peakList);
5067-
//console.log(x);
5068-
//console.log(y);
5069-
var listP = [];
5056+
function realTopDetection(peakList, x, y) {
50705057
var alpha, beta, gamma, p,currentPoint;
5071-
for(var j=0;j<peakList.length;j++){
5058+
for(var j = 0; j < peakList.length; j++) {
50725059
currentPoint = peakList[j].i;//peakList[j][2];
5073-
var tmp = currentPoint;
50745060
//The detected peak could be moved 1 or 2 unit to left or right.
5075-
if(y[currentPoint-1]>=y[currentPoint-2]
5076-
&&y[currentPoint-1]>=y[currentPoint]) {
5061+
if(y[currentPoint-1] >= y[currentPoint-2]
5062+
&& y[currentPoint-1] >= y[currentPoint]) {
50775063
currentPoint--;
50785064
}
5079-
else{
5080-
if(y[currentPoint+1]>=y[currentPoint]
5081-
&&y[currentPoint+1]>=y[currentPoint+2]) {
5065+
else {
5066+
if(y[currentPoint+1] >= y[currentPoint]
5067+
&& y[currentPoint+1] >= y[currentPoint+2]) {
50825068
currentPoint++;
50835069
}
50845070
else{
5085-
if(y[currentPoint-2]>=y[currentPoint-3]
5086-
&&y[currentPoint-2]>=y[currentPoint-1]) {
5071+
if(y[currentPoint-2] >= y[currentPoint-3]
5072+
&& y[currentPoint-2] >= y[currentPoint-1]) {
50875073
currentPoint-=2;
50885074
}
5089-
else{
5090-
if(y[currentPoint+2]>=y[currentPoint+1]
5091-
&&y[currentPoint+2]>=y[currentPoint+3]) {
5075+
else {
5076+
if(y[currentPoint+2] >= y[currentPoint+1]
5077+
&& y[currentPoint+2] >= y[currentPoint+3]) {
50925078
currentPoint+=2;
50935079
}
50945080
}
50955081
}
50965082
}
5097-
if(y[currentPoint-1]>0&&y[currentPoint+1]>0
5098-
&&y[currentPoint]>=y[currentPoint-1]
5099-
&&y[currentPoint]>=y[currentPoint+1]) {
5083+
if(y[currentPoint-1] > 0 && y[currentPoint+1] > 0
5084+
&& y[currentPoint] >= y[currentPoint-1]
5085+
&& y[currentPoint] >= y[currentPoint+1]) {
51005086
alpha = 20 * Math.log10(y[currentPoint - 1]);
51015087
beta = 20 * Math.log10(y[currentPoint]);
51025088
gamma = 20 * Math.log10(y[currentPoint + 1]);
@@ -5106,7 +5092,6 @@ return /******/ (function(modules) { // webpackBootstrap
51065092
peakList[j].x = x[currentPoint] + (x[currentPoint]-x[currentPoint-1])*p;
51075093
peakList[j].y = y[currentPoint] - 0.25 * (y[currentPoint - 1]
51085094
- y[currentPoint + 1]) * p;//signal.peaks[j].intensity);
5109-
//console.log(y[tmp]+" "+peakList[j].y);
51105095
}
51115096
}
51125097
}

dist/ml-gsd.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ml-gsd.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"homepage": "https://github.com/mljs/global-spectral-deconvolution",
3131
"devDependencies": {
32-
"cheminfo-tools": "^1.0.2",
32+
"cheminfo-tools": "^1.3.1",
3333
"mocha": "^2.2.5",
3434
"mocha-better-spec-reporter": "^2.1.1",
3535
"should": "^7.0.2",

0 commit comments

Comments
 (0)