-
Notifications
You must be signed in to change notification settings - Fork 29
Model conversion and test are done #314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,3 +1,4 @@ | ||||
import sbol2.model | ||||
import sbol3 | ||||
import sbol2 | ||||
from sbol2 import mapsto, model, sequenceconstraint | ||||
|
@@ -235,9 +236,16 @@ def visit_measure(self, a: sbol3.Measure): | |||
# Priority: 3 | ||||
raise NotImplementedError('Conversion of Measure from SBOL3 to SBOL2 not yet implemented') | ||||
|
||||
def visit_model(self, a: sbol3.Model): | ||||
# Priority: 3 | ||||
raise NotImplementedError('Conversion of Model from SBOL3 to SBOL2 not yet implemented') | ||||
def visit_model(self, model3: sbol3.Model): | ||||
# Priority: 3 | ||||
model2 = sbol2.model.Model(uri=model3.identity, source=model3.source, | ||||
language=model3.language, framework=model3.framework) | ||||
self.doc2.add(model2) | ||||
# Map over all other TopLevel properties and extensions not covered by the constructor | ||||
self._convert_toplevel(model3, model2) | ||||
# seq2 = sbol2.Sequence(seq3.identity, seq3.elements, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this commented out code. |
||||
# encoding=encoding2, | ||||
# version=self._sbol2_version(seq3)) | ||||
|
||||
def visit_participation(self, a: sbol3.Participation): | ||||
# Priority: 2 | ||||
|
@@ -266,7 +274,9 @@ def visit_sequence(self, seq3: sbol3.Sequence): | |||
sbol3.SMILES_ENCODING: sbol2.SBOL_ENCODING_SMILES} | ||||
encoding2 = encoding_map.get(seq3.encoding, seq3.encoding) | ||||
# Make the Sequence object and add it to the document | ||||
seq2 = sbol2.Sequence(seq3.identity, seq3.elements, encoding=encoding2, version=self._sbol2_version(seq3)) | ||||
seq2 = sbol2.Sequence(seq3.identity, seq3.elements, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't change the line-wrapping standard on the project. Per the setup.py file at the top, this project uses |
||||
encoding=encoding2, | ||||
version=self._sbol2_version(seq3)) | ||||
self.doc2.addSequence(seq2) | ||||
# Map over all other TopLevel properties and extensions not covered by the constructor | ||||
self._convert_toplevel(seq3, seq2) | ||||
|
@@ -546,9 +556,19 @@ def visit_measure(self, a: sbol2.measurement.Measurement): | |||
# Priority: 3 | ||||
raise NotImplementedError('Conversion of Measure from SBOL2 to SBOL3 not yet implemented') | ||||
|
||||
def visit_model(self, a: sbol2.model.Model): | ||||
def visit_model(self, model2: sbol2.model.Model): | ||||
# Priority: 3 | ||||
raise NotImplementedError('Conversion of Model from SBOL2 to SBOL3 not yet implemented') | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whitespace violates python conventions.
Suggested change
|
||||
model3 = sbol3.Model(model2.identity, source=model2.source, language=model2.language, | ||||
framework=model2.framework) | ||||
self.doc3.add(model3) | ||||
|
||||
# Map over all other TopLevel properties and extensions not covered by the constructor | ||||
self._convert_toplevel(model2, model3) | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Too much whitespace here; please use pycodestyle to follow standard python conventions.. |
||||
|
||||
|
||||
|
||||
|
||||
def visit_module(self, a: sbol2.Module): | ||||
# Priority: 3 | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file isn't currently used. Please either incorporate into a test or delete. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" ?> | ||
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sbol="http://sbols.org/v2#" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:prov="http://www.w3.org/ns/prov#" xmlns:om="http://www.ontology-of-units-of-measure.org/resource/om-2/"> | ||
<sbol:Model rdf:about="http://www.sbolstandard.org/examples/pIKE_Toggle_1"> | ||
<sbol:persistentIdentity rdf:resource="http://www.sbolstandard.org/examples/pIKE_Toggle_1"/> | ||
<sbol:displayId>pIKE_Toggle_1</sbol:displayId> | ||
<dcterms:title>pIKE_Toggle_1 toggle switch</dcterms:title> | ||
<sbol:source rdf:resource="http://virtualparts.org/part/pIKE_Toggle_1"/> | ||
<sbol:language rdf:resource="http://identifiers.org/edam/format_2585"/> | ||
<sbol:framework rdf:resource="http://identifiers.org/biomodels.sbo/SBO:0000062"/> | ||
</sbol:Model> | ||
</rdf:RDF> |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file isn't currently used. Please either incorporate into a test or delete. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<rdf:RDF xmlns:brick="https://brickschema.org/schema/Brick#" xmlns:csvw="http://www.w3.org/ns/csvw#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcat="http://www.w3.org/ns/dcat#" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcam="http://purl.org/dc/dcam/" xmlns:doap="http://usefulinc.com/ns/doap#" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:geo="http://www.opengis.net/ont/geosparql#" xmlns:odrl="http://www.w3.org/ns/odrl/2/" xmlns:org="http://www.w3.org/ns/org#" xmlns:prof="http://www.w3.org/ns/dx/prof/" xmlns:prov="http://www.w3.org/ns/prov#" xmlns:qb="http://purl.org/linked-data/cube#" xmlns:schema="https://schema.org/" xmlns:sh="http://www.w3.org/ns/shacl#" xmlns:skos="http://www.w3.org/2004/02/skos/core#" xmlns:sosa="http://www.w3.org/ns/sosa/" xmlns:ssn="http://www.w3.org/ns/ssn/" xmlns:time="http://www.w3.org/2006/time#" xmlns:vann="http://purl.org/vocab/vann/" xmlns:void="http://rdfs.org/ns/void#" xmlns:wgs="https://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" xmlns:backport="http://sboltools.org/backport#" xmlns:om="http://www.ontology-of-units-of-measure.org/resource/om-2/" xmlns:sbol="http://sbols.org/v2#" xmlns:ns0="http://www.sbolstandard.org/examples/"> | ||
<ns0:pIKE_Toggle_1 rdf:about="example"> | ||
<sbol:language rdf:resource="http://identifiers.org/edam/format_2585"/> | ||
<dcterms:title>pIKE_Toggle_1 toggle switch</dcterms:title> | ||
<sbol:source rdf:resource="http://virtualparts.org/part/pIKE_Toggle_1"/> | ||
<backport:sbol3namespace rdf:resource="http://www.sbolstandard.org/examples"/> | ||
<sbol:displayId>pIKE_Toggle_1</sbol:displayId> | ||
<sbol:persistentIdentity rdf:resource="example"/> | ||
<sbol:version>1</sbol:version> | ||
<sbol:framework rdf:resource="http://identifiers.org/biomodels.sbo/SBO:0000062"/> | ||
</ns0:pIKE_Toggle_1> | ||
</rdf:RDF> |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file isn't currently used. Please either incorporate into a test or delete. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<rdf:RDF xmlns:brick="https://brickschema.org/schema/Brick#" xmlns:csvw="http://www.w3.org/ns/csvw#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcat="http://www.w3.org/ns/dcat#" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcam="http://purl.org/dc/dcam/" xmlns:doap="http://usefulinc.com/ns/doap#" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:geo="http://www.opengis.net/ont/geosparql#" xmlns:odrl="http://www.w3.org/ns/odrl/2/" xmlns:org="http://www.w3.org/ns/org#" xmlns:prof="http://www.w3.org/ns/dx/prof/" xmlns:prov="http://www.w3.org/ns/prov#" xmlns:qb="http://purl.org/linked-data/cube#" xmlns:schema="https://schema.org/" xmlns:sh="http://www.w3.org/ns/shacl#" xmlns:skos="http://www.w3.org/2004/02/skos/core#" xmlns:sosa="http://www.w3.org/ns/sosa/" xmlns:ssn="http://www.w3.org/ns/ssn/" xmlns:time="http://www.w3.org/2006/time#" xmlns:vann="http://purl.org/vocab/vann/" xmlns:void="http://rdfs.org/ns/void#" xmlns:wgs="https://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" xmlns:backport="http://sboltools.org/backport#" xmlns:om="http://www.ontology-of-units-of-measure.org/resource/om-2/" xmlns:sbol="http://sbols.org/v2#"> | ||
<sbol:Model rdf:about="http://www.sbolstandard.org/examples/pIKE_Toggle_1"> | ||
<sbol:displayId>pIKE_Toggle_1</sbol:displayId> | ||
<sbol:version>1</sbol:version> | ||
<sbol:language rdf:resource="http://identifiers.org/edam/format_2585"/> | ||
<sbol:persistentIdentity rdf:resource="http://www.sbolstandard.org/examples/pIKE_Toggle_1"/> | ||
<backport:sbol3namespace rdf:resource="http://www.sbolstandard.org/examples"/> | ||
<sbol:source rdf:resource="http://virtualparts.org/part/pIKE_Toggle_1"/> | ||
<dcterms:title>pIKE_Toggle_1 toggle switch</dcterms:title> | ||
<sbol:framework rdf:resource="http://identifiers.org/biomodels.sbo/SBO:0000062"/> | ||
</sbol:Model> | ||
</rdf:RDF> |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file isn't currently used. Please either incorporate into a test or delete. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@prefix sbol: <http://sbols.org/v3#> . | ||
@prefix ex: <http://example.org/> . | ||
@prefix edam: <http://identifiers.org/edam/> . | ||
@prefix sbo: <http://identifiers.org/biomodels.sbo/> . | ||
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . | ||
|
||
ex:mymodel a sbol:Model ; | ||
sbol:source <https://models.example.org/my_model.sbml> ; | ||
sbol:language edam:format_2585 ; | ||
sbol:framework sbo:SBO:0000064 . |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please change this to sorted N-triples format, in order to allow direct file-to-file comparison around the loop. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@prefix sbol: <http://sbols.org/v3#> . | ||
|
||
<http://www.sbolstandard.org/examples/pIKE_Toggle_1> a sbol:Model ; | ||
sbol:displayId "pIKE_Toggle_1" ; | ||
sbol:framework <http://identifiers.org/biomodels.sbo/SBO:0000062> ; | ||
sbol:hasNamespace <http://www.sbolstandard.org/examples> ; | ||
sbol:language <http://identifiers.org/edam/format_2585> ; | ||
sbol:name "pIKE_Toggle_1 toggle switch" ; | ||
sbol:source <http://virtualparts.org/part/pIKE_Toggle_1> . | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,6 +1,9 @@ | ||||
from sbol2 import Config, ConfigOptions | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sbol2 is already imported below; please use references as |
||||
|
||||
import tempfile | ||||
from pathlib import Path | ||||
|
||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Whitespace goes against python style. |
||||
import unittest | ||||
|
||||
import sbol2 | ||||
|
@@ -17,7 +20,7 @@ class TestDirectSBOL2SBOL3Conversion(unittest.TestCase): | |||
# TODO: turn on validation | ||||
|
||||
# J23101.xml is not SBOL compliant. Leaving conversions involving it for after the compliant converter is done | ||||
''' | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't add extra whitespace against python style; use pycodestyle to check your code. |
||||
def test_3to2_conversion(self): | ||||
"""Test ability to convert a simple part from SBOL3 to SBOL2""" | ||||
# Load an SBOL3 document and check its contents | ||||
|
@@ -36,10 +39,10 @@ def test_3to2_conversion(self): | |||
tmp3 = Path(tmpdir) / 'doc3_loop.nt' | ||||
doc3_loop.write(tmp3) | ||||
self.assertFalse(file_diff(str(tmp3), str(TEST_FILES / 'BBa_J23101_patched.nt'))) | ||||
''' | ||||
|
||||
|
||||
# J23101.xml is not SBOL compliant. Leaving conversions involving it for after the compliant converter is done | ||||
''' | ||||
|
||||
def test_2to3_conversion(self): | ||||
"""Test ability to convert a simple part from SBOL2 to SBOL3""" | ||||
# Load an SBOL2 document and check its contents | ||||
|
@@ -58,10 +61,10 @@ def test_2to3_conversion(self): | |||
tmp2 = Path(tmpdir) / 'doc2_loop.xml' | ||||
doc2_loop.write(tmp2) | ||||
self.assertFalse(file_diff(str(tmp2), str(TEST_FILES / 'BBa_J23101.xml'))) | ||||
''' | ||||
|
||||
|
||||
# sbol_3to2_implementation.xml is not SBOL compliant. Leaving conversions involving it for after the compliant converter is done | ||||
''' | ||||
|
||||
def test_3to2_implementation_conversion(self): | ||||
"""Test ability to convert an implementation from SBOL3 to SBOL2""" | ||||
# Load an SBOL3 document and check its contents | ||||
|
@@ -80,10 +83,10 @@ def test_3to2_implementation_conversion(self): | |||
tmp3 = Path(tmpdir) / 'doc3_loop.nt' | ||||
doc3_loop.write(tmp3) | ||||
self.assertFalse(file_diff(str(tmp3), str(TEST_FILES / 'sbol3_implementation.nt'))) | ||||
''' | ||||
|
||||
|
||||
# sbol_3to2_implementation.xml is not SBOL compliant. Leaving conversions involving it for after the compliant converter is done | ||||
''' | ||||
|
||||
def test_2to3_implementation_conversion(self): | ||||
"""Test ability to convert an implementation from SBOL2 to SBOL3""" | ||||
# Load an SBOL2 document and check its contents | ||||
|
@@ -102,10 +105,10 @@ def test_2to3_implementation_conversion(self): | |||
tmp2 = Path(tmpdir) / 'doc2_loop.xml' | ||||
doc2_loop.write(tmp2) | ||||
self.assertFalse(file_diff(str(tmp2), str(TEST_FILES / 'sbol_3to2_implementation.xml'))) | ||||
''' | ||||
|
||||
|
||||
# sbol_3to2_collection.xml is not SBOL compliant. Leaving conversions involving it for after the compliant converter is done | ||||
''' | ||||
|
||||
# sbol_3to2_collection.xml is not SBOL compliant. Leaving conversions involving it for after the compliant converter is done | ||||
def test_3to2_collection_conversion(self): | ||||
"""Test ability to convert a collection from SBOL3 to SBOL2""" | ||||
|
@@ -125,10 +128,10 @@ def test_3to2_collection_conversion(self): | |||
tmp3 = Path(tmpdir) / 'doc3_loop.nt' | ||||
doc3_loop.write(tmp3) | ||||
self.assertFalse(file_diff(str(tmp3), str(TEST_FILES / 'sbol3_collection.nt'))) | ||||
''' | ||||
|
||||
|
||||
# sbol_3to2_collection.xml is not SBOL compliant. Leaving conversions involving it for after the compliant converter is done | ||||
''' | ||||
|
||||
def test_2to3_collection_conversion(self): | ||||
"""Test ability to convert a collection from SBOL2 to SBOL3""" | ||||
# Load an SBOL2 document and check its contents | ||||
|
@@ -147,7 +150,25 @@ def test_2to3_collection_conversion(self): | |||
tmp2 = Path(tmpdir) / 'doc2_loop.xml' | ||||
doc2_loop.write(tmp2) | ||||
self.assertFalse(file_diff(str(tmp2), str(TEST_FILES / 'sbol_3to2_collection.xml'))) | ||||
''' | ||||
|
||||
def test_2to3_and_3to2_model_conversion(self): | ||||
"""Test ability to convert a model from SBOL2 to SBOL3""" | ||||
# Load an SBOL2 document and check its contents | ||||
Config.setOption(ConfigOptions.SBOL_COMPLIANT_URIS, False) | ||||
Config.setOption(ConfigOptions.SBOL_TYPED_URIS, False) | ||||
doc2 = sbol2.Document() | ||||
doc2.read(TEST_FILES / 'example_model_sbol2.xml') | ||||
model2 = doc2.models[0] | ||||
doc3 = convert2to3(doc2, use_native_converter=True) | ||||
self.assertEqual(len(doc3.validate()), 0) | ||||
doc3.write(TEST_FILES / 'generated_model_sbol3.ttl',file_format='turtle') | ||||
doc2_loop = convert3to2(doc3, True) | ||||
model2_loop = doc2_loop.models[0] | ||||
self.assertEqual(model2.language, model2_loop.language) | ||||
self.assertEqual(model2.framework, model2_loop.framework) | ||||
self.assertEqual(model2.source, model2_loop.source) | ||||
self.assertEqual(model2.name, model2_loop.name) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These comparisons are necessary, but not sufficient.
|
||||
|
||||
|
||||
if __name__ == '__main__': | ||||
unittest.main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import should not be needed, given the
from sbol2
line below.In fact, we should probably remove that one too since it makes the references in the code more ambiguous.