diff --git a/ippisite/ippidb/forms.py b/ippisite/ippidb/forms.py index 45fd7a56747c5177228710cbbbc652c40061cd6a..d62f6debe2dc3a22c70a59b3a90cc670068e7bb8 100644 --- a/ippisite/ippidb/forms.py +++ b/ippisite/ippidb/forms.py @@ -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): diff --git a/ippisite/ippidb/migrations/0050_auto_20200420_2015.py b/ippisite/ippidb/migrations/0050_auto_20200420_2015.py new file mode 100644 index 0000000000000000000000000000000000000000..1e8802eb65d8fd3e759a7b951a27ce54d13122db --- /dev/null +++ b/ippisite/ippidb/migrations/0050_auto_20200420_2015.py @@ -0,0 +1,18 @@ +# 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'), + ), + ] diff --git a/ippisite/ippidb/models.py b/ippisite/ippidb/models.py index 8f01f1afa9841144ce999e6d4790943fd7a11a47..b510423fa334708310c3b879dec4fb922de2468c 100644 --- a/ippisite/ippidb/models.py +++ b/ippisite/ippidb/models.py @@ -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( diff --git a/ippisite/ippidb/tests/test_simple_heterodimer_208.yaml b/ippisite/ippidb/tests/test_simple_heterodimer_208.yaml index 13859df89dc9adc196434a2d499cd82418d011a2..ca004f5a96001390d7a261a3b0edc49251282c5f 100644 --- a/ippisite/ippidb/tests/test_simple_heterodimer_208.yaml +++ b/ippisite/ippidb/tests/test_simple_heterodimer_208.yaml @@ -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 diff --git a/ippisite/ippidb/tests/tests_contribute_e2e.py b/ippisite/ippidb/tests/tests_contribute_e2e.py index ce253eb0248d4f1e866a42c00981cdbfaf8dd605..610f92f8d756e1c1c8ae2ef5905aad9a6efe6310 100644 --- a/ippisite/ippidb/tests/tests_contribute_e2e.py +++ b/ippisite/ippidb/tests/tests_contribute_e2e.py @@ -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)