Skip to content

Instantly share code, notes, and snippets.

@yannabraham
Last active May 14, 2024 05:36
Show Gist options
  • Save yannabraham/5f210fed773785d8b638 to your computer and use it in GitHub Desktop.
Save yannabraham/5f210fed773785d8b638 to your computer and use it in GitHub Desktop.
How to do Dose/Response curve fitting in Python for Drug Discovery
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yannabraham
Copy link
Author

@jhfc Thanks for your feedback, and sorry about the late answer: those functions belong to the numpy package and were incorrectly called. The source is now fixed.

@akashbahai
Copy link

I am getting this error. I checked and found that there is no plt.plot in seaborn.
sns.plt.plot([pDose(i) for i in refDose],[ll4(i,*[fit[i] for i in ['b','c','d','e']]) for i in refDose])
AttributeError: 'module' object has no attribute 'plt'

@cbmII
Copy link

cbmII commented Dec 13, 2020

import matplotlib.pyplot as plt is missing from the imports
and
sns.plt.plot needs to be modified to plt.plot

for fit in fitData:
plt.plot([pDose(i) for i in refDose],[ll4(i,*[fit[i] for i in ['b','c','d','e']]) for i in refDose])

@yannabraham
Copy link
Author

Thanks! Fixed the code as you suggested, should work now @akashbahai @cbmII

@Fae14
Copy link

Fae14 commented Mar 15, 2021

How would you go about implementing a 1/Y^2 weighting and returning their parameter values as well as visualising the line on the graph?

@yannabraham
Copy link
Author

Hey @Fae14, this link should give you a few pointers:

https://stackoverflow.com/questions/27696324/using-scipy-optimize-curve-fit-with-weights

Hope this helps!

@amnfar
Copy link

amnfar commented Sep 29, 2022

Nice attempt. May be code should be more explanatory and have more comments,

@resminer
Copy link

resminer commented May 14, 2024

Copied as-is into a new jupyter session, I get the following after assigning fitCompound:

[/var/folders/2s/9l3t4cfj0c5g1s4_7shzc5900000gp/T/ipykernel_19131/1118045928.py:7](http://localhost:8888/var/folders/2s/9l3t4cfj0c5g1s4_7shzc5900000gp/T/ipykernel_19131/1118045928.py#line=6): RuntimeWarning: invalid value encountered in log
  return(c+(d-c)[/](http://localhost:8888/)(1+np.exp(b*(np.log(x)-np.log(e)))))

Then a type error making the lmplot:

TypeError                                 Traceback (most recent call last)
Cell In[81], line 3
      1 refDose = np.linspace(min(drData.logDose)*0.9,max(drData.logDose)*1.1,256)
      2 refDose = (10**-refDose)*1e6
----> 3 sns.lmplot('logDose','response',data=drData,hue='compound',fit_reg=False)
      4 for fit in fitData:
      5     plt.plot([pDose(i) for i in refDose],[ll4(i,*[fit[i] for i in ['b','c','d','e']]) for i in refDose])

TypeError: lmplot() got multiple values for argument 'data'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment