Repository navigation
Expand file tree
/
Copy pathCOSMiCS_multi.m
More file actions
1577 lines (1276 loc) · 42.9 KB
/
Copy pathCOSMiCS_multi.m
File metadata and controls
1577 lines (1276 loc) · 42.9 KB
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
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
clear all;
clc;
disp('****************************************************************************************************');
disp('** STRUCTURAL ANALYSIS OF MULTICOMPONENT AMYLOID SYSTEMS BY CHEMOMETRIC SAXS DATA DECOMPOSITION **');
disp('****************************************************************************************************');
disp(' ');
%% Selection of folders of multiple experiments
% Input the number of experiments
disp( 'Please enter the number of experiments performed');
numexp = input('Number of experiments[1] ');
if isempty(numexp)
numexpv = 1;
end
numexpv = numexp;
% Selection of multiple folders and reading the files of all the
% experiments
for k=1:numexpv
fprintf( 'Select the folder containing the data from experiment number %d (press any key to continue)\n', k);
pause;
folderInput = uigetdir('/home/');
foldernames{k} = folderInput;
disp([ 'Directory: ', folderInput]);
disp(' ');
disp(' ');
display(folderInput);
disp('Files inside');
disp(' ');
listing = dir(folderInput);
for i=3:5
display(listing(i).name);
end
display('...');
for i=(length(listing)-3):length(listing)
display(listing(i).name);
end
disp(' ');
str = 'What is the pattern of the files (e.g. curve*.dat ) ?? ';
patron = input(str,'s');
if isempty(patron)
patron = 'curve*.dat';
end
end
% Selection of output folder
disp( 'Where do you want to save the output? (press any key to continue)');
pause;
folderOutput = uigetdir('../');
folderOutput = [folderOutput, '/'];
OutputFolder = folderOutput;
disp([ 'Directory: ', folderOutput]);
disp(' ');
%% Selection of the pattern of the files
%% Charge curves
% Initialization
OutFilesList = [];
foldernameslist = {};
NumberofCurvesPerExperimentlist = zeros(numexpv+1,1);
for a = 1:numexpv
filePattern = fullfile(foldernames{a}, patron);
OutFiles = dir(filePattern);
NumberofCurvesPerExperiment = length(OutFiles);
[filepath,name,ext] = fileparts(filePattern);
foldernameslist = [foldernameslist;filepath];
OutFilesList = [OutFilesList; OutFiles];
NumberofCurvesPerExperimentlist(a+1,1) = NumberofCurvesPerExperiment;
end
ExperimentRanges(:,1) = cumsum(NumberofCurvesPerExperimentlist);
curvesInitial = cell(length(OutFilesList),1);
curves = cell(length(OutFilesList),1);
filePattern = fullfile(foldernames{a}, patron);
OutFiles = dir(filePattern);
basefilename = OutFilesList(1).name;
foldername = foldernames{1};
fullFileName = fullfile(foldername,basefilename);
textillo = ['dbtype ' fullFileName, ' 1:10'];
eval(textillo);
% Select number of header lines
disp(' ');
num = input('Number of header lines [3]: ');
if isempty(num)
num = 3;
end
headerLines = num;
% Add SAXS curves
disp(' ');
num = input('Number of columns [3]: ');
if isempty(num)
num = 3;
end
columns = num;
columnsvariable = ['indata = textscan(fid, '''];
for k = 1:columns
columnsvariable = [columnsvariable, '%f '];
end
columnsvariable = [columnsvariable, ''', ''HeaderLines'',headerLines);'];
for k = 1:numexp
for curvenumber = ExperimentRanges(k)+1:ExperimentRanges(k+1)
basefilename = OutFilesList(curvenumber).name;
foldername = foldernameslist{k};
fullFileName = fullfile(foldername,basefilename);
fid = fopen(fullFileName,'rt');
eval(columnsvariable);
fclose(fid);
for i = 1:columns
curvesInitial{curvenumber,1}(:,i) = indata{i};
end
end
end
% % Check length of the curves
%
% % Sometimes the curves have different number of datapoints, we have to
% % put all with the same number of datapoints. We compare the length of all
% % curves with the first one. If someone is not equal long we remove the
% % final points so we get all curves with the same length. Check S values
% % after
for i=1:length(curvesInitial)
long(i,:) = size(curvesInitial{i,1});
esIgual(i,1) = isequal(long(1,1),long(i,1));
end
if all(esIgual(:)) == 0 %alguna de las curvas tiene distinto tamanyoo/Some of the curves have different s value
puntosCurvasExp = min(long(:,1));
for i=1:length(curvesInitial)
compS(i,1) = isequal(curvesInitial{1,1}(1:puntosCurvasExp,1),curvesInitial{i,1}(1:puntosCurvasExp,1));
end
if all(compS(:,1)) == 1 %los valores S concuerdan/the S values agree
for i=1:length(curvesInitial)
curvesFinal{i,1}(1:puntosCurvasExp,:) = curvesInitial{i,1}(1:puntosCurvasExp,:);
end
else % los valores S no concuerdan/the S values don't agree
clear idx;
for n=1:length(curvesInitial)
firstValoresSall(1,n) = curvesInitial{n,1}(1,1);
[biggerS index] = max(firstValoresSall);
idx(n,1) = find(curvesInitial{n}(:,1) == biggerS );
curvesFinal{n,1} = curvesInitial{n,1}(idx(n,1):end,:);
end
for i=1:length(curves)
long(i,:) = size(curves{i,1});
esIgual(i,1) = isequal(long(1,1),long(i,1));
end
if all(esIgual(:)) == 0 %alguna de las curvas tiene distinto tamanyo
puntosCurvasExp = min(long(:,1));
for j=1:length(curves)
curvesFinal{j,1} = curves{j,1}(1:puntosCurvasExp,:);
end
else
for j=1:length(curves)
curvesFinal{j,1} = curves{j,1};
end
end
end
end
A = exist('curvesFinal','var');
if A==0
curvesFinal = curvesInitial;
end
for i=1:length(curvesFinal)
Intensities(:,i) = curvesFinal{i,1}(:,2);
if columns >=3
Errors(:,i) = curvesFinal{i,1}(:,3);
end
end
%% Normalize Intensities
%Get the list of I0 values
I0values = Intensities(1,:);
I0values = transpose(I0values);
I0minperExperiment = min(I0values);
for i = 1:length(Intensities(1,:))
Intensities(:,i) = Intensities(:,i)*100/I0minperExperiment;
Errors(:,i) = Errors(:,i)*100/I0minperExperiment;
end
valoresS(:,1) = curvesFinal{1,1}(:,1);
curvasTotales = length(curvesFinal);
fprintf('\nYou added %s files\n\n', num2str(curvasTotales));
%% Scale the two experiments
scalefactor = zeros(ExperimentRanges(end),1);
for i = 1:length(Intensities(1,:))
scalefactor(i,1) = Intensities(20,i)/min(Intensities(20,:));
Intensities(:,i) = Intensities(:,i)/scalefactor(i,1);
Errors(:,i) = Errors(:,i)/scalefactor(i,1);
end
scalefilename = fullfile(folderOutput, 'scale.txt');
dlmwrite(scalefilename, scalefactor);
% scalefactor = zeros(ExperimentRanges(2),1);
% % get the lowest curve
% [M,I] = min(Intensities(1,:));
% for i = 1:length(Intensities(1,:))
% f1 = sum(Intensities(:,I).*Intensities(:,i)./Errors(:,I).^2);
% f2 = sum(Intensities(:,i).^2./Errors(:,I).^2);
% %scalefactor(i,1) = valoresI(1,i)/min(valoresI(1,:));
% scalefactor(i,1) = f2/f1;
% % scalefactor = ones(ExperimentRanges(2),1);
% Intensities(:,i) = Intensities(:,i)/scalefactor(i,1);
% Errors(:,i) = Errors(:,i)/scalefactor(i,1);
% end
% scalefilename = fullfile(folderOutput, 'scale.txt');
% dlmwrite(scalefilename, scalefactor);
% Plot curves in semi-logarithmic scale
disp(' ');
str = 'Do you want to see the curves (semi-logarithmic scale)?? [Y]/N: ';
respuesta = input(str,'s');
if isempty(respuesta)
respuesta = 'y';
end
if respuesta =='y'
seleccion = 2;
plots;
end
seleccion = 2;
plots;
disp('Curves (semi-logarithmic scale)... Press any key to continue ');
pause;
%% Check units
control = 0;
while control == 0
disp(' ');
str = 'Units of your curves: 1/Angstrom [A] or 1/nanometers (N): ';
units = input(str,'s');
if isempty(units)
units = 'A';
end
if units == 'a' || units == 'A'
units = 'A';
control = 1;
elseif units == 'n' || units == 'N'
units = 'N';
control = 1;
end
end
control = 0;
while control == 0
disp(' ');
str = 'Do you want to change the units?? Y/[N]: ';
respuesta = input(str,'s');
if isempty(respuesta)
respuesta = 'n';
end
if respuesta =='y' || respuesta =='Y'
control = 1;
if units == 'A'
units = 'N';
valoresS = valoresS*10;
disp('Now the units are nanometers');
elseif units == 'N'
units = 'A';
valoresS = valoresS/10;
disp('Now the units are Angstroms');
end
elseif respuesta == 'n' || respuesta == 'N'
control = 1;
end
end
%% Remove points at the beginning
close all;
seleccion = 2;
plots;
disp(' ');
str = 'Do you want to eliminate some data points at the beginning?? [Y]/N: ';
respuesta = input(str,'s');
if isempty(respuesta)
respuesta = 'y';
end
if respuesta=='y' || respuesta =='Y'
valoresIcopy = Intensities;
valoresScopy = valoresS;
if columns >=3
valoresEcopy = Errors;
end
likeIt = 'n';
while likeIt~= 'y'
seleccion = 2;
plots;
disp(' ');
elimPoints = input('Number of data points [0]: ');
close all;
if isempty(elimPoints)
elimPoints = 0;
end
if elimPoints ~=0
Intensities(1:elimPoints,:) = [];
valoresS(1:elimPoints,:) = [];
if columns >=3
Errors(1:elimPoints,:) = [];
end
puntosCurvasExp = length(Intensities);
else
elimPoints = 0;
end
seleccion = 2;
plots;
disp(' ');
str = 'Do you like it?? Y/[N]: ';
likeIt = input(str,'s');
if isempty(likeIt)
likeIt = 'n';
end
if likeIt == 'Y'
likeIt = 'y';
else
Intensities = valoresIcopy;
valoresS = valoresScopy;
if columns >=3
Errors = valoresEcopy;
end
end
end
else
elimPoints = 0;
end
valoresIActual = Intensities;
% NOTE: From here I will use always the values in valoresS, valoresI and
% valoresE but I kept the variable curvasFibrilacion with the original data
%% Cut matrices
pointsAbs = length(Intensities);
pointsHoltzer = pointsAbs;
pointsKratky = pointsAbs;
pointsPorod = pointsAbs;
seleccion = 1;
plots;
disp(' ');
str = 'Do you want to cut the matrices?? Y/N [Y]: ';
cortar = input(str,'s');
if isempty(cortar)
cortar = 'y';
end
if (cortar == 'y' || cortar =='Y')
if units == 'N'
corteAbs = 3.0;
corteHoltzer = 1.6;
corteKratky = 1.6;
cortePorod = 1.6;
elseif units == 'A'
corteAbs = 0.50;
corteHoltzer = 0.30;
corteKratky = 0.30;
cortePorod = 0.16;
end
pointsAbs = 0;
pointsHoltzer = 0;
pointsKratky = 0;
pointsPorod = 0;
while pointsAbs == 0
if valoresS(i,1) >= corteAbs
pointsAbs = i;
end
i= i+1;
end
i=1;
while pointsHoltzer == 0
if valoresS(i,1) >= corteHoltzer
pointsHoltzer = i;
end
i= i+1;
end
i=1;
while pointsKratky == 0
if valoresS(i,1) >= corteKratky
pointsKratky = i;
end
i= i+1;
end
i=1;
while pointsPorod == 0
if valoresS(i,1) >= cortePorod
pointsPorod = i;
end
i= i+1;
end
likeIt = 'n';
close all;
seleccion = 1;
plots;
if units == 'N'
disp(' ');
disp('Default (1/nm):');
disp('Cut for Absolute scale = 3.0');
disp('Cut for Holtzer scale = 1.6');
disp('Cut for Kratky scale = 1.6');
disp('Cut for Porod scale = 0.7');
elseif units == 'A'
disp(' ');
disp('Default (1/???):');
disp('Cut for Absolute scale = 0.3');
disp('Cut for Holtzer scale = 0.16');
disp('Cut for Kratky scale = 0.16');
disp('Cut for Porod scale = 0.07');
end
str = 'Do you want default values?? [Y]/N: ';
likeIt = input(str,'s');
if (isempty(likeIt) || likeIt == 'Y' || likeIt == 'y')
likeIt = 'y';
if units == 'N'
corteAbs = 3.0;
corteHoltzer = 1.6;
corteKratky = 1.6;
cortePorod = 0.7;
elseif units == 'A'
corteAbs = 0.5;
corteHoltzer = 0.16;
corteKratky = 0.16;
cortePorod = 0.07;
end
else
pointsAbs = length(Intensities);
pointsHoltzer = pointsAbs;
pointsKratky = pointsAbs;
pointsPorod = pointsAbs;
end
while likeIt ~= 'y'
corteAbs = input('Cut for Absolute scale: ');
corteHoltzer = input('Cut for Holtzer scale: ');
corteKratky = input('Cut for Kratky scale: ');
cortePorod = input('Cut for Porod scale: ');
pointsAbs = 0;
pointsHoltzer = 0;
pointsKratky = 0;
pointsPorod = 0;
while pointsAbs == 0
if valoresS(i,1) >= corteAbs
pointsAbs = i;
end
i= i+1;
end
i=1;
while pointsHoltzer == 0
if valoresS(i,1) >= corteHoltzer
pointsHoltzer = i;
end
i= i+1;
end
i=1;
while pointsKratky == 0
if valoresS(i,1) >= corteKratky
pointsKratky = i;
end
i= i+1;
end
i=1;
while pointsPorod == 0
if valoresS(i,1) >= cortePorod
pointsPorod = i;
end
i= i+1;
end
close all;
seleccion = 1;
plots;
str = 'Do you want these values?? [Y]/N: ';
likeIt = input(str,'s');
if (isempty(likeIt) || likeIt == 'Y' || likeIt == 'y')
likeIt = 'y';
end
end
end
close all;
%% Definition of number of species (PCA)
% Principal Component Analysis
% PCA of the absolute values is the best to decide the number of species
if length(OutFilesList)<10
pcaLong = length(OutFiles);
else
pcaLong = 10;
end
for i=1:pcaLong
[uAbs,sAbs,vAbs,xAbs, SigmaAbs] = pcarep(Intensities,i);
sigmaAbs(i,1) = SigmaAbs;
end
[uAbs,sAbs,vAbs,xAbs, SigmaAbs] = pcarep(Intensities,length(Intensities(1,:)));
for i=1:length(sAbs)
eigenvalues(i,1) = sAbs(i,i);
% eigen(i,1) = i;
% eigen(i,2) = sAbs(i,i);
end
for i=1:length(uAbs)
eigenvectors(i,1) = i;
end
% Save eigenvectors
for i=1:pcaLong
% j = i+1;
eigenvectors(:,i) = uAbs(:,i);
end
% Save text files
mkdir(folderOutput);
ruta = [folderOutput,'eigenvalues.txt'];
save(ruta, 'eigenvalues', '-ASCII');
% ruta = [folderOutput,'sigma.txt'];
% save(ruta, 'sigmaAbs', '-ASCII');
ruta = [folderOutput,'eigenvectors.txt'];
save(ruta, 'eigenvectors', '-ASCII');
% Elimine first column with the counter of first column so we keep the eigenvectors as variables
eigenvectors(:,1) = [];
% Plot PCA results (eigenvalues)
disp(' ');
str = 'Do you want to see the results of PCA?? Y/N [Y]: ';
respuesta = input(str,'s');
if isempty(respuesta)
respuesta = 'y';
end
if (respuesta=='y'|| respuesta =='Y')
% Plot eigenvalues
figure();
bar(eigenvalues(1:pcaLong,1));
title('Eigenvalues');
text(9,eigenvalues(1,1), num2str(eigenvalues(1:pcaLong,:)),'HorizontalAlignment','left','VerticalAlignment','baseline');
% % Plot sigma
% figure();
% bar(sigmaAbs(1:pcaLong,1));
% title('Sigma');
% text(9,sigmaAbs(1,1), num2str(sigmaAbs(1:pcaLong,:)),'HorizontalAlignment','left','VerticalAlignment','baseline');
% Plot eigenvectors
figure();
subplot(5,1,1);
title('Eigenvectors');
for i= 1:5
subplot(5,1,i);
plot(eigenvectors(:,i));
end
subplot(5,1,1);
title('Eigenvectors');
disp('Press any key to continue');
pause;
end
%% Select number of species
disp(' ');
num = input('Number of species [3]: ');
if isempty(num)
numeroEspecies = 3;
else
numeroEspecies = num;
end
close all;
%% Definition of initial estimations
disp('Selection Method for Initial Estimates');
disp('For Pure based selection enter 1 ');
disp('For Chi based selection enter 2 (Currently only available for 3 species)');
InitEstmethod = input('How would you like to generate the initial estimates: ');
if InitEstmethod == 1
% Run pure for doing an estimation
close all;
disp(' ');disp(' ');
disp('Calculating initial estimations');
disp(' ');
for i=1:length(OutFiles)
fprintf('Curve %s - %s\n',num2str(i), OutFiles(i).name);
end
disp(' ');
disp(' ');
[pureAbs, curvasEstInic(1,:)] = pure(valoresIActual,numeroEspecies,5);
legendCell = ' ';
for i=1:numeroEspecies
semilogy(valoresS, valoresIActual(:,curvasEstInic(i)));
legendCell=[legendCell, '''curve ',num2str(curvasEstInic(i))];
legendCell=[legendCell, ''''];
if i<numeroEspecies
legendCell=[legendCell, ','];
end
hold on;
end
texto = ['legend(', legendCell,')'];
eval(texto);
title('Initial estimations');
pause;
%
str = ['\nDo you want to use the initial estimations selected by pure?? [', num2str(curvasEstInic), '] [Y]/N: '];
respuesta = input(str,'s');
if isempty(respuesta)
respuesta = 'y';
pureOK = 1;
end
close all;
correct = 'n';
if respuesta=='n'
pureOK = 0;
while correct == 'n'
for i=1:length(OutFiles)
fprintf('Curve %s - %s\n',num2str(i), OutFiles(i).name);
end
disp(' ');
disp('Introduce the curves that you want as initial estimations: ');
i=1;
while i<=numeroEspecies
k = input('Initial estimation: ');
if k<=curvasTotales
curvasEstInic(1,i) = k;
i=i+1;
else
fprintf(2,'This curve does not exist!!! Must be equal or smaller than %s\n', num2str(curvasTotales));
end
end
figure();
legendCell = ' ';
semilogy(valoresS, valoresIActual(:,curvasEstInic(i)));
legendCell=[legendCell, '''curve ',num2str(curvasEstInic(i))];
legendCell=[legendCell, ''''];
if i<numeroEspecies
legendCell=[legendCell, ','];
end
hold on;
texto = ['legend(', legendCell,')'];
eval(texto);
title('Initial estimations');
str = ['\nDo you want use the initial estimations selected by pure?? [', num2str(curvasEstInic), '] [Y]/N: '];
correct = input(str,'s');
if isempty(correct)
correct = 'y';
end
if correct == 'n' || correct == 'N'
close all;
end
end
else
pureOK = 1;
end
str = ['Do you want sort the curves?? [Y]/N: '];
respuesta = input(str,'s');
if isempty(respuesta)
respuesta = 'y';
end
if respuesta=='y' || respuesta == 'Y'
curvasEstInic = sort(curvasEstInic);
end
end
if InitEstmethod == 2
%Use chi based method
TwoEstimates = input('Enter two of the initial estimates (For example [1,51]) :');
ChiSelection;
curvasEstInic = PureComponents;
pureAbs = Intensities(:,PureComponents);
pureOK = 0;
end
%% Select constraints
numMatrices = 2;
nsign = numeroEspecies;
tipoALS = 0;
while (tipoALS ~= 1) && (tipoALS ~= 2) && (tipoALS ~= 3) && (tipoALS ~= 4)
disp('');
disp('');
disp('Type of experiment');
disp('(1) Fibrillation or folding (default) (Non-negativity for conc and spectra, closure=1)');
disp('(2) Titration (Non-negativity for conc and spectra, closure, selectivity)');
disp('(3) SEC-SAXS experiment (Non-negativity for conc and spectra)');
disp('(4) User Defined Constraints (Non-negativity=1, Unimodality=2, closure=3, selectivity=4)');
tipoALS = input('Select type of experiment: ');
%tipoALS = 1;
if isempty(tipoALS)
tipoALS = 1;
end
end
if(tipoALS == 1)
fprintf('\n');
disp('Standard options for fibrillation or folding:');
disp('- Non-negativity (fnnls) for concentrations and spectra');
disp('- Closure for concentrations (equal to 1.0)');
disp('Press any key to continue');
constraints = [1,3];
%pause;
end
if(tipoALS == 2)
fprintf('\n');
disp('Standard options for titration:');
disp('- Non-negativity (fnnls) for concentrations and spectra');
disp('- Selectivity for concentrations');
disp('- Closure with input concentrations and stoichiometry');
constraints = [1,3,4];
%pause;
end
if(tipoALS == 3)
disp('\n\nStandard options for SEC-SAXS experiment:');
disp('- Non-negativity (fnnls) for concentrations and spectra');
disp('- No closure. No Normalization');
constraints = [1];
%pause;
moduloSECSAXS;
end
if(tipoALS == 4)
constraints = input('Enter the constraints to use :');
end
%% Import Closure Restraints
c = find(constraints == 3);
if ~isempty(c)
disp(' ');
% str = 'Do you want to use closure?? Y/N [Y]: ';
% respuesta = input(str,'s');
% if isempty(respuesta)
% respuesta = 'y';
% end
% if (respuesta=='y'|| respuesta =='Y')
InFilesList = [];
disp(' ');
str = 'What is the pattern of the files for closure input(e.g. *.txt ) ?? ';
pattern = input(str,'s');
if isempty(patron)
patron = '*.txt';
end
for a = 1:numexpv
filePattern = fullfile(foldernames{a}, pattern);
InFiles = dir(filePattern);
InFilesList = [InFilesList; InFiles];
end
ConcConsAll = [];
for k = 1:length(InFilesList)
basefilename = InFilesList(k).name;
%foldername = InFilesList(k).folder;
foldername = foldernames{k};
fullFileName = fullfile(foldername,basefilename);
delimiter = ' ';
formatSpec = '%f%f%f%[^\n\r]';
fileID = fopen(fullFileName,'rt');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'MultipleDelimsAsOne', true, 'ReturnOnError', false);
fclose(fileID);
ConcCons = [dataArray{1:end-1}];
ConcConsAll = vertcat(ConcConsAll, ConcCons);
clearvars filename delimiter formatSpec fileID dataArray ans;
end
str=input('\nWhat is the stoichiometry of the system (e.g. [1,1,1])??:');
sto1 = str;
%% Generate scaled closure
vclos1 = zeros(ExperimentRanges(3),2);
for i = 1:ExperimentRanges(2)
vclos1(i,1)= ConcConsAll(1,1)/scalefactor(i,1);
end
for i = ExperimentRanges(2)+1:ExperimentRanges(3)
vclos1(i,2) = ConcConsAll(ExperimentRanges(2)+1,2)/scalefactor(i,1);
end
else
vclos1 = zeros(ExperimentRanges(end),2);
end
%% Equality constrain (optional)
c = find(constraints == 5);
if isempty(c)
fijar = 'n';
curvasFijadas = 0;
end
if ~isempty(c)
fijar = input('\nDo you want to fix any species? Y/[N]: ','s');
if (fijar == 'y' || fijar == 'Y')
j=1;
for i=1:numeroEspecies
fprintf('\nInitial estimation #%s - curve %s (%s)\n', num2str(i), num2str(curvasEstInic(i)), OutFiles(curvasEstInic(i)).name); fijarYN = input('Do you want to fix this species? Y/[N] ','s');
if isempty(fijarYN)
fijarYN = 'n';
end
if (fijarYN == 'y' || fijarYN == 'Y')
curvasFijadas = 1;
curvasFijadas2(i) = 1;
curvasFijadas3(j) = curvasEstInic(i);
j = j+1;
else
curvasFijadas2(i) = 0;
end
end
% curvasFijadas = input('Which curve(s) do you want to fix (e.g. sp 1 and 12, [1 12])?? [0 for none, by default]: ');
if isempty(curvasFijadas)
curvasFijadas = 0;
end
else
curvasFijadas = 0;
end
end
%% Selectivity Constraint
c = find(constraints == 4);
if ~isempty(c)
% disp(' ');
% str = 'Do you want to use Selectivity?? Y/N [N]: ';
% Selectivity = input(str,'s');
% if isempty(Selectivity)
% Selectivity = 'n';
% end
% if Selectivity=='Y' | Selectivity =='y';
% disp (' ');
Selectivity = 'y';
SelectiveCurves = input ('Enter the curve numbers to apply selectivity restraint e.g. [1,51] :');
disp ('')
else
Selectivity = 'n';
end
% %% Select constraints
%
% numMatrices = 2;
% nsign = numeroEspecies;
%
% tipoALS = 0;
%
% while (tipoALS ~= 1) && (tipoALS ~= 2) && (tipoALS ~= 3)
% disp('');
% disp('');
% disp('Type of experiment');
% disp('(1) Fibrillation or folding (default)');
% disp('(2) Titration');
% disp('(3) SEC-SAXS experiment');
% disp('(4) User Defined Constraints');
% tipoALS = input('Select type of experiment: ');
% %tipoALS = 1;
% if isempty(tipoALS)
% tipoALS = 1;
% end
% end
%
% if(tipoALS == 1)
% fprintf('\n');
% disp('Standard options for fibrillation or folding:');
% disp('- Non-negativity (fnnls) for concentrations and spectra');
% disp('- Closure for concentrations (equal to 1.0)');
% disp('Press any key to continue');
% constraints = [1,3];
% %pause;
%
% end
%
% if(tipoALS == 2)
% fprintf('\n');
% disp('Standard options for titration:');
% disp('- Non-negativity (fnnls) for concentrations and spectra');
% disp('- Selectivity for concentrations');
% disp('- Closure with input concentrations and stoichiometry');
% constraints = [1,3,4];
% %pause;
% end
%
% if(tipoALS == 3)
% disp('\n\nStandard options for SEC-SAXS experiment:');
% disp('- Non-negativity (fnnls) for concentrations and spectra');
% disp('- No closure. No Normalization');
% constraints = [1];
% %pause;
%
% moduloSECSAXS;
% end
%% Convergence criterion
disp(' ');
num = input('Convergence criterion (0.01% by default): ');
if isempty(num)
tolsigma = 0.01;
else
tolsigma = num;
end
% Number of iterations