def Plot_dose_response_poly(data, save_fig, save_data, ec50_poly, save_poly_coeffs, namedata): '''This function normalizes a set of data points for plotting on a dose response curve. They are normalized so that the highest drug concentration's data = 0, lowest = 1. A polynomial is fit to the data, and we measure where 0.5 (50% effect) crosses on that line.''' normalized = (data - data[0]) / (data[-1] - data[0]) normalized = np.absolute(normalized) np.savetxt(join2(save_dir, save_data), normalized, delimiter=',') # fit a 3 degree polynomial. nm is the ranks and other crap poly_coeffs, residual, nm1, nm2, nm3 = np.polyfit(concs_nums, normalized, ec50_poly, full=True) r_squared = 1 - residual / (len(normalized) * normalized.var()) # make a function out of it f = np.poly1d(poly_coeffs) np.savetxt(join2(save_dir, save_poly_coeffs), f) EC50 = x_for_known_y_poly(f) ec50s_file.write(('%s Endpoint\t EC50 = ' % namedata + '%.3f' % EC50 + '\tR-squared = ' + '%.3f' % r_squared + '\n')) fig = plt.figure() ax = fig.add_subplot(111) ax.set_xscale('log') plt.scatter(concs_nums, normalized, s=75, color='#756E71') plt.ylabel('effect (0 to 1)') plt.xlabel('concentration') plt.plot(rangeconc, f(rangeconc), 'k', EC50, f(EC50), 'r<', ms=8) plt.grid(True) ax.tick_params(axis='x') ax.xaxis.tick_bottom() ax.tick_params(axis='y') ax.yaxis.tick_left() plt.savefig(join2(save_dir, save_fig)) plt.close()
def Plot_dose_response_sig(data, save_fig, save_data, namedata): '''This function normalizes a set of data points for plotting on a dose response curve. They are normalized so that the highest drug concentration's data = 0, lowest = 1. A sigmoidal is fit to the data, and we measure where 0.5 (50% effect) crosses on that line.''' normalized = (data - data[0]) / (data[-1] - data[0]) normalized = np.absolute(normalized) np.savetxt( join2(save_dir, save_data), normalized, delimiter=',') p_guess = ( np.median( concs_nums ),np.median( normalized ),1.0,1.0 ) p, cov, infodict, mesg, ier = scipy.optimize.leastsq(residuals, p_guess, args=(concs_nums, normalized), full_output=1) x0,y0,c,k = p pxp = sigmoid(p, rangeconc) ss_err =(infodict['fvec']**2).sum() ss_tot =((normalized - normalized.mean())**2).sum() r_squared = 1- (ss_err / ss_tot) EC50 = x_for_known_y_sig( sigmoid, p ) ec50s_file.write(('%s Endpoint\t EC50 = ' %namedata + '%.3f' %EC50 + '\tR-squared = ' + '%.3f' %r_squared + '\n')) fig = plt.figure() ax = fig.add_subplot(111) ax.set_xscale('log') plt.scatter(concs_nums, normalized, s=75, color='#756E71') plt.ylabel('effect (0 to 1)') plt.xlabel('concentration') plt.plot(rangeconc, pxp, 'k', EC50, sigmoid(p, EC50), 'r<', ms=9) ax.tick_params(axis='x') ax.xaxis.tick_bottom() ax.tick_params(axis='y') ax.yaxis.tick_left() plt.grid(True) plt.savefig( join2(save_dir, save_fig)) plt.close()
def Plot_dose_response_poly(data, save_fig, save_data, ec50_poly, save_poly_coeffs, namedata): '''This function normalizes a set of data points for plotting on a dose response curve. They are normalized so that the highest drug concentration's data = 0, lowest = 1. A polynomial is fit to the data, and we measure where 0.5 (50% effect) crosses on that line.''' normalized = (data - data[0]) / (data[-1] - data[0]) normalized = np.absolute(normalized) np.savetxt( join2(save_dir, save_data), normalized, delimiter=',') # fit a 3 degree polynomial. nm is the ranks and other crap poly_coeffs, residual, nm1, nm2, nm3 = np.polyfit(concs_nums, normalized, ec50_poly, full=True) r_squared = 1 - residual / (len(normalized) * normalized.var()) # make a function out of it f = np.poly1d(poly_coeffs) np.savetxt( join2(save_dir, save_poly_coeffs), f) EC50 = x_for_known_y_poly(f) ec50s_file.write(('%s Endpoint\t EC50 = ' %namedata + '%.3f' %EC50 + '\tR-squared = ' + '%.3f' %r_squared + '\n')) fig = plt.figure() ax = fig.add_subplot(111) ax.set_xscale('log') plt.scatter(concs_nums, normalized, s=75, color='#756E71') plt.ylabel('effect (0 to 1)') plt.xlabel('concentration') plt.plot(rangeconc, f(rangeconc),'k', EC50, f(EC50),'r<', ms=8) plt.grid(True) ax.tick_params(axis='x') ax.xaxis.tick_bottom() ax.tick_params(axis='y') ax.yaxis.tick_left() plt.savefig( join2(save_dir, save_fig)) plt.close()
def Plot_dose_response_sig(data, save_fig, save_data, namedata): '''This function normalizes a set of data points for plotting on a dose response curve. They are normalized so that the highest drug concentration's data = 0, lowest = 1. A sigmoidal is fit to the data, and we measure where 0.5 (50% effect) crosses on that line.''' normalized = (data - data[0]) / (data[-1] - data[0]) normalized = np.absolute(normalized) np.savetxt(join2(save_dir, save_data), normalized, delimiter=',') p_guess = (np.median(concs_nums), np.median(normalized), 1.0, 1.0) p, cov, infodict, mesg, ier = scipy.optimize.leastsq(residuals, p_guess, args=(concs_nums, normalized), full_output=1) x0, y0, c, k = p pxp = sigmoid(p, rangeconc) ss_err = (infodict['fvec']**2).sum() ss_tot = ((normalized - normalized.mean())**2).sum() r_squared = 1 - (ss_err / ss_tot) EC50 = x_for_known_y_sig(sigmoid, p) ec50s_file.write(('%s Endpoint\t EC50 = ' % namedata + '%.3f' % EC50 + '\tR-squared = ' + '%.3f' % r_squared + '\n')) fig = plt.figure() ax = fig.add_subplot(111) ax.set_xscale('log') plt.scatter(concs_nums, normalized, s=75, color='#756E71') plt.ylabel('effect (0 to 1)') plt.xlabel('concentration') plt.plot(rangeconc, pxp, 'k', EC50, sigmoid(p, EC50), 'r<', ms=9) ax.tick_params(axis='x') ax.xaxis.tick_bottom() ax.tick_params(axis='y') ax.yaxis.tick_left() plt.grid(True) plt.savefig(join2(save_dir, save_fig)) plt.close()
# Convert list of tif images to jpg import Image import os from os.path import join as join2 dir = os.getcwd() tifs = [f for f in os.listdir(dir) if f.endswith('.png')] for i in tifs: Image.open( join2(dir, i)).save( join2(dir, i + '.jpg'), 'JPEG', quality=100)
# Convert list of tif images to jpg import Image import os from os.path import join as join2 dir = os.getcwd() tifs = [f for f in os.listdir(dir) if f.endswith('.png')] for i in tifs: Image.open(join2(dir, i)).save(join2(dir, i + '.jpg'), 'JPEG', quality=100)