annotate curve_fitting.py @ 4:2c185b562eed draft default tip

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:50:36 +0000
parents e08061d196ce
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e08061d196ce "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff changeset
1 """
e08061d196ce "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.
e08061d196ce "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)
e08061d196ce "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff changeset
4
e08061d196ce "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.
e08061d196ce "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
e08061d196ce "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff changeset
7
e08061d196ce "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff changeset
8 """
e08061d196ce "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff changeset
9
e08061d196ce "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
e08061d196ce "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff changeset
11
e08061d196ce "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
e08061d196ce "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
e08061d196ce "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
e08061d196ce "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff changeset
15
e08061d196ce "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff changeset
16
e08061d196ce "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):
e08061d196ce "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!'
e08061d196ce "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:
e08061d196ce "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
e08061d196ce "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:
e08061d196ce "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]
e08061d196ce "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff changeset
23
e08061d196ce "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff changeset
24
e08061d196ce "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):
e08061d196ce "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!'
e08061d196ce "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)
e08061d196ce "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':
e08061d196ce "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))
e08061d196ce "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':
e08061d196ce "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)
e08061d196ce "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':
e08061d196ce "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
e08061d196ce "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
e08061d196ce "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))
e08061d196ce "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
e08061d196ce "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff changeset
37
e08061d196ce "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff changeset
38
e08061d196ce "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'):
e08061d196ce "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!'
e08061d196ce "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!'
e08061d196ce "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff changeset
42
e08061d196ce "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])]
e08061d196ce "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:
e08061d196ce "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)
e08061d196ce "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff changeset
46
e08061d196ce "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
e08061d196ce "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')
e08061d196ce "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))
e08061d196ce "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff changeset
50
e08061d196ce "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)
e08061d196ce "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff changeset
52
e08061d196ce "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff changeset
53
e08061d196ce "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):
e08061d196ce "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
e08061d196ce "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)
e08061d196ce "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)
e08061d196ce "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 = []
e08061d196ce "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):
e08061d196ce "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])
e08061d196ce "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))
e08061d196ce "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()
e08061d196ce "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)
e08061d196ce "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff changeset
64
e08061d196ce "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
e08061d196ce "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'))
e08061d196ce "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):
e08061d196ce "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]
e08061d196ce "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()
e08061d196ce "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)
4
2c185b562eed 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
e08061d196ce "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)
e08061d196ce "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:
e08061d196ce "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]))
e08061d196ce "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff changeset
75
e08061d196ce "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
e08061d196ce "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:
e08061d196ce "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)
e08061d196ce "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
e08061d196ce "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)]
e08061d196ce "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):
e08061d196ce "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
e08061d196ce "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)
e08061d196ce "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff changeset
84
e08061d196ce "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
e08061d196ce "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:
e08061d196ce "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):
e08061d196ce "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()
e08061d196ce "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):
e08061d196ce "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]
e08061d196ce "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]
e08061d196ce "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:
e08061d196ce "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]
e08061d196ce "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')
e08061d196ce "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()
e08061d196ce "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff changeset
96
e08061d196ce "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/curve_fitting/ commit ef82d0882741042922349499cafa35d20d70ce70"
imgteam
parents:
diff changeset
97
e08061d196ce "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__":
e08061d196ce "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")
e08061d196ce "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)")
e08061d196ce "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)")
e08061d196ce "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")
e08061d196ce "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")
e08061d196ce "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")
e08061d196ce "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()
e08061d196ce "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)