Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MDKCalculator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TBRU
MDKCalculator
Commits
fd5cc077
Commit
fd5cc077
authored
4 months ago
by
Selim Bouaouina
Browse files
Options
Downloads
Patches
Plain Diff
Upload GetMDK.ipynb
parent
a6023b94
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
GetMDK.ipynb
+111
-0
111 additions, 0 deletions
GetMDK.ipynb
with
111 additions
and
0 deletions
GetMDK.ipynb
0 → 100644
+
111
−
0
View file @
fd5cc077
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "058d1d74-723d-4dfa-b824-a77a4c31e4ed",
"metadata": {},
"outputs": [],
"source": [
"def calc(file, threshold = 0.01, log = False, time = \"time (Days)\", path = \"path to inputfile with tolerance data\"):\n",
" \"\"\"\n",
" Takes as input a file including the following headers:\n",
" \"time (Days)\" (this can be changed), strain indentifiers\n",
" \n",
" The output is a csv file containing the columns:\n",
" \"Strain\" and \"Day at threshold\" -- The script is agnostic to units days, hour, minutes can all be considered\n",
" The file is stored in the same place as the input file unless a path is given. It contains the appendix\n",
" _output or _output_log10transformed\n",
" \n",
" Options: file --> name of the file containing your input data (required)\n",
" threshold --> the requested threshold (default is 0.01)\n",
" log --> whether you want your y-axis to be log10 transformed or not (default is \"False\")\n",
" time --> the name of the column that contains the timepoints (default is \"time (Days)\")\n",
" path --> the path to the folder where you want the outputfile to be (default is \"\")\n",
" \n",
" \"\"\"\n",
" import pandas as pd\n",
" import math\n",
" data = pd.read_excel(file)\n",
" dic = {}\n",
" i = 0\n",
" timepoints = sorted(data[time].unique())\n",
" if log == True:\n",
" threshold = math.log10(threshold)\n",
" for strain in data.columns:\n",
" if not strain == time:\n",
" dic[i] = {}\n",
" dic[i][\"Strain\"] = strain\n",
" for x2 in timepoints:\n",
" y2 = data[data[time] == x2][strain].item()\n",
" if log == True:\n",
" try:\n",
" y2 = math.log10(y2)\n",
" except:\n",
" print(\"Cannot calculate value for \" + strain)\n",
" break\n",
" if y2 < threshold:\n",
" x1 = timepoints[timepoints.index(x2)-1]\n",
" y1 = data[data[time] == x1][strain].item()\n",
" if log == True:\n",
" try: \n",
" y1 = math.log10(y1)\n",
" except:\n",
" print(\"Cannot calculate value for \" + strain)\n",
" break\n",
" \n",
" break\n",
" else:\n",
" continue\n",
" else:\n",
" continue\n",
" slope = (y2-y1)/(x2-x1)\n",
" intercept = y1 - (slope*x1)\n",
" value = (threshold-intercept)/slope\n",
" dic[i][\"Day_at_threshold\"] = value\n",
" i += 1\n",
" df = pd.DataFrame(dic).T\n",
" out = path + file.split(\"/\")[-1].split(\".\")[0] + \"_output.csv\"\n",
" if log == True:\n",
" out = path + file.split(\"/\")[-1].split(\".\")[0] + \"_4output_log10transformedmdkX.csv\"\n",
" try:\n",
" df.to_csv(out, sep = \";\", index = False)\n",
" except:\n",
" print(\"File with the requested outputfilename is open. Please close the file and rerun the code...\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "18e2dc11-9f5a-4420-92b4-1d8525cfaef7",
"metadata": {},
"outputs": [],
"source": [
"#Calling function\n",
"file =\"path to file\"\n",
"calc(file, log = True)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
%% 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
)
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment