Skip to content
Snippets Groups Projects
Commit fd5cc077 authored by Selim Bouaouina's avatar Selim Bouaouina
Browse files

Upload GetMDK.ipynb

parent a6023b94
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id:058d1d74-723d-4dfa-b824-a77a4c31e4ed tags:
``` python
def calc(file, threshold = 0.01, log = False, time = "time (Days)", path = "path to inputfile with tolerance data"):
"""
Takes as input a file including the following headers:
"time (Days)" (this can be changed), strain indentifiers
The output is a csv file containing the columns:
"Strain" and "Day at threshold" -- The script is agnostic to units days, hour, minutes can all be considered
The file is stored in the same place as the input file unless a path is given. It contains the appendix
_output or _output_log10transformed
Options: file --> name of the file containing your input data (required)
threshold --> the requested threshold (default is 0.01)
log --> whether you want your y-axis to be log10 transformed or not (default is "False")
time --> the name of the column that contains the timepoints (default is "time (Days)")
path --> the path to the folder where you want the outputfile to be (default is "")
"""
import pandas as pd
import math
data = pd.read_excel(file)
dic = {}
i = 0
timepoints = sorted(data[time].unique())
if log == True:
threshold = math.log10(threshold)
for strain in data.columns:
if not strain == time:
dic[i] = {}
dic[i]["Strain"] = strain
for x2 in timepoints:
y2 = data[data[time] == x2][strain].item()
if log == True:
try:
y2 = math.log10(y2)
except:
print("Cannot calculate value for " + strain)
break
if y2 < threshold:
x1 = timepoints[timepoints.index(x2)-1]
y1 = data[data[time] == x1][strain].item()
if log == True:
try:
y1 = math.log10(y1)
except:
print("Cannot calculate value for " + strain)
break
break
else:
continue
else:
continue
slope = (y2-y1)/(x2-x1)
intercept = y1 - (slope*x1)
value = (threshold-intercept)/slope
dic[i]["Day_at_threshold"] = value
i += 1
df = pd.DataFrame(dic).T
out = path + file.split("/")[-1].split(".")[0] + "_output.csv"
if log == True:
out = path + file.split("/")[-1].split(".")[0] + "_4output_log10transformedmdkX.csv"
try:
df.to_csv(out, sep = ";", index = False)
except:
print("File with the requested outputfilename is open. Please close the file and rerun the code...")
```
%% Cell type:code id:18e2dc11-9f5a-4420-92b4-1d8525cfaef7 tags:
``` python
#Calling function
file ="path to file"
calc(file, log = True)
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment