Ejemplo n.º 1
0
 def test_create(self):
     sbol3.set_namespace('https://github.com/synbiodex/pysbol3')
     agent = sbol3.Agent('agent')
     usage = sbol3.Usage(agent.identity)
     self.assertIsNotNone(usage)
     self.assertEqual(agent.identity, usage.entity)
     self.assertEqual([], usage.roles)
Ejemplo n.º 2
0
 def test_create(self):
     sbol3.set_namespace('https://github.com/synbiodex/pysbol3')
     agent = sbol3.Agent('agent')
     association = sbol3.Association(agent)
     self.assertIsNotNone(association)
     self.assertEqual([], association.roles)
     self.assertEqual(None, association.plan)
     self.assertEqual(agent.identity, association.agent)
Ejemplo n.º 3
0
 def test_create(self):
     sbol3.set_namespace('https://github.com/synbiodex/pysbol3')
     display_id = 'agent'
     agent = sbol3.Agent(display_id)
     self.assertIsNotNone(agent)
     self.assertEqual(display_id, agent.display_id)
     # attachments come from TopLevel
     self.assertEqual([], agent.attachments)
Ejemplo n.º 4
0
    def test_create_protocol(self):
        protocol: paml.Protocol
        doc: sbol3.Document
        logger = logging.getLogger("LUDOX_protocol")
        logger.setLevel(logging.INFO)
        protocol, doc = protocol_def.ludox_protocol()

        ########################################
        # Validate and write the document

        agent = sbol3.Agent("test_agent")

        # Execute the protocol
        # In order to get repeatable timings, we use ordinal time in the test
        # where each timepoint is one second after the previous time point
        ee = ExecutionEngine(use_ordinal_time=True)
        parameter_values = [
            paml.ParameterValue(
                parameter=protocol.get_input("wavelength"),
                value=uml.LiteralIdentified(
                    value=sbol3.Measure(100, tyto.OM.nanometer)))
        ]
        execution = ee.execute(protocol,
                               agent,
                               id="test_execution",
                               parameter_values=parameter_values)

        # Get the SampleData objects and attach values
        # get_data() returns a dict of output parameter ids to SampleData objects
        dataset = execution.get_data()

        for k, v in dataset.data_vars.items():
            for dimension in v.dims:
                new_data = [8] * len(dataset[k].data)
                dataset.update({k: (dimension, new_data)})

        execution.set_data(dataset)

        print('Validating and writing protocol')
        v = doc.validate()
        assert len(v) == 0, "".join(f'\n {e}' for e in v)

        temp_name = os.path.join(tempfile.gettempdir(),
                                 'igem_ludox_data_test.nt')
        doc.write(temp_name, sbol3.SORTED_NTRIPLES)
        print(f'Wrote file as {temp_name}')

        comparison_file = os.path.join(
            os.path.dirname(os.path.realpath(__file__)), 'testfiles',
            'igem_ludox_data_test.nt')
        # doc.write(comparison_file, sbol3.SORTED_NTRIPLES)
        print(f'Comparing against {comparison_file}')
        assert filecmp.cmp(temp_name,
                           comparison_file), "Files are not identical"
        print('File identical with test file')
Ejemplo n.º 5
0
    def _run_execution(self, doc, specializations):

        protocol = doc.find(
            "https://bbn.com/scratch/iGEM_LUDOX_OD_calibration_2018")

        #############################################
        # Execution Configuration
        ee = ExecutionEngine(specializations=specializations)
        agent = sbol3.Agent("test_agent")
        parameter_values = [
            paml.ParameterValue(
                parameter=protocol.get_input("wavelength"),
                value=uml.LiteralIdentified(
                    value=sbol3.Measure(100, tyto.OM.nanometer)))
        ]

        #############################################
        # Execute Protocol and Convert
        execution = ee.execute(protocol,
                               agent,
                               id="test_execution",
                               parameter_values=parameter_values)
