Skip to content

Commit

Permalink
Treatment Related Effect (#681)
Browse files Browse the repository at this point in the history
* created treatment effect

* exports

* arrows for constants

* helptext, tests

* fix popup

* updates from review

* remove hasData

Co-authored-by: Andy Shapiro <shapiromatron@gmail.com>
  • Loading branch information
caseyhans and shapiromatron authored Aug 24, 2022
1 parent cb2655f commit 9ab8d21
Show file tree
Hide file tree
Showing 16 changed files with 160 additions and 4 deletions.
10 changes: 8 additions & 2 deletions frontend/animal/EndpointTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class EndpointTable {
.map(function(d) {
return d[val];
})
.some($.isNumeric)
.some(x => !_.isNil(x))
.value();
}

Expand Down Expand Up @@ -83,7 +83,10 @@ class EndpointTable {
default:
throw "Unknown data type.";
}

this.hasTreatmentColumn = this.hasValues("treatment_effect");
if (this.hasTreatmentColumn) {
tr.append("<th>Treatment Related Effect</th>");
}
this.number_columns = tr.children().length;
this.thead = $("<thead>").append(tr);
}
Expand Down Expand Up @@ -113,6 +116,9 @@ class EndpointTable {
`<td>${self.endpoint._dichotomous_percent_change_incidence(v)}%</td>`
);
}
if (self.hasTreatmentColumn) {
tr.append(`<td>${v.treatment_effect || "---"}</td>`);
}
self.tbody.append(tr);
});
}
Expand Down
8 changes: 8 additions & 0 deletions hawc/apps/animal/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ class LitterEffect(models.TextChoices):
O = "O", "Other" # noqa: E741


class TreatmentEffect(models.IntegerChoices):
NR = 0, "not reported"
YES_UP = 1, "yes ↑"
YES_DOWN = 2, "yes ↓"
YES = 3, "yes"
NO = 4, "no"


