Skip to content

Commit

Permalink
Remove unneeded value columns from chemical results dataframe
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Chao authored and alexchao32 committed May 23, 2024
1 parent f95bc3b commit 010217a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/ms1/task_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,8 @@ def MPP_Ready(dft, pts, tracer_df=False, directory="", file=""):

def calc_toxcast_percent_active(df):
dft = df.copy()

# Extract out the total and active numeric values from the TOTAL_ASSAYS_TESTED column
TOTAL_ASSAYS = "\/([0-9]+)" # a regex to find the digits after a slash
dft["TOTAL_ASSAYS_TESTED"] = (
dft["TOXCAST_NUMBER_OF_ASSAYS/TOTAL"].astype("str").str.extract(TOTAL_ASSAYS, expand=True)
Expand All @@ -1333,9 +1335,13 @@ def calc_toxcast_percent_active(df):
dft["TOXCAST_NUMBER_OF_ASSAYS/TOTAL"].astype("str").str.extract(NUMBER_ASSAYS, expand=True)
)

# Convert the value columns to floats and do division to get the percent active value
dft["TOTAL_ASSAYS_TESTED"] = dft["TOTAL_ASSAYS_TESTED"].astype(float)
dft["NUMBER_ACTIVE_ASSAYS"] = dft["NUMBER_ACTIVE_ASSAYS"].astype(float)

dft["TOXCAST_PERCENT_ACTIVE"] = dft["NUMBER_ACTIVE_ASSAYS"] / dft["TOTAL_ASSAYS_TESTED"] * 100
dft["TOXCAST_PERCENT_ACTIVE"] = dft["TOXCAST_PERCENT_ACTIVE"].apply(lambda x: round(x, 2))

# Clean up and remove the temporary value columns
dft = dft.drop(["TOTAL_ASSAYS_TESTED", "NUMBER_ACTIVE_ASSAYS"], 1)

return dft

0 comments on commit 010217a

Please sign in to comment.