Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(Let me know if you need any information. I can answer your query in the comment section) Question 1 We need to write a single
(Let me know if you need any information. I can answer your query in the comment section)
Question 1 We need to write a single Python Script using the following steps/hints given below. FYI: The question description is written in details, don't be afraid by this. But the scripting might be a single page length (or even smaller). We have a csv file, named 'Collection.csv', which contains the following two columns (extended till row 1001): B 1 t F 2 0.00E+00 1.48E-05 3 1.00E-01 -6.14E-06 4 2.00E-01 -1.15E-05 5 3.00E-01 1.23E-05 6 4.00E-01 -3.22E-05 7 5.01E-01 4.01E-05 8 6.01E-01 -4.93E-05 9 7.01E-01 -5.02E-05 10 8.01E-01 -2.06E-05 11 9.01E-01 5.30E-05 We have an ordinary differential equation (ODE): d[A] = koff[C] - kon[A][B] dt Where 'A, B, C' are the concentration of different species, and kon and koff are constants. Also: [A] + [B] [C]. Depending on concentration of 'A' and 'B', the concentration 'C can be formed as five species: monomer, dimer, trimer, tetramers, and pentamers. Here C[O] is the concentration of monomers, C[1] of dimers, etc. Scripting step A: Let's build a "master equation". It identifies the time-dependent change in all species in our model. This function should return a matrix of TxN, where T is the number of time points we have and N is the number of species we have in our case 5). For example, the ODE that describes dimer change with time can look like: dc2 = k_off*(-C[1] + [2]) + k_on*C[0]*(C[0] - C[1]) Scripting step B: The function should accept a time vector t, all concentrations C, k_on, and k_off. It should return a list of all concentrations. Write this function! Scripting step C: We next call this function through our ODE solve solve_ivp. The call should look like so: sol-solve_ivp(ME,(0,100),co, args=po, t_eval=t) Here ME is the master equation ODE function, (0,100) is the integration range, CO is your initial concentrations (remember this should be a 5-member list!), po is a two-member list with the values for k_on and k_off (the order is determined by the order in your ODE function!), and t is a vector of timepoints - usually we take this directly from the experimental data. Scripting step D: Once the function is done, let's try running it with some parameters. You will want to write a few lines to plot the solution variable sol. Remember this will be a 5 x len(t) matrix! t = np.linspace (0,100,100) CO = [0.5,0,0,0,0] p0=[0.15,0.0071 sol=solve_ivp (ME, (0,100),co, args=po, t_eval=t) fig, ax = plt.subplots (figsize=[10,10]) for i in range (sol.y.shape [0]): ax.plot(t, sol.y[i], label=str (i+1)+' -mer') ax.legend (fontsize=12) ax.set_ylabel('conc') ax.set_xlabel('t') Scripting step E: You'll quickly find out that constants need to be smaller than 1 or our simulation "explodes". Try generating some solutions that would make sense, and plotting these as function of time. This is a sample plot (concentration vs time, for 5 species). 0.5-1 0.4 0.3 conc 0.21 0.1 0.0 FO 20 40 60 80 100 t Scripting step : One way to check if our model is working right is to check that matter is conserved, and no monomers are destroyed our simulation. To do this, you can use the np.sum function to go over each line in the concentration matrix, and sum the monomers. Remember to multiply each column by the number of monomers in the species! Write a function called checkModel that accepts the sol.y matrix returned from the ODE solution and checks this for you easily. Scripting step G: Finally, we need to remember that our observable cannot see small species, and cannot differentiate between the larger species. Write a function calcobs that accepts the sol.y matrix returned from the ordinary differential equation (ODE), sums the total concentration of trimers, tetramers, and pentamers, and returns this concentration as a function of time. Plot this as well. It should look something like this: 1- mer 2-mer 0.4 met III 4-mer 5- mer 0.05- 80.2 oligo. conc 0.0- 0 0.00 0 100 100 t t Scripting step H: Now we are ready to fit the observable we obtain from calcobs to the experimental data. Copy this function and paste it as a new function called fitODE This function, fitODE(t,k_on,k_off), will take all the parameters we feed into our simulation function, call solve_ivp to get a solution for the ME function, and return the final observable (sum over the concentrations of all species larger than a dimer). Recall that this is the total concentration of all species larger than dimers. Scripting step : Once we have this done, and tested that this function works with some reasonable k_on and k_off parameters, we can use it as the function to feed into curve_fit. The fitting function should look like this: popt,pcov = curve_fit(fitODE,t_exp,y_exp,p0=po) Here, fitODE is the equation that calls solve_ivp and returns the observable, t_exp is the experimental data x axis, y_exp is the experimental data y axis, and pO is the initial guess for k_on and k_off. Popt is a variable that will contain a 2-member list with the fitted k_on and k_off values. Scripting step J: Finally, we should plot the results we get. To do this, we first need to feed in the fitted k_on and k_off into our ODES: Y_model = solve_ivp(ME, (0,100), Co, args=popt, t_eval=data['t']) Then the plotting can look like this (data here is the experimental data imported to a pandas dataframe with read_csv): fig, ax = plt.subplots(1,2, figsize=[10,51) for i in rangely_model.y.shape[0]): ax[0].plot(data['t'],y_model.y[i], label=str(i+1)+'-mer') ax[1].semilogx(data['t'],data['F'),marker='0') ax[1].semilogx(data['t'],y_model.y[2:].sum(axis=0)) plt.title('after fit') ax[0].set_ylabel('conc') ax[1].set_ylabell'oligo. conc') ax[O].legend(fontsize=12) ax[0].set_xlabel('t') ax[1].set_xlabel('t') plt.tight_layout() it can also benefit from setting an initial guess using the po parameter and bounds on the numbers (between 0 and 1 for kon and koff) using the bounds parameter. Question 1 We need to write a single Python Script using the following steps/hints given below. FYI: The question description is written in details, don't be afraid by this. But the scripting might be a single page length (or even smaller). We have a csv file, named 'Collection.csv', which contains the following two columns (extended till row 1001): B 1 t F 2 0.00E+00 1.48E-05 3 1.00E-01 -6.14E-06 4 2.00E-01 -1.15E-05 5 3.00E-01 1.23E-05 6 4.00E-01 -3.22E-05 7 5.01E-01 4.01E-05 8 6.01E-01 -4.93E-05 9 7.01E-01 -5.02E-05 10 8.01E-01 -2.06E-05 11 9.01E-01 5.30E-05 We have an ordinary differential equation (ODE): d[A] = koff[C] - kon[A][B] dt Where 'A, B, C' are the concentration of different species, and kon and koff are constants. Also: [A] + [B] [C]. Depending on concentration of 'A' and 'B', the concentration 'C can be formed as five species: monomer, dimer, trimer, tetramers, and pentamers. Here C[O] is the concentration of monomers, C[1] of dimers, etc. Scripting step A: Let's build a "master equation". It identifies the time-dependent change in all species in our model. This function should return a matrix of TxN, where T is the number of time points we have and N is the number of species we have in our case 5). For example, the ODE that describes dimer change with time can look like: dc2 = k_off*(-C[1] + [2]) + k_on*C[0]*(C[0] - C[1]) Scripting step B: The function should accept a time vector t, all concentrations C, k_on, and k_off. It should return a list of all concentrations. Write this function! Scripting step C: We next call this function through our ODE solve solve_ivp. The call should look like so: sol-solve_ivp(ME,(0,100),co, args=po, t_eval=t) Here ME is the master equation ODE function, (0,100) is the integration range, CO is your initial concentrations (remember this should be a 5-member list!), po is a two-member list with the values for k_on and k_off (the order is determined by the order in your ODE function!), and t is a vector of timepoints - usually we take this directly from the experimental data. Scripting step D: Once the function is done, let's try running it with some parameters. You will want to write a few lines to plot the solution variable sol. Remember this will be a 5 x len(t) matrix! t = np.linspace (0,100,100) CO = [0.5,0,0,0,0] p0=[0.15,0.0071 sol=solve_ivp (ME, (0,100),co, args=po, t_eval=t) fig, ax = plt.subplots (figsize=[10,10]) for i in range (sol.y.shape [0]): ax.plot(t, sol.y[i], label=str (i+1)+' -mer') ax.legend (fontsize=12) ax.set_ylabel('conc') ax.set_xlabel('t') Scripting step E: You'll quickly find out that constants need to be smaller than 1 or our simulation "explodes". Try generating some solutions that would make sense, and plotting these as function of time. This is a sample plot (concentration vs time, for 5 species). 0.5-1 0.4 0.3 conc 0.21 0.1 0.0 FO 20 40 60 80 100 t Scripting step : One way to check if our model is working right is to check that matter is conserved, and no monomers are destroyed our simulation. To do this, you can use the np.sum function to go over each line in the concentration matrix, and sum the monomers. Remember to multiply each column by the number of monomers in the species! Write a function called checkModel that accepts the sol.y matrix returned from the ODE solution and checks this for you easily. Scripting step G: Finally, we need to remember that our observable cannot see small species, and cannot differentiate between the larger species. Write a function calcobs that accepts the sol.y matrix returned from the ordinary differential equation (ODE), sums the total concentration of trimers, tetramers, and pentamers, and returns this concentration as a function of time. Plot this as well. It should look something like this: 1- mer 2-mer 0.4 met III 4-mer 5- mer 0.05- 80.2 oligo. conc 0.0- 0 0.00 0 100 100 t t Scripting step H: Now we are ready to fit the observable we obtain from calcobs to the experimental data. Copy this function and paste it as a new function called fitODE This function, fitODE(t,k_on,k_off), will take all the parameters we feed into our simulation function, call solve_ivp to get a solution for the ME function, and return the final observable (sum over the concentrations of all species larger than a dimer). Recall that this is the total concentration of all species larger than dimers. Scripting step : Once we have this done, and tested that this function works with some reasonable k_on and k_off parameters, we can use it as the function to feed into curve_fit. The fitting function should look like this: popt,pcov = curve_fit(fitODE,t_exp,y_exp,p0=po) Here, fitODE is the equation that calls solve_ivp and returns the observable, t_exp is the experimental data x axis, y_exp is the experimental data y axis, and pO is the initial guess for k_on and k_off. Popt is a variable that will contain a 2-member list with the fitted k_on and k_off values. Scripting step J: Finally, we should plot the results we get. To do this, we first need to feed in the fitted k_on and k_off into our ODES: Y_model = solve_ivp(ME, (0,100), Co, args=popt, t_eval=data['t']) Then the plotting can look like this (data here is the experimental data imported to a pandas dataframe with read_csv): fig, ax = plt.subplots(1,2, figsize=[10,51) for i in rangely_model.y.shape[0]): ax[0].plot(data['t'],y_model.y[i], label=str(i+1)+'-mer') ax[1].semilogx(data['t'],data['F'),marker='0') ax[1].semilogx(data['t'],y_model.y[2:].sum(axis=0)) plt.title('after fit') ax[0].set_ylabel('conc') ax[1].set_ylabell'oligo. conc') ax[O].legend(fontsize=12) ax[0].set_xlabel('t') ax[1].set_xlabel('t') plt.tight_layout() it can also benefit from setting an initial guess using the po parameter and bounds on the numbers (between 0 and 1 for kon and koff) using the bounds parameterStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started