Skip to content

Commit 2b49d5d

Browse files
author
david.degnan@pnnl.gov
committedJan 15, 2025
Finished with Simplified Class
1 parent 5cab021 commit 2b49d5d

7 files changed

+1651
-1817
lines changed
 

‎bmdrc/filtering.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -379,14 +379,22 @@ def correlation_score(self, score, apply, diagnostic_plot):
379379
# Pull plate groups
380380
CorScore = self.plate_groups
381381

382-
# First, only keep the values that aren't being filtered
383-
CorScore = CorScore.loc[CorScore["bmdrc.filter"] == "Keep", [self.concentration, "bmdrc.Endpoint.ID", "bmdrc.num.nonna", "bmdrc.num.affected"]]
382+
# If the data is BinaryClass where plate and well information is available, do the following
383+
if hasattr(self, "value"):
384+
385+
# First, only keep the values that aren't being filtered
386+
CorScore = CorScore.loc[CorScore["bmdrc.filter"] == "Keep", [self.concentration, "bmdrc.Endpoint.ID", "bmdrc.num.nonna", "bmdrc.num.affected"]]
384387

385-
# Sum up counts
386-
CorScore = CorScore.groupby([self.concentration, "bmdrc.Endpoint.ID"]).sum().reset_index()
388+
# Sum up counts
389+
CorScore = CorScore.groupby([self.concentration, "bmdrc.Endpoint.ID"]).sum().reset_index()
390+
391+
# Calculate response
392+
CorScore["Response"] = CorScore["bmdrc.num.affected"] / CorScore["bmdrc.num.nonna"]
393+
394+
else:
387395

388-
# Calculate response
389-
CorScore["Response"] = CorScore["bmdrc.num.affected"] / CorScore["bmdrc.num.nonna"]
396+
# Calculate the response
397+
CorScore = CorScore.loc[CorScore["bmdrc.filter"] == "Keep", [self.concentration, "bmdrc.Endpoint.ID", self.response]].rename(columns = {self.response:"Response"})
390398

391399
# Sort data.frame appropriately
392400
CorScore.sort_values(by = ["bmdrc.Endpoint.ID", self.concentration])

‎bmdrc/model_fitting.py

+25-7
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,10 @@ def removed_endpoints_stats(self):
599599
low_quality = self.plate_groups[self.plate_groups["bmdrc.filter"] == "Remove"]
600600

601601
# Calculate the fraction affected
602-
low_quality["frac.affected"] = low_quality["bmdrc.num.affected"] / low_quality["bmdrc.num.nonna"]
602+
if hasattr(self, "value"):
603+
low_quality["frac.affected"] = low_quality["bmdrc.num.affected"] / low_quality["bmdrc.num.nonna"]
604+
else:
605+
low_quality["frac.affected"] = low_quality[self.response]
603606

