import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import calculate
import data
import lmfit
import models

pd.set_option("display.precision", 5)
pd.set_option('display.width', 200)
input_data = data.load_data("JZ/data/aktivni_pokus.csv")

print(input_data)
Loading data from JZ/data/aktivni_pokus.csv
    compound         c    log c  n_reps   rep1   rep2   rep3   rep4   rep5   rep6   rep7   rep8  median        SD      SEM
0      TD139  400.0000  2.60206       6    NaN    NaN   32.0   29.0   33.0   31.0   27.0   30.0    30.5   2.16025  0.88192
1      TD139   40.0000  1.60206       6    NaN    NaN   23.0   26.0   27.0   25.0   26.0   30.0    26.0   2.31661  0.94575
2      TD139    4.0000  0.60206       8   27.0   26.0   24.0   27.0   28.0   32.0   28.0   25.0    27.0   2.41646  0.85435
3      TD139    2.0000  0.30103       2   26.0   27.0    NaN    NaN    NaN    NaN    NaN    NaN    26.5   0.70711  0.50000
4      TD139    1.0000  0.00000       2   25.0   24.0    NaN    NaN    NaN    NaN    NaN    NaN    24.5   0.70711  0.50000
5      TD139    0.5000 -0.30103       2   27.0   25.0    NaN    NaN    NaN    NaN    NaN    NaN    26.0   1.41421  1.00000
6      TD139    0.4000 -0.39794       6    NaN    NaN   25.0   29.0   29.0   29.0   26.0   29.0    29.0   1.83485  0.74907
7      TD139    0.2500 -0.60206       2   29.0   25.0    NaN    NaN    NaN    NaN    NaN    NaN    27.0   2.82843  2.00000
8      TD139    0.1200 -0.92082       2   31.0   32.0    NaN    NaN    NaN    NaN    NaN    NaN    31.5   0.70711  0.50000
9      TD139    0.0600 -1.22185       2   41.0   36.0    NaN    NaN    NaN    NaN    NaN    NaN    38.5   3.53553  2.50000
10     TD139    0.0400 -1.39794       6    NaN    NaN   44.0   43.0   44.0   51.0   52.0   52.0    47.5   4.41210  1.80123
11     TD139    0.0300 -1.52288       2   58.0   60.0    NaN    NaN    NaN    NaN    NaN    NaN    59.0   1.41421  1.00000
12     TD139    0.0150 -1.82391       2   85.0   91.0    NaN    NaN    NaN    NaN    NaN    NaN    88.0   4.24264  3.00000
13     TD139    0.0070 -2.15490       2   99.0  102.0    NaN    NaN    NaN    NaN    NaN    NaN   100.5   2.12132  1.50000
14     TD139    0.0040 -2.39794       8   98.0   97.0   93.0   92.0   97.0  102.0   98.0  104.0    97.5   4.03334  1.42600
15     TD139    0.0020 -2.69897       2  104.0  104.0    NaN    NaN    NaN    NaN    NaN    NaN   104.0   0.00000  0.00000
16     TD139    0.0004 -3.39794       6    NaN    NaN  101.0   99.0   99.0  103.0  109.0  108.0   102.0   4.40076  1.79660
17  JZ7-47-4  800.0000  2.90309       8   25.0   28.0   26.0   27.0   28.0   27.0   27.0   24.0    27.0   1.41421  0.50000
18  JZ7-47-4  400.0000  2.60206       8   26.0   28.0   28.0   27.0   26.0   28.0   27.0   23.0    27.0   1.68502  0.59574
19  JZ7-47-4  100.0000  2.00000       2   28.0   30.0    NaN    NaN    NaN    NaN    NaN    NaN    29.0   1.41421  1.00000
20  JZ7-47-4   40.0000  1.60206       6    NaN    NaN   25.0   24.0   29.0   29.0   26.0   30.0    27.5   2.48328  1.01379
21  JZ7-47-4   25.0000  1.39794       2   26.0   25.0    NaN    NaN    NaN    NaN    NaN    NaN    25.5   0.70711  0.50000
22  JZ7-47-4    6.0000  0.77815       2   24.0   27.0    NaN    NaN    NaN    NaN    NaN    NaN    25.5   2.12132  1.50000
23  JZ7-47-4    4.0000  0.60206       6    NaN    NaN   27.0   26.0   33.0   24.0   26.0   23.0    26.0   3.50714  1.43178
24  JZ7-47-4    1.5000  0.17609       2   24.0   27.0    NaN    NaN    NaN    NaN    NaN    NaN    25.5   2.12132  1.50000
25  JZ7-47-4    0.4000 -0.39794       8   26.0   32.0   32.0   30.0   31.0   27.0   26.0   27.0    28.5   2.64237  0.93422
26  JZ7-47-4    0.1000 -1.00000       2   55.0   56.0    NaN    NaN    NaN    NaN    NaN    NaN    55.5   0.70711  0.50000
27  JZ7-47-4    0.0400 -1.39794       6    NaN    NaN   94.0   98.0   97.0   63.0   67.0   67.0    80.5  16.91153  6.90411
28  JZ7-47-4    0.0250 -1.60206       2   99.0   97.0    NaN    NaN    NaN    NaN    NaN    NaN    98.0   1.41421  1.00000
29  JZ7-47-4    0.0060 -2.22185       2  102.0  101.0    NaN    NaN    NaN    NaN    NaN    NaN   101.5   0.70711  0.50000
30  JZ7-47-4    0.0040 -2.39794       6    NaN    NaN  109.0  109.0  106.0   99.0   96.0  102.0   104.0   5.39444  2.20227
31  JZ7-47-4    0.0015 -2.82391       2  104.0  108.0    NaN    NaN    NaN    NaN    NaN    NaN   106.0   2.82843  2.00000
32  JZ7-47-4    0.0004 -3.39794       6    NaN    NaN  106.0  103.0  110.0  106.0  106.0  106.0   106.0   2.22860  0.90982
33  JZ7-50-2  800.0000  2.90309       2   33.0   34.0    NaN    NaN    NaN    NaN    NaN    NaN    33.5   0.70711  0.50000
34  JZ7-50-2  400.0000  2.60206       2   29.0   29.0    NaN    NaN    NaN    NaN    NaN    NaN    29.0   0.00000  0.00000
35  JZ7-50-2  100.0000  2.00000       2   26.0   27.0    NaN    NaN    NaN    NaN    NaN    NaN    26.5   0.70711  0.50000
36  JZ7-50-2   40.0000  1.60206       6    NaN    NaN   27.0   25.0   29.0   27.0   25.0   27.0    27.0   1.50555  0.61464
37  JZ7-50-2   25.0000  1.39794       2   28.0   27.0    NaN    NaN    NaN    NaN    NaN    NaN    27.5   0.70711  0.50000
38  JZ7-50-2    6.0000  0.77815       2   22.0   30.0    NaN    NaN    NaN    NaN    NaN    NaN    26.0   5.65685  4.00000
39  JZ7-50-2    4.0000  0.60206       6    NaN    NaN   23.0   26.0   29.0   23.0   24.0   26.0    25.0   2.31661  0.94575
40  JZ7-50-2    1.5000  0.17609       2   28.0   29.0    NaN    NaN    NaN    NaN    NaN    NaN    28.5   0.70711  0.50000
41  JZ7-50-2    0.4000 -0.39794       8   29.0   28.0   26.0   34.0   32.0   30.0   29.0   30.0    29.5   2.43487  0.86086
42  JZ7-50-2    0.1000 -1.00000       2   39.0   41.0    NaN    NaN    NaN    NaN    NaN    NaN    40.0   1.41421  1.00000
43  JZ7-50-2    0.0400 -1.39794       6    NaN    NaN   77.0   69.0   74.0   65.0   73.0   71.0    72.0   4.18330  1.70783
44  JZ7-50-2    0.0250 -1.60206       2   82.0   84.0    NaN    NaN    NaN    NaN    NaN    NaN    83.0   1.41421  1.00000
45  JZ7-50-2    0.0060 -2.22185       2   99.0  103.0    NaN    NaN    NaN    NaN    NaN    NaN   101.0   2.82843  2.00000
46  JZ7-50-2    0.0040 -2.39794       6    NaN    NaN  104.0  107.0  110.0  101.0   97.0  101.0   102.5   4.67618  1.90904
47  JZ7-50-2    0.0015 -2.82391       2  103.0  103.0    NaN    NaN    NaN    NaN    NaN    NaN   103.0   0.00000  0.00000
48  JZ7-50-2    0.0004 -3.39794       6    NaN    NaN  105.0  110.0  107.0  109.0  105.0  107.0   107.0   2.04124  0.83333
compounds = input_data["compound"].unique()
print("Detected compounds:", compounds)
print("No of compounds:", len(compounds))
Detected compounds: ['TD139' 'JZ7-47-4' 'JZ7-50-2']
No of compounds: 3
RT = 0.03           # [R]T parameter
LsT = 0.005           # [L]*T parameter
Kds = 0.02164        # Kd of the probe
Kd_results = calculate.fit_Kd(input_data, model="comp_3st_specific", RT=RT, LsT=LsT, Kds=Kds, ci=True, fix_min=27, fix_max=False)
Kd_results = Kd_results.sort_values(by=['Kd'], ascending=False)
print(Kd_results)
Kd_results.to_clipboard(excel=True, sep=",")
Fitting comp_3st_specific ...
   compound  n_points       Kd     loCL     upCL       SE              model  min        max    RT    LsT      Kds       Chi^2      R^2
