@@ -7,9 +7,27 @@ var removeMFLastPart = require('./util/removeMFLastPart.js');
7
7
// TODO replace from the value coming from chemcalc
8
8
var ELECTRON_MASS = 5.4857990946e-4 ;
9
9
10
+ /**
11
+ *
12
+ * @param keys
13
+ * @param options
14
+ * @param {number } [options.limit=1000000] - Maximum number of results
15
+ * @param {number } [options.minMass=0] - Minimal monoisotopic mass
16
+ * @param {number } [options.maxMass=+Infinity] - Maximal monoisotopic mass
17
+ * @param {number } [options.minMSMass=0] - Minimal observed monoisotopic mass
18
+ * @param {number } [options.maxMSMass=+Infinity] - Maximal observed monoisotopic mass
19
+ * @param {number } [options.minCharge=-Infinity] - Minimal charge
20
+ * @param {number } [options.maxCharge=+Infinity] - Maximal charge
21
+ * @returns {Array }
22
+ */
23
+
10
24
function combineMFs ( keys , options ) {
11
- var options = options || { } ;
12
- options . limit = options . limit || 1000000 ;
25
+
26
+ options = Object . assign ( { } , {
27
+ limit :1000000 ,
28
+ minCharge :Number . NEGATIVE_INFINITY ,
29
+ maxCharge :Number . POSITIVE_INFINITY
30
+ } , options ) ;
13
31
if ( ! Array . isArray ( keys ) ) return [ ] ;
14
32
15
33
@@ -52,7 +70,7 @@ function combineMFs (keys, options) {
52
70
while ( position < currents . length ) {
53
71
if ( currents [ position ] < sizes [ position ] ) {
54
72
evolution ++ ;
55
- appendResult ( results , currents , keys ) ;
73
+ appendResult ( results , currents , keys , options ) ;
56
74
currents [ position ] ++ ;
57
75
for ( var i = 0 ; i < position ; i ++ ) {
58
76
currents [ i ] = 0 ;
@@ -65,7 +83,7 @@ function combineMFs (keys, options) {
65
83
throw new Error ( 'You have reached the limit of ' + options . limit + '. You could still change this value using options.limit but it is likely to crash.' ) ;
66
84
}
67
85
}
68
- appendResult ( results , currents , keys ) ;
86
+ appendResult ( results , currents , keys , options ) ;
69
87
return results ;
70
88
}
71
89
@@ -115,13 +133,30 @@ function getEMFromParts(parts, currents) {
115
133
}
116
134
}
117
135
118
- function appendResult ( results , currents , keys ) {
136
+ function appendResult ( results , currents , keys , options ) {
119
137
// this script is designed to combine molecular formula
120
138
// that may contain comments after a "$" sign
121
139
// therefore we should put all the comments at the ned
140
+
141
+ var info = getEMFromParts ( keys , currents ) ;
142
+
143
+ var em = info . em ;
144
+ var msem = info . msem ;
145
+ var charge = info . charge ;
146
+
147
+ if ( ( typeof options . minMass !== 'undefined' && em < options . minMass )
148
+ || ( typeof options . maxMass !== 'undefined' && em > options . maxMass ) ) return ;
149
+ if ( ( typeof options . minMSMass !== 'undefined' && msem < options . minMSMass )
150
+ || ( typeof options . maxMSMass !== 'undefined' && msem > options . maxMSMass ) ) return ;
151
+ if ( charge < options . minCharge || charge > options . maxCharge ) return ;
152
+
122
153
var result = { mf : '' } ;
123
154
var comments = [ ] ;
124
155
156
+ result . em = em ;
157
+ result . msem = msem ;
158
+ result . charge = charge ;
159
+
125
160
for ( var i = 0 ; i < keys . length ; i ++ ) {
126
161
var key = keys [ i ] [ currents [ i ] ] ;
127
162
if ( key ) {
@@ -132,12 +167,12 @@ function appendResult(results, currents, keys) {
132
167
}
133
168
result . mf += key ;
134
169
}
135
- var info = getEMFromParts ( keys , currents ) ;
136
- result . em = info . em ;
137
- result . msem = info . msem ;
138
- result . charge = info . charge ;
139
170
}
140
171
172
+
173
+
174
+
175
+
141
176
if ( comments . length > 0 ) result . mf += '$' + comments . join ( ' ' ) ;
142
177
143
178
results . push ( result ) ;
0 commit comments