forked from enviPath/enviPy
**This pull request will need a separate migration pull-request**
I have added an alert box in two places when the user tries to predict with stereo chemistry.
When a user predicts a pathway with stereo chemistry an alert box is shown in that node's hover.
To do this I added two new fields. Pathway now has a "predicted" BooleanField indicating whether it was predicted or not. It is set to True if the pathway mode for prediction is "predict" or "incremental" and False if it is "build". I think it is a flag that could be useful in the future, perhaps for analysing how many predicted pathways are in enviPath?
Node now has a `stereo_removed` BooleanField which is set to True if the Node's parent Pathways has "predicted" as true and the node SMILES has stereochemistry.
<img width="500" alt="{927AC9FF-DBC9-4A19-9E6E-0EDD3B08C7AC}.png" src="attachments/69ea29bc-c2d2-4cd2-8e98-aae5c5737f69">
When a user does a prediction on a model's page it shows at the top of the list. This did not require any new fields as the entered SMILES does not get saved anywhere.
<img width="500" alt="{BED66F12-5F07-419E-AAA6-FE1FE5B4F266}.png" src="attachments/5fcc3a9b-4d1a-4e48-acac-76b7571f6507">
I think the alert box is an alright solution but if you have a great idea for something that looks/fits better please change it or let me know.
Co-authored-by: Tim Lorsbach <tim@lorsba.ch>
Reviewed-on: enviPath/enviPy#250
Co-authored-by: Liam Brydon <lbry121@aucklanduni.ac.nz>
Co-committed-by: Liam Brydon <lbry121@aucklanduni.ac.nz>
128 lines
4.3 KiB
Python
128 lines
4.3 KiB
Python
from django.conf import settings as s
|
|
from django.test import TestCase, override_settings
|
|
from django.urls import reverse
|
|
|
|
from epdb.logic import UserManager
|
|
from epdb.models import User
|
|
|
|
Package = s.GET_PACKAGE_MODEL()
|
|
|
|
|
|
@override_settings(MODEL_DIR=s.FIXTURE_DIRS[0] / "models", CELERY_TASK_ALWAYS_EAGER=True)
|
|
class ModelViewTest(TestCase):
|
|
fixtures = ["test_fixtures_incl_model.jsonl.gz"]
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
super(ModelViewTest, cls).setUpClass()
|
|
cls.user1 = UserManager.create_user(
|
|
"user1",
|
|
"user1@envipath.com",
|
|
"SuperSafe",
|
|
set_setting=True,
|
|
add_to_group=True,
|
|
is_active=True,
|
|
)
|
|
cls.user1_default_package = cls.user1.default_package
|
|
cls.model_package = Package.objects.get(name="Fixtures")
|
|
|
|
def setUp(self):
|
|
self.client.force_login(self.user1)
|
|
|
|
def test_predict(self):
|
|
self.client.force_login(User.objects.get(username="admin"))
|
|
response = self.client.get(
|
|
reverse(
|
|
"package model detail",
|
|
kwargs={
|
|
"package_uuid": str(self.model_package.uuid),
|
|
"model_uuid": str(self.model_package.models.first().uuid),
|
|
},
|
|
),
|
|
{
|
|
"classify": "ILikeCats!",
|
|
"smiles": "CCN(CC)C(=O)C1=CC(=CC=C1)CO",
|
|
},
|
|
)
|
|
|
|
expected = [
|
|
{
|
|
"products": [["O=C(O)C1=CC(CO)=CC=C1", "CCNCC"]],
|
|
"probability": 0.25,
|
|
"btrule": {
|
|
"url": "http://localhost:8000/package/1869d3f0-60bb-41fd-b6f8-afa75ffb09d3/simple-ambit-rule/0e6e9290-b658-4450-b291-3ec19fa19206",
|
|
"name": "bt0430-4011",
|
|
},
|
|
},
|
|
{
|
|
"products": [["CCNC(=O)C1=CC(CO)=CC=C1", "CC=O"]],
|
|
"probability": 0.0,
|
|
"btrule": {
|
|
"url": "http://localhost:8000/package/1869d3f0-60bb-41fd-b6f8-afa75ffb09d3/simple-ambit-rule/27a3a353-0b66-4228-bd16-e407949e90df",
|
|
"name": "bt0243-4301",
|
|
},
|
|
},
|
|
{
|
|
"products": [["CCN(CC)C(=O)C1=CC(C=O)=CC=C1"]],
|
|
"probability": 0.75,
|
|
"btrule": {
|
|
"url": "http://localhost:8000/package/1869d3f0-60bb-41fd-b6f8-afa75ffb09d3/simple-ambit-rule/2f2e0c39-e109-4836-959f-2bda2524f022",
|
|
"name": "bt0001-3568",
|
|
},
|
|
},
|
|
]
|
|
|
|
actual = response.json()["pred"]
|
|
self.assertEqual(actual, expected)
|
|
|
|
response = self.client.get(
|
|
reverse(
|
|
"package model detail",
|
|
kwargs={
|
|
"package_uuid": str(self.model_package.uuid),
|
|
"model_uuid": str(self.model_package.models.first().uuid),
|
|
},
|
|
),
|
|
{
|
|
"classify": "ILikeCats!",
|
|
"smiles": "",
|
|
},
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
self.assertEqual(response.json()["error"], "Received empty SMILES")
|
|
|
|
response = self.client.get(
|
|
reverse(
|
|
"package model detail",
|
|
kwargs={
|
|
"package_uuid": str(self.model_package.uuid),
|
|
"model_uuid": str(self.model_package.models.first().uuid),
|
|
},
|
|
),
|
|
{
|
|
"classify": "ILikeCats!",
|
|
"smiles": " ", # Input should be stripped
|
|
},
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
self.assertEqual(response.json()["error"], "Received empty SMILES")
|
|
|
|
response = self.client.get(
|
|
reverse(
|
|
"package model detail",
|
|
kwargs={
|
|
"package_uuid": str(self.model_package.uuid),
|
|
"model_uuid": str(self.model_package.models.first().uuid),
|
|
},
|
|
),
|
|
{
|
|
"classify": "ILikeCats!",
|
|
"smiles": "RandomInput",
|
|
},
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
self.assertEqual(response.json()["error"], '"RandomInput" is not a valid SMILES')
|