def test_circular_golden_gate(): record = dw.load_record(plasmid_path) sequence = dw.SequenceString.from_record(record) assert sequence.metadata['topology'] == "circular" assert dw.get_sequence_topology(sequence) == "circular" commercial_provider = dw.CommercialDnaOffer( name="supplier", pricing=dw.PerBasepairPricing(0.1), ) assembly_station = dw.DnaAssemblyStation( name="golden_gate", supplier=commercial_provider, assembly_method=dw.GoldenGateAssemblyMethod( enzyme="BsmBI", max_segment_length=3000 ), coarse_grain=600, fine_grain=None, cut_spread_radius=2, ) quote = assembly_station.get_quote(sequence) assert quote.accepted assert 1200 < quote.price < 1220 # ROUND TRIP: SIMULATE CLONING TO CHECK ASSEMBLY PLAN VALIDITY part_names, repo = extract_records_from_quote(quote) quote = assembly_station.get_quote(sequence) assembly = dc.Type2sRestrictionAssembly(parts=part_names) simulation = assembly.simulate(repo) assert len(simulation.construct_records) == 1 simulated_record = simulation.construct_records[0] assert sequences_are_circularly_equal([record, simulated_record])
def test_autoselect_connectors(): repo = dc.SequenceRepository() repo.import_records( collection="parts", folder=os.path.join(this_directory, "parts"), use_file_names_as_ids=True, topology="circular" ) repo.import_records( collection="emma_connectors", folder=os.path.join(this_directory, "emma_connectors"), use_file_names_as_ids=True, ) all_parts = list(repo.collections["parts"].keys()) assembly = dc.Type2sRestrictionAssembly( parts=all_parts, connectors_collection="emma_connectors" ) simulation = assembly.simulate(sequence_repository=repo) assert len(simulation.construct_records) == 1 assert len(simulation.warnings) == 1 warning = simulation.warnings[0] # selected_connectors = mix.autoselect_connectors(connectors) assert sorted(warning.data["selected_connectors"]) == [ "conn_A_B", "conn_D-F", "conn_J-K", "conn_L-N", "conn_R-W", "conn_W-Z", ]
def test_combinatorial_type2s(): repository = dc.SequenceRepository() repository.import_records(folder=parts_folder, use_file_names_as_ids=True) parts_list = list(repository.collections["parts"]) # EXPECT A SINGLE CONSTRUCT, GET AN ERROR assembly = dc.Type2sRestrictionAssembly(parts_list, expected_constructs=1) simulation = assembly.simulate(sequence_repository=repository) assert len(simulation.errors) == 1 assert len(simulation.construct_records) == 5 # DON'T EXPECT A CERTAIN NUMBER, GET NO ERROR assembly = dc.Type2sRestrictionAssembly(parts_list, expected_constructs="any_number") simulation = assembly.simulate(sequence_repository=repository) assert len(simulation.errors) == 0 assert len(simulation.construct_records) == 5 # LIMIT THE NUMBER OF CONSTRUCTS, GET LESS CONSTRUCTS, AND A WARNING assembly = dc.Type2sRestrictionAssembly( parts_list, max_constructs=3, expected_constructs="any_number", expect_no_unused_parts=False, ) simulation = assembly.simulate(sequence_repository=repository) assert len(simulation.errors) == 0 assert len(simulation.warnings) == 1 # Max constructs reached warning assert len(simulation.construct_records) == 3 # TEST RANDOMIZED ASSEMBLY PICKING assembly = dc.Type2sRestrictionAssembly( parts_list, max_constructs=2, expected_constructs="any_number", expect_no_unused_parts=False, randomize_constructs=True, ) simulation = assembly.simulate(sequence_repository=repository) assert len(simulation.errors) == 0 assert len(simulation.warnings) == 1 # Max constructs reached warning assert len(simulation.construct_records) == 2
import dnacauldron as dc import os repository = dc.SequenceRepository() repository.import_records(folder="parts", use_file_names_as_ids=True) parts_list = list(repository.collections["parts"]) assembly = dc.Type2sRestrictionAssembly( name="randomized_combinatorial_asm", parts=parts_list, expected_constructs="any_number", randomize_constructs=True, max_constructs=2, ) simulation = assembly.simulate(sequence_repository=repository, ) output_path = os.path.join("output", "randomized_combinatorial") simulation.write_report(target=output_path) print("Done! see output/randomized_combinatorial folder for the results.")
def work(self): self.logger(message="Reading the Data...") data = self.data # CHANGE THE VALUE OF THE BOOLEANS def yes_no(value): return {"yes": True, "no": False}.get(value, value) include_fragment_plots = yes_no(data.include_fragment_plots) include_graph_plots = yes_no(data.include_graph_plots) include_assembly_plots = yes_no(data.include_assembly_plots) report_writer = dc.AssemblyReportWriter( include_mix_graphs=include_graph_plots, include_assembly_plots=include_assembly_plots, include_fragment_plots=include_fragment_plots, ) # INITIALIZE ALL RECORDS IN A SEQUENCE REPOSITORY records = records_from_data_files( data.parts, use_file_names_as_ids=data.use_file_names_as_ids) repository = dc.SequenceRepository() for record in records: # location-less features can cause bug when concatenating records. record.features = [ f for f in record.features if f.location is not None and f.location.start <= f.location.end ] for r in records: if data.backbone_first and r.id == data.backbone_name: r.is_backbone = True repository.add_records(records, collection="parts") # CREATE A CONNECTORS COLLECTION IF CONNECTORS ARE PROVIDED connectors_collection = None if len(data.connectors): connector_records = records_from_data_files(data.connectors) for r in records + connector_records: set_record_topology(r, topology=data.topology) r.seq = r.seq.upper() repository.add_records(connector_records, collection="connectors") connectors_collection = "connectors" # SIMULATE! self.logger(message="Simulating the assembly...") if not data.use_assembly_plan: # SCENARIO: SINGLE ASSEMBLY parts = [r.id for r in records] assembly = dc.Type2sRestrictionAssembly( name="simulated_assembly", parts=parts, enzyme=data.enzyme, expected_constructs="any_number", connectors_collection=connectors_collection, ) simulation = assembly.simulate(sequence_repository=repository) n = len(simulation.construct_records) self.logger( message="Done (%d constructs found), writing report..." % n) report_zip_data = simulation.write_report( target="@memory", report_writer=report_writer) return { "file": { "data": data_to_html_data(report_zip_data, "zip"), "name": "assembly_simulation.zip", "mimetype": "application/zip", }, "errors": [str(e) for e in simulation.errors], "n_constructs": len(simulation.construct_records), "success": True, } else: # SCENARIO: FULL ASSEMBLY PLAN filelike = file_to_filelike_object(data.assembly_plan) assembly_plan = dc.AssemblyPlan.from_spreadsheet( assembly_class=dc.Type2sRestrictionAssembly, path=filelike, connectors_collection=connectors_collection, expect_no_unused_parts=data.no_skipped_parts, expected_constructs=1 if data.single_assemblies else "any_number", name="_".join(data.assembly_plan.name.split(".")[:-1]), is_csv=data.assembly_plan.name.lower().endswith(".csv"), logger=self.logger, ) simulation = assembly_plan.simulate(sequence_repository=repository) stats = simulation.compute_stats() n_errors = stats["errored_assemblies"] self.logger(message="Done (%d errors), writing report..." % n_errors) report_zip_data = simulation.write_report( target="@memory", assembly_report_writer=report_writer, logger=self.logger, ) errors = [ error for assembly_simulation in simulation.assembly_simulations for error in assembly_simulation.errors ] return { "file": { "data": data_to_html_data(report_zip_data, "zip"), "name": "%s.zip" % assembly_plan.name, "mimetype": "application/zip", }, "assembly_stats": stats, "errors": [str(e) for e in errors], "success": True, } self.logger(message="Simulating the assembly...")
import dnacauldron as dc repository = dc.SequenceRepository() repository.import_records( collection="parts", folder="genetic_parts", use_file_names_as_ids=True, topology="circular", ) repository.import_records( collection="emma_connectors", folder="emma_connectors", use_file_names_as_ids=True, ) all_parts = list(repository.collections["parts"]) # part names, no connectors assembly = dc.Type2sRestrictionAssembly( name="assembly_with_connectors", parts=all_parts, connectors_collection="emma_connectors", ) report_writer = dc.AssemblyReportWriter(include_mix_graphs=True) simulation = assembly.simulate(sequence_repository=repository) simulation.write_report("output", report_writer=report_writer) print("Done! see output/ folder for the results.")
import dnacauldron as dc import os repository = dc.SequenceRepository() repository.import_records(folder="parts", use_file_names_as_ids=True) parts_list = list(repository.collections["parts"]) assembly = dc.Type2sRestrictionAssembly( name="combinatorial_asm", parts=parts_list, expected_constructs="any_number", ) simulation = assembly.simulate(sequence_repository=repository) report_writer = dc.AssemblyReportWriter(include_mix_graphs=True, include_part_plots=True) simulation.write_report( target=os.path.join("output", "combinatorial"), report_writer=report_writer, ) print("Done! see output/combinatorial folder for the results.")
def test_single_assembly_with_wrong_enzyme(tmpdir): assembly = dc.Type2sRestrictionAssembly(parts=["partA", "partB", "partC"], enzyme="BsaI") simulation = assembly.simulate(sequence_repository=repo) assert simulation.construct_records == []