Skip to content

Commit de4387a

Browse files
committed
Select top-level design for lvl2 TU extraction
1 parent f10a5b4 commit de4387a

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

src/buildcompiler/buildcompiler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from .abstract_translator import (
2020
enumerate_design_variants,
2121
extract_combinatorial_design_parts,
22+
extract_toplevel_definition,
2223
get_or_pull,
2324
get_compatible_plasmids,
2425
)
@@ -1612,7 +1613,7 @@ def _extract_lvl2_TUs( # TODO send to misc helper file instead of buildcompiler
16121613
Returns:
16131614
A list of TU component definitions in sequential order.
16141615
"""
1615-
top_design = design_doc.componentDefinitions[0]
1616+
top_design = extract_toplevel_definition(design_doc)
16161617

16171618
return [
16181619
design_doc.get(comp.definition) for comp in top_design.getInSequentialOrder()

tests/unit/stages/test_assembly_lvl2.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,30 @@ def fail_get_backbone(*args, **kwargs):
268268

269269
assert products
270270
assert captured["backbone"] is supplied_lvl2_backbone
271+
272+
273+
def test_extract_lvl2_tus_uses_top_level_composite_not_document_order():
274+
from buildcompiler.buildcompiler import _extract_lvl2_TUs
275+
276+
doc = sbol2.Document()
277+
tu1 = sbol2.ComponentDefinition("tu1", sbol2.BIOPAX_DNA)
278+
tu2 = sbol2.ComponentDefinition("tu2", sbol2.BIOPAX_DNA)
279+
composite = sbol2.ComponentDefinition("lvl2_design", sbol2.BIOPAX_DNA)
280+
281+
# Add child TUs before the composite to ensure extraction does not depend on
282+
# ComponentDefinition serialization/document order.
283+
doc.addComponentDefinition(tu1)
284+
doc.addComponentDefinition(tu2)
285+
doc.addComponentDefinition(composite)
286+
287+
tu1_component = composite.components.create("tu1_component")
288+
tu1_component.definition = tu1.identity
289+
tu2_component = composite.components.create("tu2_component")
290+
tu2_component.definition = tu2.identity
291+
292+
tu_order = composite.sequenceConstraints.create("tu1_before_tu2")
293+
tu_order.subject = tu1_component.identity
294+
tu_order.object = tu2_component.identity
295+
tu_order.restriction = sbol2.SBOL_RESTRICTION_PRECEDES
296+
297+
assert _extract_lvl2_TUs(doc) == [tu1, tu2]

0 commit comments

Comments
 (0)