Skip to content

Commit

Permalink
Merge pull request #274 from SynBioDex/264-fix-compile
Browse files Browse the repository at this point in the history
Ensure that autoconstruction of Sequence URIs works correctly with di…
  • Loading branch information
tcmitchell authored Jun 3, 2020
2 parents 179057d + 4096e32 commit 5350e24
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
11 changes: 4 additions & 7 deletions sbol2/componentdefinition.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,10 @@ def compile(self, assembly_method=None):
'to a Document in order to compile.' % self.identity)

if self.sequence is None:
if Config.getOption('sbol_compliant_uris'):
display_id = self.displayId
if not Config.getOption('sbol_typed_uris'):
display_id += '_seq'
self.sequence = Sequence(display_id)
else:
self.sequence = Sequence(display_id + '_seq')
sequence_id = self.displayId + '_seq'
if Config.getOption('sbol_compliant_uris') and Config.getOption('sbol_typed_uris'):
sequence_id = self.displayId
self.sequence = Sequence(sequence_id)

return self.sequence.compile(assembly_method=assembly_method)

Expand Down
26 changes: 26 additions & 0 deletions test/test_componentdefinition.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,32 @@ def test_compile_sequence(self):
self.assertEqual(target_seq, 'aaatttaaatttaaatttaaa')
self.assertEqual(target_seq, gene.sequence.elements)

def test_compile_autoconstruct_sequence(self):
# Ensure that autoconstruction of Sequence URIs works correctly with
# different configuration options
root_id = 'root'
sub_id = 'sub'
sbol2.Config.setOption('sbol_compliant_uris', True)
sbol2.Config.setOption('sbol_typed_uris', True)
doc = sbol2.Document()
root = doc.componentDefinitions.create(root_id)
sub = doc.componentDefinitions.create(sub_id)
root.compile([sub])
expected_identity = sbol2.getHomespace() + '/Sequence/' + root_id + '/1'
self.assertEqual(root.sequence.identity, expected_identity)

sbol2.Config.setOption('sbol_compliant_uris', True)
sbol2.Config.setOption('sbol_typed_uris', False)
doc = sbol2.Document()
root = doc.componentDefinitions.create(root_id)
sub = doc.componentDefinitions.create(sub_id)
root.compile([sub])
expected_identity = sbol2.getHomespace() + '/' + root_id + '_seq/1'
self.assertEqual(root.sequence.identity, expected_identity)

sbol2.Config.setOption('sbol_compliant_uris', True)
sbol2.Config.setOption('sbol_typed_uris', True)

def test_recursive_compile(self):
doc = sbol2.Document()
cd1 = sbol2.ComponentDefinition('cd1')
Expand Down

0 comments on commit 5350e24

Please sign in to comment.