Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
manulera committed Apr 11, 2024
1 parent 8a30f7b commit 939ae02
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 6 deletions.
51 changes: 51 additions & 0 deletions sbol_utilities/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import sbol3
import sbol2
from sbol_utilities.conversion import convert2to3, convert3to2
import tyto
from sbol3_sbol2_conversion import SBOL2To3ConversionVisitor, SBOL3To2ConversionVisitor
from pprint import pprint

sbol3.set_namespace('http://examples.org')

dummy_doc2 = sbol2.Document()
dummy_doc3 = sbol3.Document()

component3 = sbol3.Component('component', sbol3.SBO_DNA)
subcomponent3 = sbol3.SubComponent(component3)
component3.features.append(subcomponent3)

component2 = sbol2.ComponentDefinition('component', sbol3.SBO_DNA)
subcomponent2 = sbol2.Component(definition=component2.identity)
component2.components.add(subcomponent2)

participation3 = sbol3.Participation(sbol3.SBO_REACTANT, subcomponent3)
participation2 = sbol2.Participation(participant=subcomponent2)
participation2.addRole(sbol2.SBO_REACTANT)

converter3to2 = SBOL3To2ConversionVisitor(dummy_doc3)
participation2_converted = converter3to2.visit_participation(participation3)
converter2to3 = SBOL2To3ConversionVisitor(dummy_doc2, None)
participation3_converted = converter2to3.visit_participation(participation2)

print(participation3.participant)
print(participation3_converted.participant)
print(getattr(participation3_converted, 'participant'))


def compare_participations(p1, p2):
for k in vars(p1):
if k in ['properties', '_properties']:
continue
if str(getattr(p1, k)) != str(getattr(p2, k)):
print('prop:', k)
print('original:', getattr(p1, k))
print('converted:', getattr(p2, k))
print()


print('## Participation 2')
compare_participations(participation2, participation2_converted)

print('## Participation 3')
compare_participations(participation3, participation3_converted)

23 changes: 17 additions & 6 deletions sbol_utilities/sbol3_sbol2_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,15 @@ def visit_model(self, a: sbol3.Model):
# Priority: 3
raise NotImplementedError('Conversion of Model from SBOL3 to SBOL2 not yet implemented')

def visit_participation(self, a: sbol3.Participation):
# Priority: 2
raise NotImplementedError('Conversion of Participation from SBOL3 to SBOL2 not yet implemented')
def visit_participation(self, participation3: sbol3.Participation) -> sbol2.Participation:
participation2 = sbol2.Participation(
version=self._sbol2_version(participation3),
participant=participation3.participant
)
for role in participation3.roles:
participation2.addRole(role)
self._convert_identified(participation3, participation2)
return participation2

def visit_plan(self, a: sbol3.Plan):
# Priority: 3
Expand Down Expand Up @@ -508,9 +514,14 @@ def visit_module_definition(self, a: sbol2.ModuleDefinition):
# Priority: 3
raise NotImplementedError('Conversion of ModuleDefinition from SBOL2 to SBOL3 not yet implemented')

def visit_participation(self, a: sbol2.Participation):
# Priority: 2
raise NotImplementedError('Conversion of Participation from SBOL2 to SBOL3 not yet implemented')
def visit_participation(self, participation2: sbol2.Participation) -> sbol3.Participation:
participation3 = sbol3.Participation(
roles=participation2.roles,
participant=participation2.participant
)
self._convert_identified(participation2, participation3)
return participation3


def visit_plan(self, a: sbol2.Plan):
# Priority: 3
Expand Down

0 comments on commit 939ae02

Please sign in to comment.