Commit a075f990 authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

add Kd ratio activity to compound activity test types

as discussed with @osperand following up on #204
parent 1d2b29eb
......@@ -844,7 +844,7 @@ class CompoundActivityResultForm(ModelForm):
activity_unit = forms.CharField(
label="Activity unit",
max_length=5,
required=True,
required=False,
widget=widgets.Select(
choices=(
(None, "-----"),
......@@ -855,6 +855,7 @@ class CompoundActivityResultForm(ModelForm):
("1e-12", "pmol"),
),
),
help_text="Only required if 'activity type' is not Kd ratio.",
)
class Meta:
......@@ -896,20 +897,27 @@ class CompoundActivityResultForm(ModelForm):
return cleaned_data
if cleaned_data["activity_mol"] is None:
return cleaned_data
if cleaned_data["activity_unit"] in (None, ""):
self.add_error("activity_unit", "Unit must be provided")
if (
cleaned_data.get("activity_unit", "") == ""
and cleaned_data.get("activity_type", None) != "KdRat"
):
self.add_error("activity_unit", "Unit is required if type is not Kd ratio")
return cleaned_data
try:
d = Decimal(
-log10(
Decimal(self.cleaned_data["activity_mol"])
* Decimal(self.cleaned_data["activity_unit"])
if self.cleaned_data["activity_type"] != "KdRat":
d = Decimal(
-log10(
Decimal(self.cleaned_data["activity_mol"])
* Decimal(self.cleaned_data["activity_unit"])
)
)
)
d = d.quantize(
Decimal(10) ** -self.instance._meta.get_field("activity").decimal_places
)
self.cleaned_data["activity"] = d
d = d.quantize(
Decimal(10)
** -self.instance._meta.get_field("activity").decimal_places
)
self.cleaned_data["activity"] = d
else:
self.cleaned_data["activity"] = self.cleaned_data["activity_mol"]
except Exception as e:
self.add_error(
"activity_mol",
......@@ -945,6 +953,7 @@ class CompoundActivityResultBaseInlineNestedFormSet(BaseInlineNestedFormSet):
("pEC50", "EC50 (half maximal effective concentration)"),
("pKd", "Kd (dissociation constant)"),
("pKi", "Ki (inhibition constant)"),
("KdRat", "Kd ratio (Kd w/o ligand / Kd with ligand"),
]
def add_fields(self, form, index):
......
# Generated by Django 2.2.1 on 2020-04-20 20:15
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ippidb', '0049_auto_20200419_2005'),
]
operations = [
migrations.AlterField(
model_name='compoundactivityresult',
name='activity_type',
field=models.CharField(choices=[('pIC50', 'pIC50 (half maximal inhibitory concentration, -log10)'), ('pEC50', 'pEC50 (half maximal effective concentration, -log10)'), ('pKd', 'pKd (dissociation constant, -log10)'), ('pKi', 'pKi (inhibition constant, -log10)'), ('KdRat', 'Kd ratio (Kd without/with ligand')], max_length=5, verbose_name='Activity type'),
),
]
......@@ -1078,6 +1078,7 @@ class CompoundActivityResult(models.Model):
("pEC50", "pEC50 (half maximal effective concentration, -log10)"),
("pKd", "pKd (dissociation constant, -log10)"),
("pKi", "pKi (inhibition constant, -log10)"),
("KdRat", "Kd ratio (Kd without/with ligand"),
)
compound = models.ForeignKey(Compound, models.CASCADE)
test_activity_description = models.ForeignKey(
......
......@@ -49,9 +49,8 @@ activity_tests:
cell_line_name: 'Human small-cell lung cancer'
protein_complex: '1'
compound_activity_results:
- activity_mol: 61
activity_type: pIC50
activity_unit: 1e-9
- activity_mol: 20
activity_type: "KdRat"
compound_name: 'compound 12'
modulation_type: I
\ No newline at end of file
......@@ -149,10 +149,15 @@ class ContributionE2ETestCase(TestCase):
"activity_mol" in compound_activity_results
and compound_activity_results["activity_mol"] != ""
):
compound_activity_results["activity"] = -math.log10(
Decimal(str(compound_activity_results["activity_mol"]))
* Decimal(str(compound_activity_results["activity_unit"]))
)
if compound_activity_results["activity_type"] != "KdRat":
compound_activity_results["activity"] = -math.log10(
Decimal(str(compound_activity_results["activity_mol"]))
* Decimal(str(compound_activity_results["activity_unit"]))
)
else:
compound_activity_results["activity"] = Decimal(
str(compound_activity_results["activity_mol"])
)
self._process_contribution_wizard_without_sanity_check(entry_data)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment