3352 |
26 May 15 |
olle |
var ExtractUtils = function() |
3352 |
26 May 15 |
olle |
2 |
{ |
3352 |
26 May 15 |
olle |
var exutils = {}; |
3352 |
26 May 15 |
olle |
var debug = 0; |
3352 |
26 May 15 |
olle |
5 |
|
3354 |
27 May 15 |
olle |
exutils.getQiacubeSortedPrefixes = function(primaryQiacubePrefix, secondaryQiacubePrefix) |
3354 |
27 May 15 |
olle |
7 |
{ |
3354 |
27 May 15 |
olle |
// Default value for primary QIAcube prefix is "B", and for secondary is "C" |
3354 |
27 May 15 |
olle |
if (primaryQiacubePrefix == null || primaryQiacubePrefix == '') |
3354 |
27 May 15 |
olle |
10 |
{ |
3354 |
27 May 15 |
olle |
primaryQiacubePrefix = 'B'; |
3354 |
27 May 15 |
olle |
12 |
} |
3354 |
27 May 15 |
olle |
if (secondaryQiacubePrefix == null || secondaryQiacubePrefix == '') |
3354 |
27 May 15 |
olle |
14 |
{ |
3354 |
27 May 15 |
olle |
secondaryQiacubePrefix = 'C'; |
3354 |
27 May 15 |
olle |
16 |
} |
3352 |
26 May 15 |
olle |
17 |
|
3354 |
27 May 15 |
olle |
// Get string of current QIAcube prefixes in order |
3354 |
27 May 15 |
olle |
var fullSortedPrefixSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
3354 |
27 May 15 |
olle |
var sortedPrefixes = '' + primaryQiacubePrefix + secondaryQiacubePrefix; |
3354 |
27 May 15 |
olle |
for (var i = 0; i < fullSortedPrefixSet.length; i++) |
3354 |
27 May 15 |
olle |
22 |
{ |
3354 |
27 May 15 |
olle |
// Get next prefix |
3354 |
27 May 15 |
olle |
var prefix = fullSortedPrefixSet.substring(i, i+1); |
3354 |
27 May 15 |
olle |
// Add prefix to string of sorted prefixes, if not already present |
3354 |
27 May 15 |
olle |
if (prefix != primaryQiacubePrefix && prefix != secondaryQiacubePrefix) |
3354 |
27 May 15 |
olle |
27 |
{ |
3354 |
27 May 15 |
olle |
sortedPrefixes += prefix; |
3354 |
27 May 15 |
olle |
29 |
} |
3354 |
27 May 15 |
olle |
30 |
} |
3354 |
27 May 15 |
olle |
return sortedPrefixes; |
3354 |
27 May 15 |
olle |
32 |
} |
3354 |
27 May 15 |
olle |
33 |
|
3354 |
27 May 15 |
olle |
34 |
/** |
3354 |
27 May 15 |
olle |
Returns a QIAcube position string with optional instrument |
3354 |
27 May 15 |
olle |
letter prefix A-Z for vial 'i', when 'nitems' vials are |
3354 |
27 May 15 |
olle |
to be analyzed on at most two instruments. |
3354 |
27 May 15 |
olle |
38 |
|
3354 |
27 May 15 |
olle |
If the number of items is <= 12, all will be placed in |
3354 |
27 May 15 |
olle |
the QIAcube with the primary prefix. If the number of items |
3354 |
27 May 15 |
olle |
is > 12 and <= 24, they will be distributed between |
3354 |
27 May 15 |
olle |
two instruments as evenly as possible, except that one |
3354 |
27 May 15 |
olle |
tries to avoid having 11 vials in the instrument with |
3354 |
27 May 15 |
olle |
most vials, as this would require a counterbalance. For 23 |
3354 |
27 May 15 |
olle |
vials the instruments with less vials (11) will need a |
3354 |
27 May 15 |
olle |
counterbalance. |
3354 |
27 May 15 |
olle |
47 |
*/ |
3354 |
27 May 15 |
olle |
exutils.getDetailedQiaCubePosition = function(nitems, i, qiacubeSortedPrefixes) |
3352 |
26 May 15 |
olle |
49 |
{ |
3352 |
26 May 15 |
olle |
var dpos = null; |
3352 |
26 May 15 |
olle |
var qiacubePos = null; |
3354 |
27 May 15 |
olle |
// Two QIAcube instruments are available, default is 'B' and 'C' |
3352 |
26 May 15 |
olle |
var qiacubeId = qiacubeSortedPrefixes.substring(0, 1); |
3352 |
26 May 15 |
olle |
if (nitems == null || nitems < 1 || nitems > 24) |
3352 |
26 May 15 |
olle |
55 |
{ |
3352 |
26 May 15 |
olle |
return null; |
3352 |
26 May 15 |
olle |
57 |
} |
3352 |
26 May 15 |
olle |
if (i == null || i < 1 || i > nitems) |
3352 |
26 May 15 |
olle |
59 |
{ |
3352 |
26 May 15 |
olle |
return null; |
3352 |
26 May 15 |
olle |
61 |
} |
3352 |
26 May 15 |
olle |
if (nitems <= 12) |
3352 |
26 May 15 |
olle |
63 |
{ |
3352 |
26 May 15 |
olle |
qiacubePos = exutils.getQiaCubePosition(nitems, i); |
3352 |
26 May 15 |
olle |
65 |
} |
3352 |
26 May 15 |
olle |
else |
3352 |
26 May 15 |
olle |
67 |
{ |
3352 |
26 May 15 |
olle |
var numItemsQiaCube1 = Math.floor((nitems + 1)/2); |
3352 |
26 May 15 |
olle |
if (numItemsQiaCube1 == 11) |
3352 |
26 May 15 |
olle |
70 |
{ |
3352 |
26 May 15 |
olle |
numItemsQiaCube1 = 12; |
3352 |
26 May 15 |
olle |
72 |
} |
3352 |
26 May 15 |
olle |
if (i <= numItemsQiaCube1) |
3352 |
26 May 15 |
olle |
74 |
{ |
3352 |
26 May 15 |
olle |
// Place sample in first QIAcube |
3352 |
26 May 15 |
olle |
qiacubePos = exutils.getQiaCubePosition(numItemsQiaCube1, i); |
3352 |
26 May 15 |
olle |
77 |
} |
3352 |
26 May 15 |
olle |
else |
3352 |
26 May 15 |
olle |
79 |
{ |
3352 |
26 May 15 |
olle |
// Place sample in second QIAcube |
3352 |
26 May 15 |
olle |
var numItemsQiaCube2 = nitems - numItemsQiaCube1; |
3352 |
26 May 15 |
olle |
qiacubePos = exutils.getQiaCubePosition(numItemsQiaCube2, i - numItemsQiaCube1); |
3352 |
26 May 15 |
olle |
qiacubeId = qiacubeSortedPrefixes.substring(1, 2); |
3352 |
26 May 15 |
olle |
84 |
} |
3352 |
26 May 15 |
olle |
85 |
} |
3352 |
26 May 15 |
olle |
if (qiacubeId != null && qiacubePos != null) |
3352 |
26 May 15 |
olle |
87 |
{ |
3352 |
26 May 15 |
olle |
dpos = qiacubeId + qiacubePos; |
3352 |
26 May 15 |
olle |
89 |
} |
3352 |
26 May 15 |
olle |
return dpos; |
3352 |
26 May 15 |
olle |
91 |
} |
3352 |
26 May 15 |
olle |
92 |
|
3354 |
27 May 15 |
olle |
93 |
/** |
3354 |
27 May 15 |
olle |
Returns a QIAcube position number in a single instrument |
3354 |
27 May 15 |
olle |
for vial 'i', when 'nitems' vials are placed in the instrument. |
3354 |
27 May 15 |
olle |
The numbers are based on recommendations from the manufacturer, |
3354 |
27 May 15 |
olle |
in order to ensure balance stability of the centrifuge. |
3354 |
27 May 15 |
olle |
For a total of 1 or 11 items, it is assumed that a counterbalance |
3354 |
27 May 15 |
olle |
in the proper positions is used. |
3354 |
27 May 15 |
olle |
100 |
*/ |
3352 |
26 May 15 |
olle |
exutils.getQiaCubePosition = function(nitems, i) |
3352 |
26 May 15 |
olle |
102 |
{ |
3352 |
26 May 15 |
olle |
var pos = null; |
3352 |
26 May 15 |
olle |
if (nitems == null || nitems < 1 || nitems > 12) |
3352 |
26 May 15 |
olle |
105 |
{ |
3352 |
26 May 15 |
olle |
return null; |
3352 |
26 May 15 |
olle |
107 |
} |
3352 |
26 May 15 |
olle |
if (i == null || i < 1 || i > nitems) |
3352 |
26 May 15 |
olle |
109 |
{ |
3352 |
26 May 15 |
olle |
return null; |
3352 |
26 May 15 |
olle |
111 |
} |
3352 |
26 May 15 |
olle |
var posArr = ['1','2','3','4','5','6','7','8','9','10','11','12']; |
3352 |
26 May 15 |
olle |
if (nitems == 2) |
3352 |
26 May 15 |
olle |
114 |
{ |
3352 |
26 May 15 |
olle |
posArr = ['1','7','','','','','','','','','','']; |
3352 |
26 May 15 |
olle |
116 |
} |
3352 |
26 May 15 |
olle |
else if (nitems == 3) |
3352 |
26 May 15 |
olle |
118 |
{ |
3352 |
26 May 15 |
olle |
posArr = ['1','5','9','','','','','','','','','']; |
3352 |
26 May 15 |
olle |
120 |
} |
3352 |
26 May 15 |
olle |
else if (nitems == 4) |
3352 |
26 May 15 |
olle |
122 |
{ |
3352 |
26 May 15 |
olle |
posArr = ['1','2','7','8','','','','','','','','']; |
3352 |
26 May 15 |
olle |
124 |
} |
3352 |
26 May 15 |
olle |
else if (nitems == 5) |
3352 |
26 May 15 |
olle |
126 |
{ |
3352 |
26 May 15 |
olle |
posArr = ['1','2','5','8','9','','','','','','','']; |
3352 |
26 May 15 |
olle |
128 |
} |
3352 |
26 May 15 |
olle |
else if (nitems == 6) |
3352 |
26 May 15 |
olle |
130 |
{ |
3352 |
26 May 15 |
olle |
posArr = ['1','2','3','7','8','9','','','','','','']; |
3352 |
26 May 15 |
olle |
132 |
} |
3352 |
26 May 15 |
olle |
else if (nitems == 7) |
3352 |
26 May 15 |
olle |
134 |
{ |
3352 |
26 May 15 |
olle |
posArr = ['1','2','3','6','7','9','10','','','','','']; |
3352 |
26 May 15 |
olle |
136 |
} |
3352 |
26 May 15 |
olle |
else if (nitems == 8) |
3352 |
26 May 15 |
olle |
138 |
{ |
3352 |
26 May 15 |
olle |
posArr = ['1','2','3','4','7','8','9','10','','','','']; |
3352 |
26 May 15 |
olle |
140 |
} |
3352 |
26 May 15 |
olle |
else if (nitems == 9) |
3352 |
26 May 15 |
olle |
142 |
{ |
3352 |
26 May 15 |
olle |
posArr = ['1','2','3','5','6','7','9','10','11','','','']; |
3352 |
26 May 15 |
olle |
144 |
} |
3352 |
26 May 15 |
olle |
else if (nitems == 10) |
3352 |
26 May 15 |
olle |
146 |
{ |
3352 |
26 May 15 |
olle |
posArr = ['1','2','3','4','5','7','8','9','10','11','','']; |
3352 |
26 May 15 |
olle |
148 |
} |
3352 |
26 May 15 |
olle |
else if (nitems == 11) |
3352 |
26 May 15 |
olle |
150 |
{ |
3352 |
26 May 15 |
olle |
// Counterbalance blank vial filled with water needed i position 12. |
3352 |
26 May 15 |
olle |
posArr = ['1','2','3','4','5','6','7','8','9','10','11','']; |
3352 |
26 May 15 |
olle |
153 |
} |
3352 |
26 May 15 |
olle |
pos = posArr[i-1]; |
3352 |
26 May 15 |
olle |
return pos; |
3352 |
26 May 15 |
olle |
156 |
} |
3352 |
26 May 15 |
olle |
157 |
|
3352 |
26 May 15 |
olle |
158 |
/** |
3352 |
26 May 15 |
olle |
Returns a QIAcube position string with optional instrument |
3352 |
26 May 15 |
olle |
letter prefix A-Z from a pure integer position value. |
3352 |
26 May 15 |
olle |
161 |
|
3352 |
26 May 15 |
olle |
Examples for qiacubeSortedPrefixes = 'BCADEFGHIJKLMNOPQRSTUVWXYZ' ("B" is default) |
3352 |
26 May 15 |
olle |
intPosition ( 1 - 12) => positionStr = 'B' + integer |
3352 |
26 May 15 |
olle |
intPosition ( 13 - 24) => positionStr = 'C' + (integer - 12) |
3352 |
26 May 15 |
olle |
intPosition (301 - 312) => positionStr = 'Z' + (integer - 300) |
3352 |
26 May 15 |
olle |
166 |
*/ |
3354 |
27 May 15 |
olle |
exutils.getDetailedQiacubePosition = function(intPosition, qiacubeSortedPrefixes) |
3352 |
26 May 15 |
olle |
168 |
{ |
3352 |
26 May 15 |
olle |
var qiacubePositionStr = null; |
3352 |
26 May 15 |
olle |
if (intPosition && intPosition > 0) |
3352 |
26 May 15 |
olle |
171 |
{ |
3352 |
26 May 15 |
olle |
var numPrefixes = qiacubeSortedPrefixes.length; |
3352 |
26 May 15 |
olle |
var prefixIndex = Math.floor(intPosition/12); |
3352 |
26 May 15 |
olle |
if (prefixIndex < numPrefixes) |
3352 |
26 May 15 |
olle |
175 |
{ |
3352 |
26 May 15 |
olle |
var qiacubePrefix = qiacubeSortedPrefixes.substring(prefixIndex, prefixIndex + 1); |
3352 |
26 May 15 |
olle |
var qiacubePos = intPosition - 12*prefixIndex; |
3352 |
26 May 15 |
olle |
qiacubePositionStr = qiacubePrefix + qiacubePos; |
3352 |
26 May 15 |
olle |
179 |
} |
3352 |
26 May 15 |
olle |
else |
3352 |
26 May 15 |
olle |
181 |
{ |
3352 |
26 May 15 |
olle |
qiacubePositionStr = '' + intPosition; |
3352 |
26 May 15 |
olle |
183 |
} |
3352 |
26 May 15 |
olle |
184 |
} |
3352 |
26 May 15 |
olle |
return qiacubePositionStr; |
3352 |
26 May 15 |
olle |
186 |
} |
3352 |
26 May 15 |
olle |
187 |
|
3352 |
26 May 15 |
olle |
188 |
/** |
3352 |
26 May 15 |
olle |
Returns a pure integer position value from a QIAcube position |
3352 |
26 May 15 |
olle |
string with optional instrument letter prefix A-Z. |
3352 |
26 May 15 |
olle |
Returns `null` if input position string is `null`. |
3352 |
26 May 15 |
olle |
192 |
|
3352 |
26 May 15 |
olle |
positionStr = integer => QIAcube position = integer (1-12) |
3352 |
26 May 15 |
olle |
positionStr = Prefix + integer => QIAcube position = integer + 12*<Prefix order number 0-25> |
3352 |
26 May 15 |
olle |
195 |
*/ |
3354 |
27 May 15 |
olle |
exutils.getIntQiacubePosition = function(positionStr, qiacubeSortedPrefixes) |
3352 |
26 May 15 |
olle |
197 |
{ |
3352 |
26 May 15 |
olle |
var intPos = null; |
3352 |
26 May 15 |
olle |
if (positionStr) |
3352 |
26 May 15 |
olle |
200 |
{ |
3352 |
26 May 15 |
olle |
// Check if string contains uppercase letter + QIAcube position number 1-12 |
3352 |
26 May 15 |
olle |
if (/^[A-Z]([2-9]|1[0-2]?)$/.test(positionStr)) |
3352 |
26 May 15 |
olle |
203 |
{ |
3352 |
26 May 15 |
olle |
var qiaCubePrefix = positionStr.substring(0,1); |
3352 |
26 May 15 |
olle |
// Get QIAcube prefix order number 0-25 |
3352 |
26 May 15 |
olle |
var qiacubePrefixOrder = qiacubeSortedPrefixes.indexOf(qiaCubePrefix); |
3352 |
26 May 15 |
olle |
if (qiacubePrefixOrder >= 0) |
3352 |
26 May 15 |
olle |
208 |
{ |
3352 |
26 May 15 |
olle |
intPos = parseInt(positionStr.substring(1)) + 12*qiacubePrefixOrder; |
3352 |
26 May 15 |
olle |
210 |
} |
3352 |
26 May 15 |
olle |
211 |
} |
3352 |
26 May 15 |
olle |
if (intPos == null) |
3352 |
26 May 15 |
olle |
213 |
{ |
3352 |
26 May 15 |
olle |
intPos = parseInt(positionStr); |
3352 |
26 May 15 |
olle |
215 |
} |
3352 |
26 May 15 |
olle |
216 |
} |
3352 |
26 May 15 |
olle |
return intPos; |
3352 |
26 May 15 |
olle |
218 |
} |
3352 |
26 May 15 |
olle |
219 |
|
3432 |
29 Jun 15 |
olle |
exutils.isMeludiItem = function(item) |
3432 |
29 Jun 15 |
olle |
221 |
{ |
3432 |
29 Jun 15 |
olle |
var isMeludiItem = false; |
3432 |
29 Jun 15 |
olle |
if (item != null) |
3432 |
29 Jun 15 |
olle |
224 |
{ |
3432 |
29 Jun 15 |
olle |
var name = item.name; |
3432 |
29 Jun 15 |
olle |
if (name != null) |
3432 |
29 Jun 15 |
olle |
227 |
{ |
3432 |
29 Jun 15 |
olle |
// Check that item name starts with "ML" to exclude extra items |
3432 |
29 Jun 15 |
olle |
if (name.indexOf('ML') == 0) |
3432 |
29 Jun 15 |
olle |
230 |
{ |
3432 |
29 Jun 15 |
olle |
isMeludiItem = true; |
3432 |
29 Jun 15 |
olle |
232 |
} |
3432 |
29 Jun 15 |
olle |
233 |
} |
3432 |
29 Jun 15 |
olle |
234 |
} |
3432 |
29 Jun 15 |
olle |
return isMeludiItem; |
3432 |
29 Jun 15 |
olle |
236 |
} |
3432 |
29 Jun 15 |
olle |
237 |
|
3432 |
29 Jun 15 |
olle |
exutils.isExtraMaterial = function(item) |
3432 |
29 Jun 15 |
olle |
239 |
{ |
3432 |
29 Jun 15 |
olle |
var isExtraMaterial = false; |
3432 |
29 Jun 15 |
olle |
if (item != null) |
3432 |
29 Jun 15 |
olle |
242 |
{ |
3432 |
29 Jun 15 |
olle |
var name = item.name; |
3432 |
29 Jun 15 |
olle |
if (name != null) |
3432 |
29 Jun 15 |
olle |
245 |
{ |
3432 |
29 Jun 15 |
olle |
// Check that item name does not start with "ML" to exclude MeLuDI items |
3432 |
29 Jun 15 |
olle |
if (name.indexOf('ML') != 0) |
3432 |
29 Jun 15 |
olle |
248 |
{ |
3432 |
29 Jun 15 |
olle |
isExtraMaterial = true; |
3432 |
29 Jun 15 |
olle |
250 |
} |
3432 |
29 Jun 15 |
olle |
251 |
} |
3432 |
29 Jun 15 |
olle |
252 |
} |
3432 |
29 Jun 15 |
olle |
return isExtraMaterial; |
3432 |
29 Jun 15 |
olle |
254 |
} |
3432 |
29 Jun 15 |
olle |
255 |
|
3352 |
26 May 15 |
olle |
exutils.isSpecimen = function(item) |
3352 |
26 May 15 |
olle |
257 |
{ |
3352 |
26 May 15 |
olle |
var isSpecimen = false; |
3352 |
26 May 15 |
olle |
if (item != null) |
3352 |
26 May 15 |
olle |
260 |
{ |
3432 |
29 Jun 15 |
olle |
var name = item.name; |
3432 |
29 Jun 15 |
olle |
if (name != null) |
3352 |
26 May 15 |
olle |
263 |
{ |
3432 |
29 Jun 15 |
olle |
// Check that item name ends with single dot "." followed by a natural number (>0) |
3432 |
29 Jun 15 |
olle |
// "\x2E" represents a dot "." (2E is the hexadecimal ASCII code for ".") |
3638 |
02 Dec 15 |
olle |
var pattern = /^[0-9_-]*[A-Za-z]+[A-Za-z0-9_-]*\x2E[1-9]+[0-9]*$/ |
3432 |
29 Jun 15 |
olle |
if (pattern.test(name)) |
3352 |
26 May 15 |
olle |
268 |
{ |
3432 |
29 Jun 15 |
olle |
isSpecimen = true; |
3352 |
26 May 15 |
olle |
270 |
} |
5225 |
14 Jan 19 |
olle |
else |
5225 |
14 Jan 19 |
olle |
272 |
{ |
5225 |
14 Jan 19 |
olle |
// New name convention |
5225 |
14 Jan 19 |
olle |
// Check that item name ends with single dot "." followed by a natural number (>0) followed by ".s" |
5225 |
14 Jan 19 |
olle |
var pattern2 = /^[0-9_-]*[A-Za-z]+[A-Za-z0-9_-]*\x2E[1-9]+[0-9]*\x2E[s]$/ |
5225 |
14 Jan 19 |
olle |
if (pattern2.test(name)) |
5225 |
14 Jan 19 |
olle |
277 |
{ |
5225 |
14 Jan 19 |
olle |
isSpecimen = true; |
5225 |
14 Jan 19 |
olle |
279 |
} |
5225 |
14 Jan 19 |
olle |
280 |
} |
3352 |
26 May 15 |
olle |
281 |
} |
3352 |
26 May 15 |
olle |
282 |
} |
3352 |
26 May 15 |
olle |
return isSpecimen; |
3352 |
26 May 15 |
olle |
284 |
} |
3352 |
26 May 15 |
olle |
285 |
|
3352 |
26 May 15 |
olle |
exutils.isRna = function(item) |
3352 |
26 May 15 |
olle |
287 |
{ |
3352 |
26 May 15 |
olle |
var isRna = false; |
3352 |
26 May 15 |
olle |
if (item != null) |
3352 |
26 May 15 |
olle |
290 |
{ |
3352 |
26 May 15 |
olle |
var name = item.name; |
3352 |
26 May 15 |
olle |
if (name != null) |
3352 |
26 May 15 |
olle |
293 |
{ |
3352 |
26 May 15 |
olle |
// Check if item name ends with ".r" |
3352 |
26 May 15 |
olle |
if (name.indexOf('.r') == (name.length - 2)) |
3352 |
26 May 15 |
olle |
296 |
{ |
3352 |
26 May 15 |
olle |
isRna = true; |
3352 |
26 May 15 |
olle |
298 |
} |
3352 |
26 May 15 |
olle |
299 |
} |
3352 |
26 May 15 |
olle |
300 |
} |
3352 |
26 May 15 |
olle |
return isRna; |
3352 |
26 May 15 |
olle |
302 |
} |
3352 |
26 May 15 |
olle |
303 |
|
3352 |
26 May 15 |
olle |
exutils.isDna = function(item) |
3352 |
26 May 15 |
olle |
305 |
{ |
3352 |
26 May 15 |
olle |
var isDna = false; |
3352 |
26 May 15 |
olle |
if (item != null) |
3352 |
26 May 15 |
olle |
308 |
{ |
3352 |
26 May 15 |
olle |
var name = item.name; |
3352 |
26 May 15 |
olle |
if (name != null) |
3352 |
26 May 15 |
olle |
311 |
{ |
3352 |
26 May 15 |
olle |
// Check if item name ends with ".d" |
3352 |
26 May 15 |
olle |
if (name.indexOf('.d') == (name.length - 2)) |
3352 |
26 May 15 |
olle |
314 |
{ |
3352 |
26 May 15 |
olle |
isDna = true; |
3352 |
26 May 15 |
olle |
316 |
} |
3352 |
26 May 15 |
olle |
317 |
} |
3352 |
26 May 15 |
olle |
318 |
} |
3352 |
26 May 15 |
olle |
return isDna; |
3352 |
26 May 15 |
olle |
320 |
} |
3352 |
26 May 15 |
olle |
321 |
|
3352 |
26 May 15 |
olle |
exutils.findSeparator = function(data, searchString) |
3352 |
26 May 15 |
olle |
323 |
{ |
3352 |
26 May 15 |
olle |
// Searches for the first line containing the input search string, then returns next character as separator |
3352 |
26 May 15 |
olle |
var separator = null; |
3352 |
26 May 15 |
olle |
if (data != null && searchString != null) |
3352 |
26 May 15 |
olle |
327 |
{ |
3352 |
26 May 15 |
olle |
var lines = data.split(/[\n\r]+/); |
3352 |
26 May 15 |
olle |
var found = false; |
3352 |
26 May 15 |
olle |
for (var i = 0; (i < lines.length && !found); i++) |
3352 |
26 May 15 |
olle |
331 |
{ |
3352 |
26 May 15 |
olle |
if (lines[i].match(/^\s*$/)) continue; // Ignore empty lines |
3352 |
26 May 15 |
olle |
var line = lines[i]; |
3352 |
26 May 15 |
olle |
var index = line.indexOf(searchString); |
3352 |
26 May 15 |
olle |
if (index >= 0) |
3352 |
26 May 15 |
olle |
336 |
{ |
3352 |
26 May 15 |
olle |
// Get next character after first column header as separator |
3352 |
26 May 15 |
olle |
var separatorIndex = index + searchString.length; |
3352 |
26 May 15 |
olle |
separator = line.substring(separatorIndex, separatorIndex+1); |
3352 |
26 May 15 |
olle |
found = true; |
3352 |
26 May 15 |
olle |
341 |
} |
3352 |
26 May 15 |
olle |
342 |
} |
3352 |
26 May 15 |
olle |
343 |
} |
3352 |
26 May 15 |
olle |
return separator; |
3352 |
26 May 15 |
olle |
345 |
} |
3352 |
26 May 15 |
olle |
346 |
|
5313 |
27 Feb 19 |
olle |
exutils.findSeparatorFromJSONArray = function(data, jsonKey) |
5313 |
27 Feb 19 |
olle |
348 |
{ |
5313 |
27 Feb 19 |
olle |
// Searches for the first occurrence of comma, semicolon, or tab in the first line of data |
5313 |
27 Feb 19 |
olle |
var separator = null; |
5313 |
27 Feb 19 |
olle |
//alert("extraction_utils.js::findSeparatorFromJSONArray(): jsonKey = '" + jsonKey + "' data = '" + JSON.stringify(data) + "'."); |
5313 |
27 Feb 19 |
olle |
if (data != null) |
5313 |
27 Feb 19 |
olle |
353 |
{ |
5313 |
27 Feb 19 |
olle |
var lines = data[jsonKey]; |
5313 |
27 Feb 19 |
olle |
var found = false; |
5313 |
27 Feb 19 |
olle |
for (var i = 0; (i < lines.length && !found); i++) |
5313 |
27 Feb 19 |
olle |
357 |
{ |
5313 |
27 Feb 19 |
olle |
if (lines[i].match(/^\s*$/)) continue; // Ignore empty lines |
5313 |
27 Feb 19 |
olle |
var line = lines[i]; |
5313 |
27 Feb 19 |
olle |
var index = 1000000; |
5313 |
27 Feb 19 |
olle |
var commaIndex = line.indexOf(","); |
5313 |
27 Feb 19 |
olle |
var semicolonIndex = line.indexOf(";"); |
5313 |
27 Feb 19 |
olle |
//var tabChar = "\\t"; |
5313 |
27 Feb 19 |
olle |
var tabChar = String.fromCharCode(9); |
5313 |
27 Feb 19 |
olle |
var tabIndex = line.indexOf(tabChar); |
5313 |
27 Feb 19 |
olle |
//alert("extraction_utils.js::findSeparatorFromJSONArray(): line[" + i + "] = '" + line + "' commaIndex = " + commaIndex + " semicolonIndex = " + semicolonIndex + " tabIndex = " + tabIndex + "."); |
5313 |
27 Feb 19 |
olle |
if (commaIndex >= 0) |
5313 |
27 Feb 19 |
olle |
368 |
{ |
5313 |
27 Feb 19 |
olle |
index = commaIndex; |
5313 |
27 Feb 19 |
olle |
separator = ","; |
5313 |
27 Feb 19 |
olle |
found = true; |
5313 |
27 Feb 19 |
olle |
372 |
} |
5313 |
27 Feb 19 |
olle |
if (semicolonIndex >= 0 && semicolonIndex < index) |
5313 |
27 Feb 19 |
olle |
374 |
{ |
5313 |
27 Feb 19 |
olle |
index = semicolonIndex; |
5313 |
27 Feb 19 |
olle |
separator = ";"; |
5313 |
27 Feb 19 |
olle |
found = true; |
5313 |
27 Feb 19 |
olle |
378 |
} |
5313 |
27 Feb 19 |
olle |
if (tabIndex >= 0 && tabIndex < index) |
5313 |
27 Feb 19 |
olle |
380 |
{ |
5313 |
27 Feb 19 |
olle |
index = tabIndex; |
5313 |
27 Feb 19 |
olle |
separator = tabChar; |
5313 |
27 Feb 19 |
olle |
found = true; |
5313 |
27 Feb 19 |
olle |
384 |
} |
5313 |
27 Feb 19 |
olle |
385 |
} |
5313 |
27 Feb 19 |
olle |
386 |
} |
5313 |
27 Feb 19 |
olle |
return separator; |
5313 |
27 Feb 19 |
olle |
388 |
} |
5313 |
27 Feb 19 |
olle |
389 |
|
3352 |
26 May 15 |
olle |
exutils.setDecimalDotInsideDoubleQuotes = function(line) |
3352 |
26 May 15 |
olle |
391 |
{ |
3352 |
26 May 15 |
olle |
var lineParts = line.split(/ *" */); |
3352 |
26 May 15 |
olle |
var procLine = lineParts[0]; |
3352 |
26 May 15 |
olle |
var numAddedDblQts = 0; |
3352 |
26 May 15 |
olle |
for (var i = 1; i < lineParts.length; i++) |
3352 |
26 May 15 |
olle |
396 |
{ |
3352 |
26 May 15 |
olle |
var str = lineParts[i]; |
3352 |
26 May 15 |
olle |
if (i % 2 == 1) |
3352 |
26 May 15 |
olle |
399 |
{ |
3352 |
26 May 15 |
olle |
// Inside double quotes |
3352 |
26 May 15 |
olle |
// Replace decimal comma with decimal dot |
3352 |
26 May 15 |
olle |
str = str.replace(/,/, '.'); |
3352 |
26 May 15 |
olle |
403 |
} |
3352 |
26 May 15 |
olle |
// Add string to processed line |
3352 |
26 May 15 |
olle |
procLine += '"' + str; |
3352 |
26 May 15 |
olle |
numAddedDblQts++; |
3352 |
26 May 15 |
olle |
407 |
} |
3352 |
26 May 15 |
olle |
if (numAddedDblQts % 2 == 1) |
3352 |
26 May 15 |
olle |
409 |
{ |
3352 |
26 May 15 |
olle |
// Add terminal double quote |
3352 |
26 May 15 |
olle |
procLine += '"'; |
3352 |
26 May 15 |
olle |
412 |
} |
3352 |
26 May 15 |
olle |
// Return processed line |
3352 |
26 May 15 |
olle |
return procLine; |
3352 |
26 May 15 |
olle |
415 |
} |
3352 |
26 May 15 |
olle |
416 |
|
3352 |
26 May 15 |
olle |
exutils.getNumber = function(sValue) |
3352 |
26 May 15 |
olle |
418 |
{ |
3352 |
26 May 15 |
olle |
return parseFloat(sValue.replace(/,/, '.')); |
3352 |
26 May 15 |
olle |
420 |
} |
3352 |
26 May 15 |
olle |
421 |
|
3352 |
26 May 15 |
olle |
return exutils; |
3352 |
26 May 15 |
olle |
423 |
}(); |
3352 |
26 May 15 |
olle |
424 |
|
3352 |
26 May 15 |
olle |
//Doc.onLoad(ExtractUtils.initPage); |
3352 |
26 May 15 |
olle |
426 |
|