-
-
Save dgruano/18fb1f81570c3a5aad74213befe521e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Calculate OD values of an old experiment using the original raw data and a given calibration | |
by Daniel Garcia Ruano (dani14-96) | |
SyntheCell Team | |
""" | |
import json | |
import numpy as np | |
import os | |
# Custom variables | |
PATH_TO_CALIBRATIONS_JSON = "calibrations.json" | |
CALIBRATION_NAME = "OD_01_01_2000" | |
FIT_NAME = "OD_01_01_2000" | |
EXPT_PATH = "/Users/evolver/dpu/experiment/test/test_cp_expt" | |
# Load initial calibration curve | |
calibrations = json.load(open(PATH_TO_CALIBRATIONS_JSON, "r")) | |
for c, cal in enumerate(calibrations): # Iterate over calibrations list | |
if cal["calibrationType"] == "od": | |
if cal["name"] == CALIBRATION_NAME: | |
calibration = cal | |
for f in calibration["fits"]: | |
if f["name"] == FIT_NAME: | |
fit = f # Extract fit for the coefficients | |
# Iterate through vials | |
for vial in range(0,16): | |
print(f"Recalculating ODs for vial {vial}...") | |
# Read Raw data files | |
raw_file = os.path.join(EXPT_PATH, "od_135_raw", f"vial{vial}_od_135_raw.txt") # Change for od_90 if needed | |
new_od_file = os.path.join(EXPT_PATH, "NewOD", f"vial{vial}_OD.txt") # You need to manually create a folder NewOD inside your experiment | |
header = open(raw_file, "r").readlines()[0] | |
data = np.genfromtxt(raw_file, delimiter=",", skip_header=1) | |
od_coefficients = fit["coefficients"][vial] | |
for i in range(len(data)): | |
# Get OD using calibration curve | |
data[i,1] = np.real(od_coefficients[2] - | |
((np.log10((od_coefficients[1] - | |
od_coefficients[0]) / | |
(float(data[i,1]) - | |
od_coefficients[0])-1)) / | |
od_coefficients[3])) | |
# Here, substract blank if needed | |
if not np.isfinite(data[i,1]): | |
data[i,1] = "NaN" | |
# Log data in datafiles | |
np.savetxt(new_od_file, data, delimiter=",", fmt='%.4f', header=header) | |
print("Done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment