forked from enviPath/enviPy
This is an initial implementation that creates a working minimal .i6z document. It passes schema validation and can be imported into IUCLID. Caveat: IUCLID files target individual compounds. Pathway is not actually covered by the format. It can be added in either soil or water and soil OECD endpoints. **I currently only implemented the soil endpoint for all data.** This sort of works, and I can report all degradation products in a pathway (not a nice view, but we can report many transformation products and add a diagram attachment in the future). Adding additional information is an absolute pain, as we need to explicitly map each type of information to the relevant OECD field. I use the XSD scheme for validation, but unfortunately the IUCLID parser is not fully compliant and requires a specific order, etc. The workflow is: finding the AI structure from the XSD scheme -> make the scheme validation pass -> upload to IUCLID to get obscure error messages -> guess what could be wrong -> repeat 💣 New specifications get released once per year, so we will have to update accordingly. I believe that this should be a more expensive feature, as it requires significant effort to uphold. Currently implemented for root compound only in SOIL: - Soil Texture 2 - Soil Texture 1 - pH value - Half-life per soil sample / scenario (mapped to disappearance; not sure about that). - CEC - Organic Matter (only Carbon) - Moisture content - Humidity <img width="2123" alt="image.png" src="attachments/d29830e1-65ef-4136-8939-1825e0959c62"> <img width="2124" alt="image.png" src="attachments/ac9de2ac-bf68-4ba4-b40b-82f810a9de93"> <img width="2139" alt="image.png" src="attachments/5674c7e6-865e-420e-974a-6b825b331e6c"> Reviewed-on: enviPath/enviPy#338 Co-authored-by: Tobias O <tobias.olenyi@envipath.com> Co-committed-by: Tobias O <tobias.olenyi@envipath.com>
203 lines
6.7 KiB
Python
203 lines
6.7 KiB
Python
from django.test import TestCase, override_settings
|
|
from django.urls import reverse
|
|
from django.conf import settings as s
|
|
|
|
from epdb.logic import UserManager, PackageManager
|
|
from epdb.models import Pathway, Edge
|
|
|
|
|
|
@override_settings(MODEL_DIR=s.FIXTURE_DIRS[0] / "models", CELERY_TASK_ALWAYS_EAGER=True)
|
|
class PathwayViewTest(TestCase):
|
|
fixtures = ["test_fixtures_incl_model.jsonl.gz"]
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
super(PathwayViewTest, 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.package = PackageManager.create_package(cls.user1, "Test", "Test Pack")
|
|
|
|
def setUp(self):
|
|
self.client.force_login(self.user1)
|
|
|
|
def test_predict_pathway(self):
|
|
response = self.client.post(
|
|
reverse("pathways"),
|
|
{
|
|
"name": "Test Pathway",
|
|
"description": "Just a Description",
|
|
"predict": "predict",
|
|
"smiles": "CCN(CC)C(=O)C1=CC(=CC=C1)CO",
|
|
},
|
|
)
|
|
self.assertEqual(response.status_code, 302)
|
|
pathway_url = response["Location"]
|
|
|
|
pw = Pathway.objects.get(url=pathway_url)
|
|
self.assertEqual(self.user1_default_package, pw.package)
|
|
|
|
self.assertEqual(pw.name, "Test Pathway")
|
|
self.assertEqual(pw.description, "Just a Description")
|
|
self.assertEqual(len(pw.root_nodes), 1)
|
|
self.assertEqual(
|
|
pw.root_nodes.first().default_node_label.smiles, "CCN(CC)C(=O)C1=CC(CO)=CC=C1"
|
|
)
|
|
|
|
first_level_nodes = {
|
|
# Edge 1
|
|
"CCN(CC)C(=O)C1=CC(C=O)=CC=C1",
|
|
# Edge 2
|
|
"CCNC(=O)C1=CC(CO)=CC=C1",
|
|
"CC=O",
|
|
# Edge 3
|
|
"CCNCC",
|
|
"O=C(O)C1=CC(CO)=CC=C1",
|
|
}
|
|
|
|
predicted_nodes = set()
|
|
edges = Edge.objects.filter(start_nodes__in=[pw.root_nodes.first()])
|
|
|
|
for edge in edges:
|
|
for n in edge.end_nodes.all():
|
|
predicted_nodes.add(n.default_node_label.smiles)
|
|
|
|
self.assertEqual(first_level_nodes, predicted_nodes)
|
|
|
|
def test_predict_package_pathway(self):
|
|
response = self.client.post(
|
|
reverse("package pathway list", kwargs={"package_uuid": str(self.package.uuid)}),
|
|
{
|
|
"name": "Test Pathway",
|
|
"description": "Just a Description",
|
|
"predict": "predict",
|
|
"smiles": "CCN(CC)C(=O)C1=CC(=CC=C1)CO",
|
|
},
|
|
)
|
|
self.assertEqual(response.status_code, 302)
|
|
pathway_url = response["Location"]
|
|
|
|
pw = Pathway.objects.get(url=pathway_url)
|
|
self.assertEqual(self.package, pw.package)
|
|
|
|
self.assertEqual(pw.name, "Test Pathway")
|
|
self.assertEqual(pw.description, "Just a Description")
|
|
self.assertEqual(len(pw.root_nodes), 1)
|
|
self.assertEqual(
|
|
pw.root_nodes.first().default_node_label.smiles, "CCN(CC)C(=O)C1=CC(CO)=CC=C1"
|
|
)
|
|
|
|
first_level_nodes = {
|
|
# Edge 1
|
|
"CCN(CC)C(=O)C1=CC(C=O)=CC=C1",
|
|
# Edge 2
|
|
"CCNC(=O)C1=CC(CO)=CC=C1",
|
|
"CC=O",
|
|
# Edge 3
|
|
"CCNCC",
|
|
"O=C(O)C1=CC(CO)=CC=C1",
|
|
}
|
|
|
|
predicted_nodes = set()
|
|
edges = Edge.objects.filter(start_nodes__in=[pw.root_nodes.first()])
|
|
|
|
for edge in edges:
|
|
for n in edge.end_nodes.all():
|
|
predicted_nodes.add(n.default_node_label.smiles)
|
|
|
|
self.assertEqual(first_level_nodes, predicted_nodes)
|
|
|
|
def test_set_aliases(self):
|
|
alias_1 = "Alias 1"
|
|
alias_2 = "Alias 2"
|
|
|
|
response = self.client.post(
|
|
reverse("package pathway list", kwargs={"package_uuid": str(self.package.uuid)}),
|
|
{
|
|
"name": "Test Pathway",
|
|
"description": "Just a Description",
|
|
"predict": "predict",
|
|
"smiles": "CCN(CC)C(=O)C1=CC(=CC=C1)CO",
|
|
},
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
pathway_url = response["Location"]
|
|
pw = Pathway.objects.get(url=pathway_url)
|
|
|
|
response = self.client.post(
|
|
reverse(
|
|
"package pathway detail",
|
|
kwargs={"package_uuid": str(pw.package.uuid), "pathway_uuid": str(pw.uuid)},
|
|
),
|
|
{"aliases": [alias_1, alias_2]},
|
|
)
|
|
|
|
pw = Pathway.objects.get(url=pathway_url)
|
|
self.assertEqual(len(pw.aliases), 2)
|
|
|
|
response = self.client.post(
|
|
reverse(
|
|
"package pathway detail",
|
|
kwargs={"package_uuid": str(pw.package.uuid), "pathway_uuid": str(pw.uuid)},
|
|
),
|
|
{"aliases": [alias_1]},
|
|
)
|
|
|
|
pw = Pathway.objects.get(url=pathway_url)
|
|
self.assertEqual(len(pw.aliases), 1)
|
|
|
|
response = self.client.post(
|
|
reverse(
|
|
"package pathway detail",
|
|
kwargs={"package_uuid": str(pw.package.uuid), "pathway_uuid": str(pw.uuid)},
|
|
),
|
|
{
|
|
# We have to set an empty string to avoid that the parameter is removed
|
|
"aliases": ""
|
|
},
|
|
)
|
|
|
|
pw = Pathway.objects.get(url=pathway_url)
|
|
self.assertEqual(len(pw.aliases), 0)
|
|
|
|
@override_settings(FLAGS={**s.FLAGS, "IUCLID_EXPORT": True})
|
|
def test_pathway_detail_shows_iuclid_export_action_when_enabled(self):
|
|
pathway = Pathway.create(self.package, "CCO", name="IUCLID Export Pathway")
|
|
|
|
response = self.client.get(
|
|
reverse(
|
|
"package pathway detail",
|
|
kwargs={
|
|
"package_uuid": str(pathway.package.uuid),
|
|
"pathway_uuid": str(pathway.uuid),
|
|
},
|
|
)
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertContains(response, f"/api/v1/pathway/{pathway.uuid}/export/iuclid")
|
|
|
|
@override_settings(FLAGS={**s.FLAGS, "IUCLID_EXPORT": False})
|
|
def test_pathway_detail_hides_iuclid_export_action_when_disabled(self):
|
|
pathway = Pathway.create(self.package, "CCO", name="IUCLID Export Pathway")
|
|
|
|
response = self.client.get(
|
|
reverse(
|
|
"package pathway detail",
|
|
kwargs={
|
|
"package_uuid": str(pathway.package.uuid),
|
|
"pathway_uuid": str(pathway.uuid),
|
|
},
|
|
)
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertNotContains(response, f"/api/v1/pathway/{pathway.uuid}/export/iuclid")
|