Ejemplo n.º 6
0
    def test_execute_protocol(self):
        #############################################
        # set up the document
        print('Setting up document')
        doc = sbol3.Document()
        sbol3.set_namespace('https://bbn.com/scratch/')

        protocol_file = os.path.join(
            os.path.dirname(os.path.realpath(__file__)), "testfiles",
            "igem_ludox_test.nt")
        doc.read(protocol_file, 'nt')

        protocol = doc.find(
            "https://bbn.com/scratch/iGEM_LUDOX_OD_calibration_2018")
        agent = sbol3.Agent("test_agent")

        # print('Importing libraries')
        # paml.import_library('liquid_handling')
        # print('... Imported liquid handling')

        ee = ExecutionEngine()
        parameter_values = [
            paml.ParameterValue(parameter=protocol.get_input("wavelength"),
                                value=sbol3.Measure(100, tyto.OM.nanometer))
        ]
        execution = ee.execute(protocol,
                               agent,
                               id="test_execution",
                               parameter_values=parameter_values)

        #dot = execution.to_dot()
        #dot.render(f'{protocol.name}.gv')
        #dot.view()  # uncomment to see it on your own screen

        ########################################
        # Validate and write the document
        print('Validating and writing protocol')
        v = doc.validate()
        assert len(v) == 0, "".join(f'\n {e}' for e in v)
