Skip to content

Instantly share code, notes, and snippets.

@yannabraham
Last active December 20, 2023 19:07
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • 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.
@jfhc
Copy link

jfhc commented Aug 6, 2015

When I try running it, in the fifth block I get


NameError Traceback (most recent call last)
in ()
3 # generate base curve
4 curData = pd.DataFrame(data={'compound':curve['compound'],
----> 5 'dose':curve['startDose']/power(curve['dilution'],range(curve['nDose']))})
6 curData['logDose'] = pDose(curData.dose)
7 curData['response'] = curData.dose.apply(lambda x: ll4(x,*[curve[i] for i in ['b','c','d','e']]))

NameError: name 'power' is not defined

any idea what's going on here?

@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,

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