604607
# Group values by endpoint ID
605608
low_quality = low_quality.groupby("bmdrc.Endpoint.ID")
@@ -632,7 +635,13 @@ def select_and_run_models(self, gof_threshold, aic_threshold, model_selection, d
632635
self.model_fitting_model_selection = model_selection
633636

634637
# Add fraction affected to plate groups
635-
self.plate_groups["bmdrc.frac.affected"] = self.plate_groups["bmdrc.num.affected"] / self.plate_groups["bmdrc.num.nonna"]
638+
if hasattr(self, "value"):
639+
self.plate_groups["bmdrc.frac.affected"] = self.plate_groups["bmdrc.num.affected"] / self.plate_groups["bmdrc.num.nonna"]
640+
else:
641+
self.plate_groups["bmdrc.frac.affected"] = self.plate_groups[self.response]
642+
self.plate_groups["bmdrc.num.tot"] = np.nan
643+
self.plate_groups["bmdrc.num.affected"] = self.plate_groups["bmdrc.frac.affected"]
644+
self.plate_groups["bmdrc.num.nonna"] = 1
636645

637646
# Pull dose_response
638647
dose_response = self.plate_groups[self.plate_groups["bmdrc.filter"] == "Keep"]
@@ -651,11 +660,20 @@ def select_and_run_models(self, gof_threshold, aic_threshold, model_selection, d
651660
# Subset to endpoint
652661
sub_data = dose_response[dose_response["bmdrc.Endpoint.ID"] == endpoint]
653662

654-
# Only keep required columns, and sum counts across plates
655-
sub_data = sub_data[[self.concentration, "bmdrc.num.tot", "bmdrc.num.affected", "bmdrc.num.nonna"]].groupby(self.concentration).sum().reset_index()
663+
if hasattr(self, "value"):
664+
665+
# Only keep required columns, and sum counts across plates
666+
sub_data = sub_data[[self.concentration, "bmdrc.num.tot", "bmdrc.num.affected", "bmdrc.num.nonna"]].groupby(self.concentration).sum().reset_index()
667+
668+
# Calculate fraction affected
669+
sub_data["bmdrc.frac.affected"] = sub_data["bmdrc.num.affected"] / sub_data["bmdrc.num.nonna"]
656670

657-
# Calculate fraction affected
658-
sub_data["bmdrc.frac.affected"] = sub_data["bmdrc.num.affected"] / sub_data["bmdrc.num.nonna"]
671+
else:
672+
673+
sub_data = sub_data[[self.concentration, "bmdrc.frac.affected"]].groupby(self.concentration).sum().reset_index()
674+
sub_data["bmdrc.num.tot"] = np.nan
675+
sub_data["bmdrc.num.affected"] = sub_data["bmdrc.frac.affected"]
676+
sub_data["bmdrc.num.nonna"] = 1
659677

660678
# Calculate P-Value Function
661679
def calc_p_value(PredictedValues, Params):
@@ -1006,7 +1024,7 @@ def calc_fit_statistics(self):
10061024

10071025
# Get the dose response data
10081026
Data = self.plate_groups[self.plate_groups["bmdrc.Endpoint.ID"] == id]
1009-
1027+
10101028
# Get the AUC, min, and max dose
10111029
AUC = np.trapz(Data["bmdrc.frac.affected"], x = Data[self.concentration])
10121030
Min_Dose = round(min(Data[self.concentration]), 4)

‎bmdrc/output_modules.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def benchmark_dose(self, path):
3030
BMDS_Final = BMDS
3131

3232
# Add those that failed the p-value checks
33-
if self.failed_pvalue_test is not None:
33+
if hasattr(self, "failed_pvalue_test"):
3434

3535
# Make a data frame with all endpoints that failed the p-value checks
3636
pvalue_fails = self.plate_groups[self.plate_groups["bmdrc.Endpoint.ID"].isin(self.failed_pvalue_test)]

‎data/ToxExample_Long.txt

+70-46
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,78 @@
11
chemical.id endpoint concentration response
2-
DTXSID7020182 Tox21_202992 0 0.0247
3-
DTXSID7020182 Tox21_202992 0 0.0004
4-
DTXSID7020182 Tox21_202992 0 0.0097
5-
DTXSID7020182 Tox21_202992 0.003 0.0157
6-
DTXSID7020182 Tox21_202992 0.003 0
7-
DTXSID7020182 Tox21_202992 0.003 0
8-
DTXSID7020182 Tox21_202992 0.007 0.04
9-
DTXSID7020182 Tox21_202992 0.007 0.0423
10-
DTXSID7020182 Tox21_202992 0.007 0
11-
DTXSID7020182 Tox21_202992 0.01 0.0606
12-
DTXSID7020182 Tox21_202992 0.01 0.0234
13-
DTXSID7020182 Tox21_202992 0.01 0
14-
DTXSID7020182 Tox21_202992 0.03 0.1037
15-
DTXSID7020182 Tox21_202992 0.03 0.0175
16-
DTXSID7020182 Tox21_202992 0.03 0
17-
DTXSID7020182 Tox21_202992 0.07 0.0097
18-
DTXSID7020182 Tox21_202992 0.07 0
19-
DTXSID7020182 Tox21_202992 0.1 0.0559
20-
DTXSID7020182 Tox21_202992 0.1 0.0111
21-
DTXSID7020182 Tox21_202992 0.1 0
22-
DTXSID7020182 Tox21_202992 0.3 0.0158
23-
DTXSID7020182 Tox21_202992 0.3 0
24-
DTXSID7020182 Tox21_202992 0.3 0
25-
DTXSID7020182 Tox21_202992 0.7 0.0165
26-
DTXSID7020182 Tox21_202992 0.7 0
27-
DTXSID7020182 Tox21_202992 0.7 0
28-
DTXSID7020182 Tox21_202992 2 0.0827
29-
DTXSID7020182 Tox21_202992 2 0.0271
30-
DTXSID7020182 Tox21_202992 2 0
31-
DTXSID7020182 Tox21_202992 4 0
32-
DTXSID7020182 Tox21_202992 4 0
33-
DTXSID7020182 Tox21_202992 4 0
34-
DTXSID7020182 Tox21_202992 8 0.0542
35-
DTXSID7020182 Tox21_202992 8 0
36-
DTXSID7020182 Tox21_202992 8 0
37-
DTXSID7020182 Tox21_202992 20 0.0697
38-
DTXSID7020182 Tox21_202992 20 0
39-
DTXSID7020182 Tox21_202992 20 0
40-
DTXSID7020182 Tox21_202992 40 0.5292
41-
DTXSID7020182 Tox21_202992 40 0.1713
42-
DTXSID7020182 Tox21_202992 40 0.0747
43-
DTXSID7020182 Tox21_202992 90 1
44-
DTXSID7020182 Tox21_202992 90 1
45-
DTXSID7020182 Tox21_202992 90 0.9322
2+
DTXSID7020182 202992 0 0.0247
3+
DTXSID7020182 202992 0 0.0004
4+
DTXSID7020182 202992 0 0.0097
5+
DTXSID7020182 202992 0.003 0.0157
6+
DTXSID7020182 202992 0.003 0
7+
DTXSID7020182 202992 0.003 0
8+
DTXSID7020182 202992 0.007 0.04
9+
DTXSID7020182 202992 0.007 0.0423
10+
DTXSID7020182 202992 0.007 0
11+
DTXSID7020182 202992 0.01 0.0606
12+
DTXSID7020182 202992 0.01 0.0234
13+
DTXSID7020182 202992 0.01 0
14+
DTXSID7020182 202992 0.03 0.1037
15+
DTXSID7020182 202992 0.03 0.0175
16+
DTXSID7020182 202992 0.03 0
17+
DTXSID7020182 202992 0.07 0.0097
18+
DTXSID7020182 202992 0.07 0
19+
DTXSID7020182 202992 0.1 0.0559
20+
DTXSID7020182 202992 0.1 0.0111
21+
DTXSID7020182 202992 0.1 0
22+
DTXSID7020182 202992 0.3 0.0158
23+
DTXSID7020182 202992 0.3 0
24+
DTXSID7020182 202992 0.3 0
25+
DTXSID7020182 202992 0.7 0.0165
26+
DTXSID7020182 202992 0.7 0
27+
DTXSID7020182 202992 0.7 0
28+
DTXSID7020182 202992 2 0.0827
29+
DTXSID7020182 202992 2 0.0271
30+
DTXSID7020182 202992 2 0
31+
DTXSID7020182 202992 4 0
32+
DTXSID7020182 202992 4 0
33+
DTXSID7020182 202992 4 0
34+
DTXSID7020182 202992 8 0.0542
35+
DTXSID7020182 202992 8 0
36+
DTXSID7020182 202992 8 0
37+
DTXSID7020182 202992 20 0.0697
38+
DTXSID7020182 202992 20 0
39+
DTXSID7020182 202992 20 0
40+
DTXSID7020182 202992 40 0.5292
41+
DTXSID7020182 202992 40 0.1713
42+
DTXSID7020182 202992 40 0.0747
43+
DTXSID7020182 202992 90 1
44+
DTXSID7020182 202992 90 1
45+
DTXSID7020182 202992 90 0.9322
4646
Chemical2 Endpoint1 0 0
47+
Chemical2 Endpoint1 0 0.01
48+
Chemical2 Endpoint1 0 0
49+
Chemical2 Endpoint1 0 0.01
50+
Chemical2 Endpoint1 0 0
51+
Chemical2 Endpoint1 2 0.02
4752
Chemical2 Endpoint1 2 0.04
53+
Chemical2 Endpoint1 2 0.05
54+
Chemical2 Endpoint1 2 0.01
55+
Chemical2 Endpoint1 2 0
4856
Chemical2 Endpoint1 8 0.06
57+
Chemical2 Endpoint1 8 0.12
58+
Chemical2 Endpoint1 8 0.15
59+
Chemical2 Endpoint1 8 0.18
60+
Chemical2 Endpoint1 8 0.12
4961
Chemical2 Endpoint1 10 0.28
50-
Chemical2 Endpoint1 20 0.8
51-
Chemical2 Endpoint1 40 0.9
62+
Chemical2 Endpoint1 10 0.33
63+
Chemical2 Endpoint1 10 0.23
64+
Chemical2 Endpoint1 10 0.19
65+
Chemical2 Endpoint1 10 0.40
66+
Chemical2 Endpoint1 20 0.81
67+
Chemical2 Endpoint1 20 0.66
68+
Chemical2 Endpoint1 20 0.71
69+
Chemical2 Endpoint1 20 0.54
70+
Chemical2 Endpoint1 20 0.81
71+
Chemical2 Endpoint1 40 0.99
72+
Chemical2 Endpoint1 40 0.99
73+
Chemical2 Endpoint1 40 0.98
74+
Chemical2 Endpoint1 40 0.99
75+
Chemical2 Endpoint1 40 0.66
5276
Chemical2 Endpoint2 0 0
5377
Chemical2 Endpoint2 2 0
5478
Chemical2 Endpoint2 8 0.08

‎vignettes/Binary Class Example.ipynb

+182-128
Large diffs are not rendered by default.

‎vignettes/LPR Class Example.ipynb

+420-886
Large diffs are not rendered by default.

‎vignettes/Simplified Class Example.ipynb

+939-743
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.