From 8d6879266fca469d3c6bed9e48f2d494710be01a Mon Sep 17 00:00:00 2001 From: GeneCodeSavvy Date: Fri, 2 May 2025 15:49:30 +0530 Subject: [PATCH 1/3] fix misspelled variable name --- sbol_utilities/sbol3_sbol2_conversion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbol_utilities/sbol3_sbol2_conversion.py b/sbol_utilities/sbol3_sbol2_conversion.py index d93b1094..4f908ab9 100644 --- a/sbol_utilities/sbol3_sbol2_conversion.py +++ b/sbol_utilities/sbol3_sbol2_conversion.py @@ -632,7 +632,7 @@ def visit_range(self, r2: sbol2.Range): cdef = r2.parent.parent ns = self._sbol3_namespace(cdef) seq_stub = sbol3.Sequence(f'{ns}/{cdef.displayId}Seq/', namespace=ns) - cdef.sequence = seq_stup + cdef.sequence = seq_stub cdef.doc.add(seq_stub) r3 = sbol3.Range(seq_ref, r2.start, r2.end) self._convert_identified(r2, r3) From 5c9abe01cb3b1e6a12682201eefcaa6ede58b532 Mon Sep 17 00:00:00 2001 From: GeneCodeSavvy Date: Thu, 24 Jul 2025 17:29:49 +0530 Subject: [PATCH 2/3] convert attachment objects sbol3 to sbol2 --- sbol_utilities/sbol3_sbol2_conversion.py | 36 ++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/sbol_utilities/sbol3_sbol2_conversion.py b/sbol_utilities/sbol3_sbol2_conversion.py index 4f908ab9..a455668b 100644 --- a/sbol_utilities/sbol3_sbol2_conversion.py +++ b/sbol_utilities/sbol3_sbol2_conversion.py @@ -5,7 +5,7 @@ # Namespaces -from rdflib import URIRef +from rdflib import URIRef, Literal BACKPORT_NAMESPACE = 'http://sboltools.org/backport#' BACKPORT2_VERSION = f'{BACKPORT_NAMESPACE}sbol2version' @@ -150,8 +150,38 @@ def visit_association(self, a: sbol3.Association): raise NotImplementedError('Conversion of Association from SBOL3 to SBOL2 not yet implemented') def visit_attachment(self, a: sbol3.Attachment): - # Priority: 2 - raise NotImplementedError('Conversion of Attachment from SBOL3 to SBOL2 not yet implemented') + # Make the Attachment object and add it to the document + att2 = sbol2.Attachment(self._sbol2_identity(a), source=a.source, version=self._sbol2_version(a)) + self.doc2.addAttachment(att2) + + # Handle hash and hash_algorithm properties + if a.hash: + # Check if hash_algorithm is specified + hash_algorithm = a.hash_algorithm + + # Check if it's SHA1 (SBOL2 only supports SHA1) + # Common SHA1 identifiers + sha1_identifiers = [ + 'SHA1', + 'sha1', + 'SHA-1', + 'sha-1' + ] + + if any(sha1_id in str(hash_algorithm) for sha1_id in sha1_identifiers): + # It's SHA1, so we can set it directly in SBOL2 + att2.hash = a.hash + else: + # It's not SHA1, add as backport extension properties + att2.properties[BACKPORT_NAMESPACE + 'hash'] = [Literal(a.hash)] + att2.properties[BACKPORT_NAMESPACE + 'hashAlgorithm'] = [Literal(hash_algorithm)] + + att2.format = a.format + att2.size = a.size + + # Map over all other TopLevel properties and extensions not covered by the constructor + self._convert_toplevel(a, att2) + def visit_binary_prefix(self, a: sbol3.BinaryPrefix): # Priority: 4 From 80e065a34b4099d41346184d7665a072463a53cc Mon Sep 17 00:00:00 2001 From: GeneCodeSavvy Date: Thu, 24 Jul 2025 17:31:44 +0530 Subject: [PATCH 3/3] convert attachment objects sbol2 to sbol3 --- sbol_utilities/sbol3_sbol2_conversion.py | 35 ++++++++++++------------ 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/sbol_utilities/sbol3_sbol2_conversion.py b/sbol_utilities/sbol3_sbol2_conversion.py index a455668b..d21172ff 100644 --- a/sbol_utilities/sbol3_sbol2_conversion.py +++ b/sbol_utilities/sbol3_sbol2_conversion.py @@ -150,25 +150,14 @@ def visit_association(self, a: sbol3.Association): raise NotImplementedError('Conversion of Association from SBOL3 to SBOL2 not yet implemented') def visit_attachment(self, a: sbol3.Attachment): - # Make the Attachment object and add it to the document att2 = sbol2.Attachment(self._sbol2_identity(a), source=a.source, version=self._sbol2_version(a)) self.doc2.addAttachment(att2) - # Handle hash and hash_algorithm properties if a.hash: - # Check if hash_algorithm is specified - hash_algorithm = a.hash_algorithm - # Check if it's SHA1 (SBOL2 only supports SHA1) - # Common SHA1 identifiers - sha1_identifiers = [ - 'SHA1', - 'sha1', - 'SHA-1', - 'sha-1' - ] + hash_algorithm = a.hash_algorithm - if any(sha1_id in str(hash_algorithm) for sha1_id in sha1_identifiers): + if hash_algorithm.replace("-", "").replace(" ", "").lower() == 'sha1': # It's SHA1, so we can set it directly in SBOL2 att2.hash = a.hash else: @@ -176,10 +165,9 @@ def visit_attachment(self, a: sbol3.Attachment): att2.properties[BACKPORT_NAMESPACE + 'hash'] = [Literal(a.hash)] att2.properties[BACKPORT_NAMESPACE + 'hashAlgorithm'] = [Literal(hash_algorithm)] - att2.format = a.format + att2.format = str(a.format) att2.size = a.size - # Map over all other TopLevel properties and extensions not covered by the constructor self._convert_toplevel(a, att2) @@ -486,8 +474,21 @@ def visit_association(self, a: sbol2.Association): raise NotImplementedError('Conversion of Association from SBOL2 to SBOL3 not yet implemented') def visit_attachment(self, a: sbol2.Attachment): - # Priority: 2 - raise NotImplementedError('Conversion of Attachment from SBOL2 to SBOL3 not yet implemented') + att3 = sbol3.Attachment(self._sbol3_identity(a), namespace=self._sbol3_namespace(a), source=a.source) + self.doc3.add(att3) + + # Check for backported hash properties first (higher priority) + if BACKPORT_NAMESPACE + 'hash' in a.properties: + att3.hash = a.properties[BACKPORT_NAMESPACE + 'hash'][0] + att3.hash_algorithm = a.properties[BACKPORT_NAMESPACE + 'hashAlgorithm'][0] + elif a.hash: + att3.hash = a.hash + att3.hash_algorithm = 'sha1' + + att3.format = str(a.format) + att3.size = a.size + + self._convert_toplevel(a, att3) def visit_collection(self, coll2: sbol2.Collection): # Make the Collection object and add it to the document