1  JZ7-47-4        70  0.01700  0.01316  0.02189  0.00233  comp_3st_specific   27  172.12952  0.03  0.005  0.02164  2442.67878  0.97116
2  JZ7-50-2        58  0.00927  0.00790  0.01084  0.00075  comp_3st_specific   27  171.08798  0.03  0.005  0.02164   627.58237  0.99070
0     TD139        66  0.00222  0.00182  0.00267  0.00021  comp_3st_specific   27  165.72488  0.03  0.005  0.02164   696.20233  0.98970
plt.figure(figsize=(7, 6))

data.plot(input_data, Kd_results, compound_sel=False, show_all_data=True, show_medians=False)

plt.xlabel("Log concentration")
plt.ylabel("Response")
plt.xscale("log")
plt.legend()
#plt.savefig("actives_alldata.png", dpi=150)
plt.show()

import matplotlib.pyplot as plt
import numpy as np

# Data setup
x = np.linspace(0, 10, 100)
y_list = [np.sin(x), np.cos(x), np.tan(x), np.exp(-x)]  # list of functions

# Create a 2x2 grid of subplots
fig, axes = plt.subplots(2, 2, figsize=(7, 5))  # 2 rows, 2 columns

# Flatten the 2D axes array to iterate over it
axes = axes.flatten()

# Plot each function on a different subplot
for i, y in enumerate(y_list):
    axes[i].plot(x, y)
    axes[i].set_title(f"Plot {i+1}")

# Adjust layout to avoid overlap
plt.tight_layout()
plt.show()

print(compounds)
['TD139' 'JZ7-47-4' 'JZ7-50-2']
data.plot(input_data, Kd_results, compound_sel=False, show_all_data=True, show_medians=False)


# Create a 2x2 grid of subplots
fig, axes = plt.subplots(2, 2, figsize=(7, 5))  # 2 rows, 2 columns

# Flatten the 2D axes array to iterate over it
axes = axes.flatten()

# Plot each function on a different subplot
for i, compound in enumerate(compounds):
    axes[i].plot
    axes[i].set_title(f"Plot {i+1}")

# Adjust layout to avoid overlap
plt.tight_layout()
plt.show()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[12], line 12
     10 # Plot each function on a different subplot
     11 for i, compound in enumerate(compounds):
---> 12     axes[i].data.plot(input_data, Kd_results, compound_sel=False, show_all_data=True, show_medians=False)
     13     axes[i].set_title(f"Plot {i+1}")
     15 # Adjust layout to avoid overlap

AttributeError: 'Axes' object has no attribute 'data'