-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
605 lines (531 loc) · 16.8 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
<!doctype html><html><head>
<meta charset=utf8>
<title>orbitrap</title>
<script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/exceljs/4.4.0/exceljs.min.js"
integrity="sha512-dlPw+ytv/6JyepmelABrgeYgHI0O+frEwgfnPdXDTOIZz+eDgfW07QXG02/O8COfivBdGNINy+Vex+lYmJ5rxw=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
></script>
<style>
@keyframes animacio{
from{
background-color: orange;
}
to{
background-color: yellow;
}
}
div[treballant]{
animation-name: animacio;
animation-duration: 2s;
animation-iteration-count: infinite;
}
hr{
border:none;
border-top:1px solid #ccc;
}
[center]{
text-align:center;
}
[number]{
text-align:right;
font-family:monospace;
}
[ms]{
font-family:monospace;
}
[yellow=true]{
background:gold;
}
label:hover{
background:gold;
}
[hover_underline]:hover{
text-decoration:underline;
cursor:pointer;
color:blue;
}
</style>
</head><body>
<nav>
<b>pàgina en construcció</b> |
<a href="standards.html" target="_blank">veure llista standards</a>
</nav><hr>
<div>
<b>PROCESSAR ARXIUS ORBITRAP</b>
</div><hr>
<div id=app>
<!--boto carregar excel-->
<div v-if="!treballant && sheets_processats==0">
<p>
Peak Label <input v-model="peak_label" style="field-sizing:content">
</p>
<input type=file @change="load_excel($event)">
</div>
<div v-if="error" style="background:red">
{{error}}
</div>
<div v-if="treballant" treballant>
<div>⏳ treballant...</div>
</div>
<div v-if="sheets_processats">
Sheets processed: {{sheets_processats}}
—
Peak Label = {{peak_label}}
</div><hr>
<div v-if="sheets">
<!--checkboxes calcurve, mm, etc-->
<div>
<span v-for="fn in get_filenames" class=filename>
<label>
<input
type=checkbox
:checked="filenames_seleccionats.has(fn)"
@change="filenames_seleccionats[!filenames_seleccionats.has(fn)?'add':'delete'](fn)"
> {{fn}}
</label>
</span>
</div><hr>
<!--filtres-->
<div
style="
display:grid;
grid-template-columns:repeat(3,1fr);
grid-gap:5px;
"
>
<!--filtre_nom_compost-->
<div>
<label>
Filtrar resultats per nom compost<br>
<input v-model="filtre_nom_compost"
style="
field-sizing: content;
min-width:50px;
"
:yellow="filtre_nom_compost!=''"
placeholder="nom compost"
>
<button @click="filtre_nom_compost=''" :disabled="filtre_nom_compost==''">X</button>
</label><br>
</div>
<!--checkbox filtres regressio-->
<div>
<label>
<input type=checkbox v-model="veure_nomes_sheets_amb_regressio">
Filtrar resultats per regressió lineal
</label><br>
<label>
r<sup>2</sup> llindar
<input type=number :disabled="veure_nomes_sheets_amb_regressio==false" v-model="r_squared_threshold">
</label>
</div>
<!--limits recovery-->
<div>
<table border=1 style="border-collapse:collapse">
<tr>
<td rowspan=3 center>
<label>
<input type=checkbox v-model="recovery_thresholds">
Recovery llindars
</label>
</td>
</tr>
<tr>
<td>low</td>
<td>
<label>
<input type=number v-model="recovery_threshold_lo" :disabled="!recovery_thresholds" placeholder="Recovery threshold low">%
</label>
</td>
</tr>
<tr>
<td>high</td>
<td>
<label>
<input type=number v-model="recovery_threshold_hi" :disabled="!recovery_thresholds" placeholder="Recovery threshold high">%
</label>
</td>
</tr>
</table>
</div>
</div><hr>
<div style="margin-top:5px">
<b>Resultats ({{get_sheets_filtrats.length}}/{{sheets.length}})</b>
</div>
<table border=1>
<tbody v-for="sheet in get_sheets_filtrats">
<tr>
<td ms>
<span hover_underline @click="filtre_nom_compost=sheet.nom">{{sheet.nom}}</span>
</td>
<td style="vertical-align:top">
<table
border=1
style="
font-size:smaller;
border-collapse:collapse;
"
>
<tr>
<td>filename</td>
<td>area</td>
<td>ppb calculat</td>
<td>
ppb calculat<br>
<small>(aplicant recovery)</small>
</td>
</tr>
<tbody v-for="row in sheet.rows">
<tr v-for="ppb_calc in [quantifica_area(sheet,row.area)]">
<td ms>
{{row.filename}}
</td>
<td number>
{{row.area}}
</td>
<td number>
{{ppb_calc}}
</td>
<td
v-if="families_where_recovery_is_applied.includes(row.family)"
number
>
<div v-for="rec in [sheet.recovery]">
<div v-if="rec">
{{ppb_calc*rec/100}}
</div>
</div>
</td>
</tr>
</tbody>
</table>
</td>
<!--taules regressio i recovery-->
<td style="vertical-align:top">
<div v-for="tipus_regressio in ['CC','MM']">
<div v-if="sheet.regressio[tipus_regressio]">
<table border=1
style="
font-size:smaller;
border-collapse:collapse;
margin-bottom:5px;
"
>
<tr>
<th colspan=2>
<small>
Regressió {{tipus_regressio}} (ppb = m·area + n)
</small>
</th>
</tr>
<tr>
<th>m</th>
<td number>{{sheet.regressio[tipus_regressio].m}}</td>
</tr>
<tr>
<th>n</th>
<td number>{{sheet.regressio[tipus_regressio].n}}</td>
</tr>
<tr>
<th>r<sup>2</sup></th>
<td number>{{sheet.regressio[tipus_regressio].r_squared}}</td>
</tr>
<tr>
<td>punts</td>
<td number>{{sheet.regressio[tipus_regressio].N}}</td>
</tr>
</table>
</div>
</div>
<table border=1
v-if="sheet.recovery"
style="
font-size:smaller;
border-collapse:collapse;
"
>
<tr>
<th>
<small>Recovery (%)</small>
</th>
<td>{{sheet.recovery}}</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<script>
function linear_regression(points){
//points: [{x,y},{x,y},...{x,y}]
let N = points.length; //number of points
if(N<3){ throw new Error("N<3 points"); }
//arrays of points
let xi = points.map(p=>p.x); //array x
let yi = points.map(p=>p.y); //array y
let xi_sq = xi.map(x=>x*x); //array x squared
let yi_sq = yi.map(y=>y*y); //array y squared
let xiyi = points.map(p=>{ //array x·y
return p.x*p.y;
});
//sums of arrays
let xi_sum = xi.reduce((p,c)=>p+c,0); //sum of x array
let yi_sum = yi.reduce((p,c)=>p+c,0); //sum of y array
let xi_sq_sum = xi_sq.reduce((p,c)=>p+c,0); //sum of x squared array
let yi_sq_sum = yi_sq.reduce((p,c)=>p+c,0); //sum of y squared array
let xiyi_sum = xiyi.reduce((p,c)=>p+c,0); //sum of x·y array
//compute m (slope) and n (intercept) as (y = mx + n)
let m = (N*(xiyi_sum) - yi_sum*xi_sum)/(N*xi_sq_sum - xi_sum*xi_sum);
let n = (yi_sum - m*xi_sum)/N;
//compute r squared
let r_squared = Math.pow(N*xiyi_sum - xi_sum*yi_sum, 2)/((N*xi_sq_sum - Math.pow(xi_sum,2))*(N*yi_sq_sum - Math.pow(yi_sum,2)));
//end
return {m, n, r_squared, N};
}
</script>
<script>
let app = Vue.createApp({
data(){return{
//filtrar per les files amb el valor "T1" a la columna "Peak Label"
peak_label:"T1",
treballant:false,
err:"", //missatge error
wb:null, //objecte workbook que ha sigut carregat
sheets_processats:0, //number
sheets:null, //array de sheets processats
filenames_seleccionats: new Set(["MM"]),
//regressio
veure_nomes_sheets_amb_regressio:true,
r_squared_threshold:0.9,
//recovery thresholds
recovery_thresholds:true,
recovery_threshold_lo: 60,
recovery_threshold_hi:120,
//filtre nom compost
filtre_nom_compost:"",
//regressio lineal: diccionari pels valors x
//MM (matrix match) i CC (calibration curve)
equiv_MM_o_CC:{
//MM
"MM_Blank_AIF": 0,
"MM_1ppb_IS_100ppb_AIF": 1,
"MM_5ppb_IS_100ppb_AIF": 5,
"MM_10ppb_IS_100ppb_AIF": 10,
"MM_50ppb_IS_100ppb_AIF": 50,
"MM_100ppb_IS_100ppb_AIF":100,
"MM_150ppb_IS_100ppb_AIF":150,
"MM_200ppb_IS_100ppb_AIF":200,
"MM_250ppb_IS_100ppb_AIF":250,
//CC
"CalCurve_1ppb_IS_100ppb_AIF": 1,
"CalCurve_1ppb_IS_100ppb_AIF_02": 1,
"CalCurve_5ppb_IS_100ppb_AIF": 5,
"CalCurve_10ppb_IS_100ppb_AIF": 10,
"CalCurve_10ppb_IS_100ppb_AIF_005_def":10,
"CalCurve_50ppb_IS_100ppb_AIF": 50,
"CalCurve_100ppb_IS_100ppb_AIF": 100,
"CalCurve_150ppb_IS_100ppb_AIF": 150,
"CalCurve_200ppb_IS_100ppb_AIF": 200,
},
families_where_recovery_is_applied:[
"Eff",
"Sand",
"Chlorination",
],
}},
methods:{
async load_excel(event){
this.treballant=true;
this.error="";
let file = event.target.files[0];
let wb = new ExcelJS.Workbook();
this.wb=wb;
try{
await wb.xlsx.load(file);
this.sheets = wb.worksheets.map(sheet=>{
return this.processa_sheet(sheet);
});
//per cada compost, calcula 2 rectes de regressió:
//una per MM i l'altra per CalCurve
this.sheets.forEach(sheet=>{
//regressio CC
let CC = this.calcula_regressio(sheet,"CalCurve"); //objecte o null
//regressio MM
let MM = this.calcula_regressio(sheet,"MM"); //objecte o null
//guarda els resultats
sheet.regressio={CC,MM};
});
//per cada compost, calcula el recovery (a,b,c)
this.sheets.forEach(sheet=>{
sheet.recovery = this.calcula_recovery(sheet);
});
this.treballant=false;
}catch(err){
this.error=err;
this.treballant=false;
}
},
processa_sheet(sheet){
/*
per cada sheet necessitem:
- nom compost
- array filename
- array area
- array peak label (i filtrar per valor=="T1")
*/
let nom = sheet.name;
try{
nom = sheet.columns[0].values[2];
}catch(err){}
//busca index columna "Filename"
let index_col_filename = sheet.columns.find(c=>c.values[1]=="Filename")._number;
//busca index columna "Area"
let index_col_area = sheet.columns.find(c=>c.values[1]=="Area")._number;
//busca index columna "Peak Label"
let index_col_peak_label = sheet.columns.find(c=>c.values[1]=="Peak Label")._number;
//filtra per "Peak Label"=="T1"
//i retorna [filename, area, peak_label]
let rows = sheet._rows.filter(r=>{
return (
r.values[index_col_peak_label] == this.peak_label
);
}).map(r=>{
let filename = r.values[index_col_filename];
let area = r.values[index_col_area];
let peak_label = r.values[index_col_peak_label];
let family = filename.split("_")[0];
return {family,filename,area,peak_label};
});
this.sheets_processats++;
return {nom,rows};
},
//adapta les dades per poder cridar "linear_regression()"
calcula_regressio(sheet, family){
family = family || "MM"; //"MM" || "CalCurve"
let rows = sheet.rows.filter(r=>r.family==family);
let punts = rows.map(r=>{
let x = r.area;
let y = this.equiv_MM_o_CC[r.filename];
return {x,y};
}).filter(p=>p.x!="N/F");
//result: {m,n,r2}
let result;
try{
result = linear_regression(punts);
}catch(err){
result = null;
}
return result;
},
calcula_recovery(sheet){
//mitjana dels recoveries
let recovery=[];//init empty array
let rows = sheet.rows.filter(r=>r.family=="Recovery");
rows.forEach(row=>{
let area = row.area; //number | string ("N/F")
if(area=="N/F") return;
let ppb = this.quantifica_area(sheet,area); //number or NaN
if(ppb===false) return;
//TODO
//if(ppb<=60 || ppb>=120) return;
recovery.push(ppb);
});
let N = recovery.length;
if(N==0) return false;
return recovery.reduce((p,c)=>p+c,0)/N;
},
//calcula PPB a partir d'àrea fent servir les regressions lineals
// PPB = m·area + n
quantifica_area(sheet, area){
//sheet:object
//area:number
let CC = sheet.regressio.CC;
let MM = sheet.regressio.MM;
//tria quina de les dues regressions es farà servir: CC ò MM
let reg = null;
if(CC && MM){
if(CC.r_squared > MM.r_squared){
reg = CC;
}else{
reg = MM;
}
}else if(!CC && MM){
reg = MM;
}else if(!MM && CC){
reg = CC;
}else{
reg = false;
}
if(!reg) return false;
//aplica formula recta (y=mx+n)
return reg.m*area + reg.n;
},
//TODO
descarregar_fitxer_final(){
let wb = new ExcelJS.Workbook();
let sh = wb.addWorksheet('Merged');
this.fitxer_final.forEach(row=>{
sh.addRow(row);
});
//export workbook to xlsx file
const fileType='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
wb.xlsx.writeBuffer().
then(buffer=>saveAs(new Blob([buffer],{type:fileType}),'fitxer_final.xlsx'))
.catch(err=>console.log('Error writing excel file',err));
},
},
computed:{
//obtenir els diferents camps dins de l'excel
get_filenames(){
if(!this.sheets) return [];
let set = new Set();
this.sheets.forEach(s=>{
s.rows.forEach(r=>{
set.add(r.family);
});
});
return Array.from(set);
},
get_sheets_filtrats(){
let sheets = this.sheets.map(s=>{
let nom = s.nom;
let rows = s.rows.filter(r=>{
return this.filenames_seleccionats.has(r.family);
});
let regressio = s.regressio;
let recovery = s.recovery;
return {nom,rows,regressio,recovery};
});
let filtre_nom_compost_uppercase = this.filtre_nom_compost.toUpperCase();
if(this.filtre_nom_compost){
sheets = sheets.filter(s=>
s.nom.toUpperCase().includes(filtre_nom_compost_uppercase)
);
}
if(this.veure_nomes_sheets_amb_regressio){
sheets = sheets.filter(s=>
(
(s.regressio.MM && s.regressio.MM.r_squared>=this.r_squared_threshold)
||
(s.regressio.CC && s.regressio.CC.r_squared>=this.r_squared_threshold)
)
);
}
if(this.recovery_thresholds){
sheets = sheets.filter(s=>
s.recovery!==false &&
(s.recovery >= this.recovery_threshold_lo)
&&
(s.recovery <= this.recovery_threshold_hi)
);
}
return sheets;
},
},
}).mount("#app");
</script>