From f92141260da3cc2ed6dd4dd1a209061fac2035f7 Mon Sep 17 00:00:00 2001 From: Jake Beal Date: Sat, 7 Oct 2023 16:35:46 -0400 Subject: [PATCH] Clean up minor details to allow triple-to-triple identify in first tests of SBOL2/SBOL3 Python conversion Note that pySBOL2 validation fails, apparently due to an issue with SHACL rules for the DateTime type (https://github.com/SynBioDex/pySBOL2/issues/429) --- sbol_utilities/sbol3_sbol2_conversion.py | 10 ++++++---- test/test_files/BBa_J23101_patched.nt | 4 +--- test/test_sbol2_sbol3_direct.py | 20 +++++++++++--------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/sbol_utilities/sbol3_sbol2_conversion.py b/sbol_utilities/sbol3_sbol2_conversion.py index ca3f6bee..29ee4c33 100644 --- a/sbol_utilities/sbol3_sbol2_conversion.py +++ b/sbol_utilities/sbol3_sbol2_conversion.py @@ -12,6 +12,8 @@ NON_EXTENSION_PROPERTY_PREFIXES = {sbol3.SBOL3_NS, sbol3.SBOL2_NS, # SBOL 2 & 3 namespaces sbol3.RDF_NS, sbol3.PROV_NS, sbol3.OM_NS, # Standard ontologies BACKPORT_NAMESPACE} # Information added by this converter +SBOL2_NON_EXTENSION_PROPERTY_PREFIXES = NON_EXTENSION_PROPERTY_PREFIXES.union({ + 'http://purl.org/dc/terms/description', 'http://purl.org/dc/terms/title'}) class SBOL3To2ConversionVisitor: @@ -57,9 +59,9 @@ def _convert_extension_properties(obj3: sbol3.Identified, obj2: sbol2.Identified obj2.properties[p] = obj3._properties[p].copy() # Can't use setPropertyValue because it may not be a string @staticmethod - def _value_or_property(obj3: sbol3.Identified, value, property: str): - if property in obj3._properties and len(obj3._properties[property]) == 1: - return value or obj3._properties[property][0] + def _value_or_property(obj3: sbol3.Identified, value, prop: str): + if prop in obj3._properties and len(obj3._properties[prop]) == 1: + return value or obj3._properties[prop][0] return value def _convert_identified(self, obj3: sbol3.Identified, obj2: sbol2.Identified): @@ -306,7 +308,7 @@ def _convert(self, doc2: sbol2.Document): def _convert_extension_properties(obj2: sbol2.Identified, obj3: sbol3.Identified): """Copy over extension properties""" extension_properties = (p for p in obj2.properties - if not any(p.startswith(prefix) for prefix in NON_EXTENSION_PROPERTY_PREFIXES)) + if not any(p.startswith(prefix) for prefix in SBOL2_NON_EXTENSION_PROPERTY_PREFIXES)) for p in extension_properties: obj3._properties[p] = obj2.properties[p] diff --git a/test/test_files/BBa_J23101_patched.nt b/test/test_files/BBa_J23101_patched.nt index e17240c4..08763480 100644 --- a/test/test_files/BBa_J23101_patched.nt +++ b/test/test_files/BBa_J23101_patched.nt @@ -9,7 +9,6 @@ . . . - . "1" . "false" . "true" . @@ -47,7 +46,6 @@ "James Alastair McLaughlin" . "Conversion of the iGEM parts registry to SBOL2.1" . "iGEM to SBOL conversion" . - . "igem2sbol" . . "1" . @@ -56,4 +54,4 @@ . . . - "2017-03-06T15:00:00+00:00" . + "2017-03-06T15:00:00+00:00"^^ . diff --git a/test/test_sbol2_sbol3_direct.py b/test/test_sbol2_sbol3_direct.py index 294a2563..51caaa03 100644 --- a/test/test_sbol2_sbol3_direct.py +++ b/test/test_sbol2_sbol3_direct.py @@ -22,15 +22,16 @@ def test_3to2_conversion(self): doc3.read(TEST_FILES / 'BBa_J23101_patched.nt') # Convert to SBOL2 and check contents doc2 = convert3to2(doc3, True) - #self.assertEqual(len(doc2.validate()), 0) + #report = doc2.validate() + #self.assertEqual(len(report), 0, f'Validation failed: {report}') with tempfile.NamedTemporaryFile(suffix='.xml') as tmp2: doc2.write(tmp2.name) self.assertFalse(file_diff(tmp2.name, str(TEST_FILES / 'BBa_J23101.xml'))) - doc3_loop = convert2to3(doc2) - #self.assertEqual(len(doc3_loop.validate()), 0) + doc3_loop = convert2to3(doc2, use_native_converter=True) + self.assertEqual(len(doc3_loop.validate()), 0) with tempfile.NamedTemporaryFile(suffix='.nt') as tmp3: doc3_loop.write(tmp3.name) - #self.assertFalse(file_diff(tmp3.name, str(TEST_FILES / 'BBa_J23101_patched.nt'))) + self.assertFalse(file_diff(tmp3.name, str(TEST_FILES / 'BBa_J23101_patched.nt'))) def test_2to3_conversion(self): """Test ability to convert a simple part from SBOL3 to SBOL2""" @@ -39,15 +40,16 @@ def test_2to3_conversion(self): doc2.read(TEST_FILES / 'BBa_J23101.xml') # Convert to SBOL3 and check contents doc3 = convert2to3(doc2, use_native_converter=True) - #self.assertEqual(len(doc3.validate()), 0) + self.assertEqual(len(doc3.validate()), 0) with tempfile.NamedTemporaryFile(suffix='.nt') as tmp3: doc3.write(tmp3.name) - #self.assertFalse(file_diff(tmp3.name, str(TEST_FILES / 'BBa_J23101_patched.nt'))) - doc2_loop = convert3to2(doc3) - # self.assertEqual(len(doc2_loop.validate()), 0) + self.assertFalse(file_diff(tmp3.name, str(TEST_FILES / 'BBa_J23101_patched.nt'))) + doc2_loop = convert3to2(doc3, True) + # report = doc2.validate() + # self.assertEqual(len(report), 0, f'Validation failed: {report}') with tempfile.NamedTemporaryFile(suffix='.xml') as tmp2: doc2_loop.write(tmp2.name) - #self.assertFalse(file_diff(tmp2.name, str(TEST_FILES / 'BBa_J23101.xml'))) + self.assertFalse(file_diff(tmp2.name, str(TEST_FILES / 'BBa_J23101.xml'))) if __name__ == '__main__':