# Setting the file path for clinical trial data filefilepath1=os.path.join("raw_data","clinicaltrial_data.csv")
# Setting the file path for mouse drug data filefilepath2=os.path.join("raw_data","mouse_drug_data.csv")
# Reading the csv fileClinical_data=pd.read_csv(filepath1)
Mouse_Drug_data=pd.read_csv(filepath2)
# Combining the data files to one single dataframeClinical_Combined_data=pd.merge(Clinical_data,Mouse_Drug_data,on="Mouse ID",how="left")
Tumor Response to Treatment
# Creating a pivot table for Clinical Tumor ResponseClinical_TumorResponse=pd.pivot_table(Clinical_Combined_data, values="Tumor Volume (mm3)",
columns=["Drug"],index=["Timepoint"],aggfunc=np.mean)
Clinical_TumorResponse
# Droping the not needed drugs from the already existing pivot tableClinical_TumorResponse_DF=Clinical_TumorResponse.drop(['Ceftamin','Naftisol','Propriva','Ramicane','Stelasyn','Zoniferol'],
axis=1)
Clinical_TumorResponse_DF
# Setting the lists of drugs, colors and markers respectivelydrug=["Capomulin","Infubinol","Ketapril","Placebo"]
colors=["red","blue","green","black"]
markers=["o","^","s","D"]
# Intializing the plotsfig, ax=plt.subplots()
foritemindrug:
# Setting the x_axis data,y_axis data and standard deviation for the graphx_data=Clinical_TumorResponse_DF.index.valuesy_data=Clinical_TumorResponse_DF[item]
err=sem(Clinical_TumorResponse_DF[item])
# Finding the index for colors and markersindex=drug.index(item)
# Setting up the plotax.errorbar(x_data, y_data,err,linestyle="--",color=colors[index],
marker=markers[index],capsize=3,capthick=1,markeredgecolor='black')
# Setting the legendax.legend(loc="upper left", fancybox=True,numpoints=2,edgecolor="black")
# Setting the grid plt.grid(linestyle='dotted')
# Setting the x_axis and y_axis limitsax.set_xlim(0,45)
ax.set_ylim(0,80)
# Setting the title,x_axis and y_axis labelsax.set_title("Tumor Response to Treatment", fontsize=16)
ax.set_xlabel("Time(Days)")
ax.set_ylabel("Tumor Volume (mm3)")
# Display the graphplt.show()
Metastatic Response to Treatment
# Creating a pivot table for Metastatic ResponseMetastatic_Response=pd.pivot_table(Clinical_Combined_data, values="Metastatic Sites",
columns=["Drug"],index=["Timepoint"],aggfunc=np.mean)
Metastatic_Response
# Droping the not needed drugs from the already existing pivot tableMetastatic_Response_DF=Metastatic_Response.drop(['Ceftamin','Naftisol','Propriva','Ramicane','Stelasyn','Zoniferol'], axis=1)
Metastatic_Response_DF
# Setting the lists of drugs, colors and markers respectivelydrug=["Capomulin","Infubinol","Ketapril","Placebo"]
colors=["red","blue","green","black"]
markers=["o","^","s","D"]
# Intializing the plotsfig, ax=plt.subplots()
foritemindrug:
# Setting the x_axis data,y_axis data and standard deviation for the graphx_data=Metastatic_Response_DF.index.valuesy_data=Metastatic_Response_DF[item]
err=sem(Metastatic_Response_DF[item])
# Finding the index for colors and markersindex=drug.index(item)
# Setting up the plotax.errorbar(x_data, y_data,err,linestyle=":",color=colors[index],
marker=markers[index],capsize=3,capthick=1,markeredgecolor='black')
# Setting the legendax.legend(loc="upper left", fancybox=True,numpoints=2,edgecolor="black")
# Setting the grid plt.grid(linestyle='dotted')
# Setting the x_axis and y_axis limitsax.set_xlim(0,45)
ax.set_ylim(0,4)
# Setting the title,x_axis and y_axis labelsax.set_title("Metastatic Spread during Treatment", fontsize=16)
ax.set_xlabel("Treatment Duration (Days)")
ax.set_ylabel("Met. Sites")
# Display the graphplt.show()
Survival Rates
# Creating a pivot table for Survival RatesSurvival_Rates=pd.pivot_table(Clinical_Combined_data, values="Tumor Volume (mm3)",
columns=["Drug"],index=["Timepoint"],aggfunc='count')
Survival_Rates
# Droping the not needed drugs from the already existing pivot tableSurvival_Rates_DF=Survival_Rates.drop(['Ceftamin','Naftisol','Propriva','Ramicane','Stelasyn','Zoniferol'], axis=1)
Survival_Rates_DF
# Setting the lists of drugs, colors and markers respectivelydrug=["Capomulin","Infubinol","Ketapril","Placebo"]
colors=["red","blue","green","black"]
markers=["o","^","s","D"]
# Intializing the plotsfig, ax=plt.subplots()
foritemindrug:
# Setting the x_axis data and y_axis data for the graphx_data=Survival_Rates_DF.index.valuesy_data=(Survival_Rates_DF[item]*100)/Survival_Rates_DF[item][0]
# Finding the index for colors and markersindex=drug.index(item)
# Setting up the plotax.plot(x_data,y_data,linestyle="--",color=colors[index],marker=markers[index],label=item,markeredgecolor='black')
# Setting the legendax.legend(loc="lower left", fancybox=True,numpoints=2,edgecolor="black")
# Setting the gridax.grid(linestyle='dotted')
# Setting the x_axis and y_axis limitsax.set_xlim(0,45)
ax.set_ylim(0,102)
# Setting the title,x_axis and y_axis labelsax.set_title("Survival during Treatment", fontsize=16)
ax.set_xlabel("Time (Days)")
ax.set_ylabel("Survival Rate(%)")
# Display the graphplt.show()
Summary Bar Graph
# Summary of the analysis based on % Tumor Change over 45 daysSummary=round(((Clinical_TumorResponse_DF.iloc[9,:]-Clinical_TumorResponse_DF.iloc[0,:])*100/Clinical_TumorResponse_DF.iloc[0,:]),0).to_frame()
# Renaming the columnSummary=Summary.rename(columns={0:"% Tumor Change"})
Summary
# Setting the x_axis and y-axis valuex_axis=Summary.index.valuesy_axis=Summary["% Tumor Change"]
# If value is positive then put True in the Summary else place False, for changing the color based on the valueSummary["Positive"]=Summary["% Tumor Change"]>0# Intializing the plotsfig,ax=plt.subplots()
#Setting the plot and assigning the color based on the Positive or not valuebars=ax.bar(x_axis,y_axis,align="edge",width=1,linewidth=1,
edgecolor=Summary.Positive.map({True: 'black', False: 'black'}),
color=Summary.Positive.map({True: 'green', False: 'red'}))
# Setting the ticks for the bar graphtick_locations= [value+0.5forvalueinrange(len(x_axis))]
ax.set_xticks(tick_locations)
# Setting the text label in the bar graph# Assign the height based on the positive calueheight=Summary.Positive.map({True: 5, False: -5})
forbarinbars:
ax.text(bar.get_x() +bar.get_width()/2., height[bars.index(bar)],
str(int(Summary["% Tumor Change"][bars.index(bar)]))+"%",
ha='center', va='bottom')
# Setting the x_axis limitsax.set_xlim(0, len(x_axis))
# Setting a horizontal line at y=0plt.hlines(0,0,len(x_axis))
# Setting the title of the graphax.set_title("Tumor Change over 45 Day Treatment", fontsize=16)
# Setting the y_axis labelax.set_ylabel("% Tumor Volume Change")
# Setting the grid lineplt.grid(linestyle='dotted')
# Display the graphplt.show()