Ejemplo n.º 7
0
    def test_create_protocol(self):
        protocol: paml.Protocol
        doc: sbol3.Document
        logger = logging.getLogger("transfer_map_protocol")
        logger.setLevel(logging.INFO)
        protocol, doc = initialize_protocol()

        # The aliquots will be the coordinates of the SampleArray and SampleMap objects
        num_aliquots = 4
        aliquot_ids = list(range(num_aliquots))

        # Make Components for the contents of the SampleArray
        reagent1 = sbol3.Component(
            'ddH2Oa', 'https://identifiers.org/pubchem.substance:24901740')
        reagent2 = sbol3.Component(
            'ddH2Ob', 'https://identifiers.org/pubchem.substance:24901740')
        reagents = [reagent1, reagent2]

        # TODO ContainerSpec without parameters will refer to a logical container of unspecified size and geometry
        source_spec = paml.ContainerSpec(name='abstractPlateRequirement1')
        target_spec = paml.ContainerSpec(name='abstractPlateRequirement2')

        # Arbitrary volume to use in specifying the reagents in the container.
        default_volume = sbol3.Measure(600, tyto.OM.microliter)

        # Creating the source SampleArray involves the following steps:
        # 1. Calling the EmptyContainer primitive with a defined specifcation
        # 2. Creating the SampleArray and referencing the specification.
        #    (SBOLFactory needs the specification to have an identity, which only
        #     happens in step 1.)
        # 3. Remove the EmptyContainer InputPin for "sample_array"
        # 4. Create a ValuePin for "sample_array" and add it to the input of the EmptyContainer call.
        #    (This is a place where we can map a SampleArray to a container)

        # 1.
        create_source = protocol.primitive_step('EmptyContainer',
                                                specification=source_spec)

        # 2.
        # The SampleArray is a 2D |aliquot| x |reagent| array, where values are volumes.
        # The aliquot dimension uses aliquot_ids (specified above) as coordinates.
        # The reagent dimension uses reagents (specified above) as coordinates.
        #
        # Results in the DataArray representing contents:
        #
        # <xarray.DataArray (aliquot: 4, contents: 2)>
        # array([[600., 600.],
        #        [600., 600.],
        #        [600., 600.],
        #        [600., 600.]])
        # Coordinates:
        #   * aliquot   (aliquot) int64 0 1 2 3
        #   * contents  (contents) <U30 'https://bbn.com/scratch/ddH2Oa' 'https://bbn.c...
        source_array = paml.SampleArray(
            name="source",
            container_type=source_spec,
            contents=json.dumps(
                xr.DataArray(
                    [[default_volume.value for reagent in reagents]
                     for id in aliquot_ids],
                    dims=("aliquot", "contents"),
                    coords={
                        "aliquot": aliquot_ids,
                        "contents": [r.identity for r in reagents]
                    }).to_dict()))
        # 3.
        sample_array_parameter = create_source.pin_parameter("sample_array")
        [old_input
         ] = [x for x in create_source.inputs if x.name == "sample_array"]
        create_source.inputs.remove(old_input)

        # 4.
        create_source.inputs.append(
            uml.ValuePin(
                name="sample_array",
                is_ordered=sample_array_parameter.property_value.is_ordered,
                is_unique=sample_array_parameter.property_value.is_unique,
                value=uml.literal(source_array)))

        # Similar to the source_array, above, we specify an analogous target_array
        # 1.
        create_target = protocol.primitive_step('EmptyContainer',
                                                specification=target_spec)

        # 2.
        target_array = paml.SampleArray(
            name="target",
            container_type=target_spec,
            contents=json.dumps(
                xr.DataArray(
                    [[0.0 for reagent in reagents] for id in aliquot_ids],
                    dims=("aliquot", "contents"),
                    coords={
                        "aliquot": aliquot_ids,
                        "contents": [r.identity for r in reagents]
                    }).to_dict()))

        # 3.
        sample_array_parameter = create_target.pin_parameter("sample_array")
        [old_input
         ] = [x for x in create_target.inputs if x.name == "sample_array"]
        create_target.inputs.remove(old_input)

        # 4.
        create_target.inputs.append(
            uml.ValuePin(
                name="sample_array",
                is_ordered=sample_array_parameter.property_value.is_ordered,
                is_unique=sample_array_parameter.property_value.is_unique,
                value=uml.literal(target_array)))

        # plan_mapping is a 4D array of volumes for transfers:
        #    (source_array, source_aliquot) --volume--> (target_array, target_aliquot)
        #
        # The plan_mapping from above is a single source_array and single target_array:
        #
        # <xarray.DataArray (source_array: 1, source_aliquot: 4, target_array: 1,
        #                    target_aliquot: 4)>
        # array([[[[10., 10., 10., 10.]],

        #         [[10., 10., 10., 10.]],

        #         [[10., 10., 10., 10.]],

        #         [[10., 10., 10., 10.]]]])
        # Coordinates:
        #   * source_array    (source_array) <U6 'source'
        #   * source_aliquot  (source_aliquot) int64 0 1 2 3
        #   * target_array    (target_array) <U6 'target'
        #   * target_aliquot  (target_aliquot) int64 0 1 2 3

        plan_mapping = json.dumps(
            xr.DataArray(
                [[[[10.0 for target_aliquot in aliquot_ids]
                   for target_array in [target_array.name]]
                  for source_aliquot in aliquot_ids]
                 for source_array in [source_array.name]],
                dims=(
                    "source_array",
                    "source_aliquot",
                    "target_array",
                    "target_aliquot",
                ),
                coords={
                    "source_array": [source_array.name],
                    "source_aliquot": aliquot_ids,
                    "target_array": [target_array.name],
                    "target_aliquot": aliquot_ids
                }).to_dict())

        # The SampleMap specifies the sources and targets, along with the mappings.
        plan = paml.SampleMap(sources=[source_array],
                              targets=[target_array],
                              values=plan_mapping)

        # The outputs of the create_source and create_target calls will be identical
        # to the source_array and target_array.  They will not be on the output pin
        # until execution, but the SampleMap needs to reference them.
        transfer_by_map = protocol.primitive_step(
            'TransferByMap',
            source=create_source.output_pin('samples'),
            destination=create_target.output_pin('samples'),
            plan=plan)

        ########################################
        # Validate and write the document

        agent = sbol3.Agent("test_agent")

        # Execute the protocol
        # In order to get repeatable timings, we use ordinal time in the test
        # where each timepoint is one second after the previous time point
        ee = ExecutionEngine(use_ordinal_time=True)
        parameter_values = [
            # paml.ParameterValue(parameter=protocol.get_input("wavelength"),
            #                     value=uml.LiteralIdentified(value=sbol3.Measure(100, tyto.OM.nanometer)))
        ]
        execution = ee.execute(protocol,
                               agent,
                               id="test_execution",
                               parameter_values=parameter_values)

        print('Validating and writing protocol')
        v = doc.validate()
        assert len(v) == 0, "".join(f'\n {e}' for e in v)

        temp_name = os.path.join(tempfile.gettempdir(),
                                 'igem_ludox_data_test.nt')
        doc.write(temp_name, sbol3.SORTED_NTRIPLES)
        print(f'Wrote file as {temp_name}')

        comparison_file = os.path.join(
            os.path.dirname(os.path.realpath(__file__)), 'testfiles',
            'sample_map_test.nt')
        doc.write(comparison_file, sbol3.SORTED_NTRIPLES)
        print(f'Comparing against {comparison_file}')
        assert filecmp.cmp(temp_name,
                           comparison_file), "Files are not identical"
        print('File identical with test file')