Mercurial > repos > imgteam > curve_fitting
annotate curve_fitting.py @ 5:e0af18405e37 draft
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit cd63bc5e6eb7254111012209fac9154569355f20
author | imgteam |
---|---|
date | Tue, 19 Jul 2022 08:51:41 +0000 |
parents | 8bf2c507af3a |
children |
rev | line source |
---|---|
0
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
1 """ |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
2 Copyright 2021 Biomedical Computer Vision Group, Heidelberg University. |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
3 Author: Qi Gao (qi.gao@bioquant.uni-heidelberg.de) |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
4 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
5 Distributed under the MIT license. |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
6 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
7 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
8 """ |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
9 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
10 import argparse |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
11 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
12 import numpy as np |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
13 import pandas as pd |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
14 from scipy.optimize import least_squares |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
15 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
16 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
17 def compute_curve(x, par): |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
18 assert len(par) in [2, 3], 'The degree of curve must be 1 or 2!' |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
19 if len(par) == 3: |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
20 return par[0] * x + par[1] + par[2] * x ** 2 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
21 elif len(par) == 2: |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
22 return par[0] * x + par[1] |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
23 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
24 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
25 def fitting_err(par, xx, seq, penalty): |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
26 assert penalty in ['abs', 'quadratic', 'student-t'], 'Unknown penalty function!' |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
27 curve = compute_curve(xx, par) |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
28 if penalty == 'abs': |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
29 err = np.sqrt(np.abs(curve - seq)) |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
30 elif penalty == 'quadratic': |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
31 err = (curve - seq) |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
32 elif penalty == 'student-t': |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
33 a = 1000 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
34 b = 0.001 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
35 err = np.sqrt(a * np.log(1 + (b * (curve - seq)) ** 2)) |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
36 return err |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
37 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
38 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
39 def curve_fitting(seq, degree=2, penalty='abs'): |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
40 assert len(seq) > 5, 'Data is too short for curve fitting!' |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
41 assert degree in [1, 2], 'The degree of curve must be 1 or 2!' |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
42 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
43 par0 = [(seq[-1] - seq[0]) / len(seq), np.mean(seq[0:3])] |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
44 if degree == 2: |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
45 par0.append(-0.001) |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
46 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
47 xx = np.array([i for i in range(len(seq))]) + 1 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
48 x = np.array(par0, dtype='float64') |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
49 result = least_squares(fitting_err, x, args=(xx, seq, penalty)) |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
50 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
51 return compute_curve(xx, result.x) |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
52 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
53 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
54 def curve_fitting_io(fn_in, fn_out, degree=2, penalty='abs', alpha=0.01): |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
55 # read all sheets |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
56 xl = pd.ExcelFile(fn_in) |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
57 nSpots = len(xl.sheet_names) |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
58 data_all = [] |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
59 for i in range(nSpots): |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
60 df = pd.read_excel(xl, xl.sheet_names[i]) |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
61 data_all.append(np.array(df)) |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
62 col_names = df.columns.tolist() |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
63 ncols_ori = len(col_names) |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
64 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
65 # curve_fitting |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
66 diff = np.array([], dtype=('float64')) |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
67 for i in range(nSpots): |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
68 seq = data_all[i][:, -1] |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
69 seq_fit = seq.copy() |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
70 idx_valid = ~np.isnan(seq) |
5
e0af18405e37
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit cd63bc5e6eb7254111012209fac9154569355f20
imgteam
parents:
0
diff
changeset
|
71 seq_fit[idx_valid] = curve_fitting(seq[idx_valid], degree=degree, penalty=penalty) |
0
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
72 data_all[i] = np.concatenate((data_all[i], seq_fit.reshape(-1, 1)), axis=1) |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
73 if alpha > 0: |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
74 diff = np.concatenate((diff, seq_fit[idx_valid] - seq[idx_valid])) |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
75 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
76 # add assistive curve |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
77 if alpha > 0: |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
78 sorted_diff = np.sort(diff) |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
79 fac = 1 - alpha / 2 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
80 sig3 = sorted_diff[int(diff.size * fac)] |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
81 for i in range(nSpots): |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
82 seq_assist = data_all[i][:, -1] + sig3 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
83 data_all[i] = np.concatenate((data_all[i], seq_assist.reshape(-1, 1)), axis=1) |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
84 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
85 # write to file |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
86 with pd.ExcelWriter(fn_out) as writer: |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
87 for i in range(nSpots): |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
88 df = pd.DataFrame() |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
89 for c in range(ncols_ori): |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
90 df[col_names[c]] = data_all[i][:, c] |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
91 df['CURVE'] = data_all[i][:, ncols_ori] |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
92 if alpha > 0: |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
93 df['CURVE_A'] = data_all[i][:, ncols_ori + 1] |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
94 df.to_excel(writer, sheet_name=xl.sheet_names[i], index=False, float_format='%.2f') |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
95 writer.save() |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
96 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
97 |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
98 if __name__ == "__main__": |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
99 parser = argparse.ArgumentParser(description="Fit (1st- or 2nd-degree) polynomial curves to data points") |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
100 parser.add_argument("fn_in", help="File name of input data points (xlsx)") |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
101 parser.add_argument("fn_out", help="File name of output fitted curves (xlsx)") |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
102 parser.add_argument("degree", type=int, help="Degree of the polynomial function") |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
103 parser.add_argument("penalty", help="Optimization objective for fitting") |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
104 parser.add_argument("alpha", type=float, help="Significance level for generating assistive curves") |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
105 args = parser.parse_args() |
8bf2c507af3a
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff
changeset
|
106 curve_fitting_io(args.fn_in, args.fn_out, args.degree, args.penalty, args.alpha) |