예제 #1
0
def test_hierarchical_biobrick():
    repository = dc.SequenceRepository()
    repository.import_records(folder=parts_folder, use_file_names_as_ids=True)
    assembly_plan = dc.AssemblyPlan.from_spreadsheet(
        assembly_class=dc.BioBrickStandardAssembly,
        path=os.path.join(this_directory, "hierarchical_biobrick.csv"),
    )
    plan_simulation = assembly_plan.simulate(sequence_repository=repository)
    stats = plan_simulation.compute_stats()
    assert stats["valid_assemblies"] == 3
    report_writer = dc.AssemblyReportWriter(include_mix_graphs=True)
    plan_simulation.write_report("@memory",
                                 assembly_report_writer=report_writer)
예제 #2
0
def test_gibson_assembly_plan():
    repository = dc.SequenceRepository()
    repository.import_records(files=[sequences_fasta])
    assembly_plan = dc.AssemblyPlan.from_spreadsheet(
        assembly_class=dc.GibsonAssembly,
        path=os.path.join(this_directory, "gibson_plan.csv"),
    )
    plan_simulation = assembly_plan.simulate(sequence_repository=repository)
    stats = plan_simulation.compute_stats()
    assert stats["valid_assemblies"] == 3
    assert stats["errored_assemblies"] == 2
    report_writer = dc.AssemblyReportWriter(
        include_mix_graphs=True,
        include_assembly_plots=True,
        show_overhangs_in_graph=True,
        annotate_parts_homologies=True,
    )
    plan_simulation.write_report(target="@memory",
                                 assembly_report_writer=report_writer)
예제 #3
0
def test_single_assembly(tmpdir):
    repository = dc.SequenceRepository()
    repository.import_records(folder=parts_folder, use_file_names_as_ids=True)
    assembly_plan = dc.AssemblyPlan.from_spreadsheet(
        assembly_class=dc.Type2sRestrictionAssembly,
        path=os.path.join(this_directory, "type2s_two-level.csv"),
    )
    plan_simulation = assembly_plan.simulate(sequence_repository=repository)
    stats = plan_simulation.compute_stats()
    report_writer = dc.AssemblyReportWriter(
        include_fragment_plots=False,
        include_part_plots=False,
        include_mix_graphs=False,
        include_assembly_plots=False,
        show_overhangs_in_graph=False,
        annotate_parts_homologies=False,
        include_pdf_report=True,
    )
    plan_simulation.write_report(target="@memory", assembly_report_writer=report_writer)
예제 #4
0
def test_type2s_hierarchical_flawed():
    repository = dc.SequenceRepository()
    repository.import_records(folder=parts_folder, use_file_names_as_ids=True)
    assembly_plan = dc.AssemblyPlan.from_spreadsheet(
        assembly_class=dc.Type2sRestrictionAssembly,
        path=os.path.join(this_directory, "type2s_two-level_flawed.xls"),
    )
    assert sorted(assembly_plan.levels) == [1, 2]
    plan_simulation = assembly_plan.simulate(sequence_repository=repository)
    stats = plan_simulation.compute_stats()
    assert stats["valid_assemblies"] == 2  # Construct 1 and its dependant
    assert stats["errored_assemblies"] == 1
    assert stats["cancelled_assemblies"] == 1

    report_writer = dc.AssemblyReportWriter(
        include_fragment_plots=True,
        include_part_plots=True,
        include_mix_graphs=True,
        include_assembly_plots=True,
        show_overhangs_in_graph=True,
        annotate_parts_homologies=True,
    )
    plan_simulation.write_report(target="@memory",
                                 assembly_report_writer=report_writer)
    def work(self):
        data = self.data
        logger = self.logger
        logger(message="Reading the 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

        # INITIALIZE ALL RECORDS IN A SEQUENCE REPOSITORY

        logger(message="Parsing the sequences...")

        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:
            set_record_topology(r, topology=data.topology)
            r.seq = r.seq.upper()
        repository.add_records(records, collection="parts")

        # CREATE A CONNECTORS COLLECTION IF CONNECTORS ARE PROVIDED
        if len(data.connectors):
            connector_records = records_from_data_files(data.connectors)
            for r in connector_records:
                set_record_topology(r, topology=data.topology)
                r.seq = r.seq.upper()
                if hasattr(r, "zip_file_name"):
                    collection_name = ".".join(r.zip_file_name.split(".")[:-1])
                else:
                    collection_name = ".".join(r.file_name.split(".")[:-1])
                repository.add_record(r, collection=collection_name)

        logger(message="Simulating the assembly plan...")
        filelike = file_to_filelike_object(data.assembly_plan)
        assembly_plan = dc.AssemblyPlan.from_spreadsheet(
            assembly_class="from_spreadsheet",
            path=filelike,
            name="_".join(data.assembly_plan.name.split(".")[:-1]),
            is_csv=data.assembly_plan.name.lower().endswith(".csv"),
            logger=logger,
        )
        simulation = assembly_plan.simulate(sequence_repository=repository)
        stats = simulation.compute_stats()
        n_errors = stats["errored_assemblies"]
        logger(submessage="%s error(s) found" % 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
        ]
        logger(message="All done!")

        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,
        }
예제 #6
0
import dnacauldron as dc

repository = dc.SequenceRepository()
repository.import_records(folder="parts", use_file_names_as_ids=True)
assembly_plan = dc.AssemblyPlan.from_spreadsheet(
    assembly_class=dc.Type2sRestrictionAssembly,
    path="golden_gate_two_levels.csv",
)
plan_simulation = assembly_plan.simulate(sequence_repository=repository)
report_writer = dc.AssemblyReportWriter(include_mix_graphs=True,
                                        include_assembly_plots=True)
plan_simulation.write_report("output", assembly_report_writer=report_writer)
예제 #7
0
    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...")
예제 #8
0
import dnacauldron as dc

repository = dc.SequenceRepository()
repository.import_records(files=["gibson_sequences.fa"])
assembly_plan = dc.AssemblyPlan.from_spreadsheet(
    assembly_class=dc.GibsonAssembly, path="gibson_assembly.csv")
plan_simulation = assembly_plan.simulate(sequence_repository=repository)
print("Assembly stats:", plan_simulation.compute_stats())

report_writer = dc.AssemblyReportWriter(
    include_mix_graphs=True,
    include_assembly_plots=True,
    show_overhangs_in_graph=True,
    annotate_parts_homologies=True,
)
plan_simulation.write_report(target="output",
                             assembly_report_writer=report_writer)