time | calls | line |
---|
| | 1 | function [G1_a, G1_b, G1_c] = fit_Gaussian_model2(data, location, func_type, show_fitting, ploidy1x)
|
| | 2 | % Attempt to fit a single-gaussian model to data.
|
| | 3 | % Used to help determine copy number estimates for regions.
|
| | 4 |
|
| 14 | 5 | time = 1:length(data);
|
| 14 | 6 | G1_a = nan;
|
| 14 | 7 | G1_b = nan;
|
| 14 | 8 | G1_c = nan;
|
| | 9 |
|
| 14 | 10 | if isnan(data)
|
| | 11 | % fitting variables
|
| | 12 | return
|
| | 13 | end
|
| | 14 |
|
| | 15 | % find max height in data.
|
| 14 | 16 | datamax = max(data);
|
| | 17 | %datamax(data ~= max(datamax)) = [];
|
| | 18 |
|
| | 19 | % if maxdata is final bin, then find next highest p
|
| 14 | 20 | if (find(data == datamax) == length(data))
|
| | 21 | data(data == datamax) = 0;
|
| | 22 | datamax = data;
|
| | 23 | datamax(data ~= max(datamax)) = [];
|
| | 24 | end;
|
| | 25 |
|
| | 26 | % a = height; b = location; c = width.
|
| 14 | 27 | G1_ai = datamax;
|
| 14 | 28 | G1_bi = location;
|
| | 29 |
|
| | 30 | %find G1_ci; width of G1 at halfmax.
|
| 14 | 31 | dd = data;
|
| 14 | 32 | dd(data < max(data)/2) = 0;
|
| 14 | 33 | c1 = find(dd,1,'first');
|
| 14 | 34 | G1_ci = (G1_bi-c1)/sqrt(2*log(2));
|
| | 35 |
|
| 14 | 36 | initial = [G1_ai, G1_bi, G1_ci];
|
0.05 | 14 | 37 | options = optimset('Display','off','FunValCheck','on','MaxFunEvals',10000);
|
| | 38 |
|
0.21 | 14 | 39 | [Estimates,~,exitflag] = fminsearch(@fiterror, ... % function to be fitted.
|
| | 40 | initial, ... % initial x-value.
|
| | 41 | options, ... % options for fitting algorithm.
|
| | 42 | time, ... % problem-specific parameter 1.
|
| | 43 | data, ... % problem-specific parameter 2.
|
| | 44 | func_type, ... % problem-specific parameter 3.
|
| | 45 | show_fitting, ... % problem-specific parameter 4.
|
| | 46 | ploidy1x ... % problem-specific parameter 5.
|
| | 47 | );
|
| 14 | 48 | if (exitflag > 0)
|
| | 49 | % > 0 : converged to a solution.
|
| 14 | 50 | G1_a = abs(Estimates(1));
|
| 14 | 51 | G1_b = Estimates(2);
|
| 14 | 52 | G1_c = abs(Estimates(3));
|
| | 53 | else
|
| | 54 | % = 0 : exceeded maximum iterations allowed.
|
| | 55 | % < 0 : did not converge to a solution.
|
| | 56 | % return last best estimate anyhow.
|
| | 57 | G1_a = abs(Estimates(1));
|
| | 58 | G1_b = Estimates(2);
|
| | 59 | G1_c = abs(Estimates(3));
|
| | 60 | end;
|
| 14 | 61 | end
|
Other subfunctions in this file are not included in this listing.