# bool can't be subclassed with models.Choices
POSITIVE_CONTROL_CHOICES = (
(True, "Yes"),
Expand Down
8 changes: 7 additions & 1 deletion hawc/apps/animal/exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ def _get_header_row(self):
"upper_ci",
"pairwise significant",
"pairwise significant value",
"treatment related effect",
"percent control mean",
"percent control low",
"percent control high",
Expand Down Expand Up @@ -358,6 +359,7 @@ def _get_data_rows(self):
eg["upper_ci"],
eg["significant"],
eg["significance_level"],
eg["treatment_effect"],
eg["percentControlMean"],
eg["percentControlLow"],
eg["percentControlHigh"],
Expand Down Expand Up @@ -438,6 +440,7 @@ def _get_header_row(self):
rng = range(1, num_doses + 1)
header.extend([f"Dose {i}" for i in rng])
header.extend([f"Significant {i}" for i in rng])
header.extend([f"Treatment Related Effect {i}" for i in rng])
header.extend(list(self.rob_headers.values()))

# distinct applied last so that queryset can add annotations above
Expand Down Expand Up @@ -585,9 +588,12 @@ def _get_data_rows(self):

sigs = get_significance_and_direction(ser["data_type"], ser["groups"])
sigs.extend([None] * (self.num_doses - len(sigs)))

row.extend(sigs)

tres = [dose["treatment_effect"] for dose in ser["groups"]]
tres.extend([None] * (self.num_doses - len(tres)))
row.extend(tres)

row.extend(
[self.rob_data[(ser["id"], metric_id)] for metric_id in self.rob_headers.keys()]
)
Expand Down
1 change: 1 addition & 0 deletions hawc/apps/animal/migrations/0019_py3_unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ class Migration(migrations.Migration):
field=models.FloatField(
blank=True,
default=None,
help_text="Enter statistical significance level for the effect. Typically this is as presented in the study. Indicate in the results comment field if it is based on statistical analysis conducted by the assessment team",
null=True,
validators=[
django.core.validators.MinValueValidator(0),
Expand Down
22 changes: 22 additions & 0 deletions hawc/apps/animal/migrations/0031_tre.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("animal", "0030_django31"),
]

operations = [
migrations.AddField(
model_name="endpointgroup",
name="treatment_effect",
field=models.PositiveSmallIntegerField(
blank=True,
choices=[(0, "not reported"), (1, "yes ↑"), (2, "yes ↓"), (3, "yes"), (4, "no")],
default=None,
help_text="Expert judgement based report of treatment related effects (add direction if known). Use when statistical analysis not available. In results comments, indicate whether it was author judgment or assessment team judgement",
null=True,
),
)
]
10 changes: 10 additions & 0 deletions hawc/apps/animal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,14 @@ class EndpointGroup(ConfidenceIntervalsMixin, models.Model):
default=None,
validators=[MinValueValidator(0), MaxValueValidator(1)],
verbose_name="Statistical significance level",
help_text="Enter statistical significance level for the effect. Typically this is as presented in the study. Indicate in the results comment field if it is based on statistical analysis conducted by the assessment team",
)
treatment_effect = models.PositiveSmallIntegerField(
null=True,
blank=True,
default=None,
choices=constants.TreatmentEffect.choices,
help_text="Expert judgement based report of treatment related effects (add direction if known). Use when statistical analysis not available. In results comments, indicate whether it was author judgment or assessment team judgement",
)

COPY_NAME = "groups"
Expand Down Expand Up @@ -1550,6 +1558,7 @@ def flat_complete_header_row():
"endpoint_group-upper_ci",
"endpoint_group-significant",
"endpoint_group-significance_level",
"endpoint_group-treatment_effect",
"endpoint_group-NOEL",
"endpoint_group-LOEL",
"endpoint_group-FEL",
Expand All @@ -1568,6 +1577,7 @@ def flat_complete_data_row(ser, endpoint):
ser["upper_ci"],
ser["significant"],
ser["significance_level"],
ser["treatment_effect"],
ser["dose_group_id"] == endpoint["NOEL"],
ser["dose_group_id"] == endpoint["LOEL"],
ser["dose_group_id"] == endpoint["FEL"],
Expand Down
1 change: 1 addition & 0 deletions hawc/apps/animal/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ def to_representation(self, instance):
ret = super().to_representation(instance)
ret["hasVariance"] = instance.hasVariance
ret["isReported"] = instance.isReported
ret["treatment_effect"] = instance.get_treatment_effect_display()
return ret

def validate(self, data):
Expand Down
9 changes: 8 additions & 1 deletion hawc/apps/animal/templates/animal/endpoint_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@
<th id="varianceHeader" class="c_only">Variance (SD or SE)</th>
<th class="p_only">Low CI (%)</th>
<th class="p_only">High CI (%)</th>
<th>Significance<br>Level<br>(if significant)</th>
<th>Significance<br>Level<br>(if significant)
{% include "common/helptext_popup.html" with text=formset.0.significance_level.help_text %}
</th>
<th>Treatment Related Effect
{% include "common/helptext_popup.html" with text=formset.0.treatment_effect.help_text %}
</th>
</tr>
</thead>
<tbody>
Expand All @@ -77,6 +82,7 @@
<th class="p_only">{{form.lower_ci}}{{form.lower_ci.errors|add_class:"alert alert-danger"}}</th>
<th class="p_only">{{form.upper_ci}}{{form.upper_ci.errors|add_class:"alert alert-danger"}}</th>
<td>{{form.significance_level}}</td>
<td>{{form.treatment_effect}}</td>
</tr>
{% endfor %}
</tbody>
Expand Down Expand Up @@ -134,4 +140,5 @@
});
});
</script>
{% include "common/helptext_popup_js.html" %}
{% endblock %}
3 changes: 3 additions & 0 deletions hawc/apps/common/templates/common/helptext_popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<i class="ml-1 fa fa-fw fa-question-circle"
aria-hidden="true" data-html="true" data-toggle="popover"
title="{{title}}" data-content="{{text}}"></i>
9 changes: 9 additions & 0 deletions hawc/apps/common/templates/common/helptext_popup_js.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script type="text/javascript">
$(document).ready(() => {
$('[data-toggle="popover"]').popover({
placement: "auto",
trigger: "hover",
delay: { show: 100, hide: 1000 },
})
});
</script>
15 changes: 15 additions & 0 deletions tests/data/api/api-animal-assessment-full-export.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"endpoint_group-response": 15.0,
"endpoint_group-significance_level": null,
"endpoint_group-significant": false,
"endpoint_group-treatment_effect": null,
"endpoint_group-upper_ci": 15.7956244909,
"endpoint_group-variance": 1.7,
"experiment-cas": "1163-19-5",
Expand Down Expand Up @@ -178,6 +179,7 @@
"endpoint_group-response": 11.0,
"endpoint_group-significance_level": null,
"endpoint_group-significant": false,
"endpoint_group-treatment_effect": null,
"endpoint_group-upper_ci": 11.8892273722,
"endpoint_group-variance": 1.9,
"experiment-cas": "1163-19-5",
Expand Down Expand Up @@ -286,6 +288,7 @@
"endpoint_group-response": 15.0,
"endpoint_group-significance_level": null,
"endpoint_group-significant": false,
"endpoint_group-treatment_effect": null,
"endpoint_group-upper_ci": 16.0764331348,
"endpoint_group-variance": 2.3,
"experiment-cas": "1163-19-5",
Expand Down Expand Up @@ -394,6 +397,7 @@
"endpoint_group-response": 12.0,
"endpoint_group-significance_level": null,
"endpoint_group-significant": false,
"endpoint_group-treatment_effect": null,
"endpoint_group-upper_ci": 13.0296316941,
"endpoint_group-variance": 2.2,
"experiment-cas": "1163-19-5",
Expand Down Expand Up @@ -502,6 +506,7 @@
"endpoint_group-response": 9.0,
"endpoint_group-significance_level": 0.05,
"endpoint_group-significant": true,
"endpoint_group-treatment_effect": null,
"endpoint_group-upper_ci": 9.5616172877,
"endpoint_group-variance": 1.2,
"experiment-cas": "1163-19-5",
Expand Down Expand Up @@ -610,6 +615,7 @@
"endpoint_group-response": null,
"endpoint_group-significance_level": null,
"endpoint_group-significant": false,
"endpoint_group-treatment_effect": null,
"endpoint_group-upper_ci": null,
"endpoint_group-variance": null,
"experiment-cas": "1163-19-5",
Expand Down Expand Up @@ -718,6 +724,7 @@
"endpoint_group-response": null,
"endpoint_group-significance_level": null,
"endpoint_group-significant": false,
"endpoint_group-treatment_effect": null,
"endpoint_group-upper_ci": null,
"endpoint_group-variance": null,
"experiment-cas": "1163-19-5",
Expand Down Expand Up @@ -826,6 +833,7 @@
"endpoint_group-response": null,
"endpoint_group-significance_level": null,
"endpoint_group-significant": false,
"endpoint_group-treatment_effect": null,
"endpoint_group-upper_ci": null,
"endpoint_group-variance": null,
"experiment-cas": "1163-19-5",
Expand Down Expand Up @@ -934,6 +942,7 @@
"endpoint_group-response": null,
"endpoint_group-significance_level": null,
"endpoint_group-significant": false,
"endpoint_group-treatment_effect": null,
"endpoint_group-upper_ci": null,
"endpoint_group-variance": null,
"experiment-cas": "1163-19-5",
Expand Down Expand Up @@ -1042,6 +1051,7 @@
"endpoint_group-response": null,
"endpoint_group-significance_level": null,
"endpoint_group-significant": false,
"endpoint_group-treatment_effect": null,
"endpoint_group-upper_ci": null,
"endpoint_group-variance": null,
"experiment-cas": "1163-19-5",
Expand Down Expand Up @@ -1150,6 +1160,7 @@
"endpoint_group-response": null,
"endpoint_group-significance_level": null,
"endpoint_group-significant": false,
"endpoint_group-treatment_effect": null,
"endpoint_group-upper_ci": 0.3408051366,
"endpoint_group-variance": null,
"experiment-cas": "1163-19-5",
Expand Down Expand Up @@ -1258,6 +1269,7 @@
"endpoint_group-response": null,
"endpoint_group-significance_level": null,
"endpoint_group-significant": false,
"endpoint_group-treatment_effect": null,
"endpoint_group-upper_ci": 0.3408051366,
"endpoint_group-variance": null,
"experiment-cas": "1163-19-5",
Expand Down Expand Up @@ -1366,6 +1378,7 @@
"endpoint_group-response": null,
"endpoint_group-significance_level": null,
"endpoint_group-significant": false,
"endpoint_group-treatment_effect": null,
"endpoint_group-upper_ci": 0.4871743473,
"endpoint_group-variance": null,
"experiment-cas": "1163-19-5",
Expand Down Expand Up @@ -1474,6 +1487,7 @@
"endpoint_group-response": null,
"endpoint_group-significance_level": null,
"endpoint_group-significant": false,
"endpoint_group-treatment_effect": null,
"endpoint_group-upper_ci": 0.4171011516,
"endpoint_group-variance": null,
"experiment-cas": "1163-19-5",
Expand Down Expand Up @@ -1582,6 +1596,7 @@
"endpoint_group-response": null,
"endpoint_group-significance_level": null,
"endpoint_group-significant": false,
"endpoint_group-treatment_effect": null,
"endpoint_group-upper_ci": 0.7265646156,
"endpoint_group-variance": null,
"experiment-cas": "1163-19-5",
Expand Down
Loading

0 comments on commit 9ab8d21

Please sign in to comment.