def test_single_transfer(self):
     p = Protocol()
     c = p.ref("test", None, "96-flat", discard=True)
     p.transfer(c.well(0), c.well(1), "20:microliter")
     self.assertEqual(Unit(20, "microliter"), c.well(1).volume)
     self.assertEqual(None, c.well(0).volume)
     self.assertTrue("transfer" in p.instructions[-1].groups[-1])
    def runTest(self):
        p1 = Protocol()
        p2 = Protocol()

        p1.spin("dummy_ref", "2000:rpm", "560:second")
        self.assertEqual(len(p2.instructions), 0,
            "incorrect number of instructions in empty protocol")
 def test_single_well(self):
     p = Protocol()
     test_plate = p.ref("test", None, "96-flat", discard=True)
     p.fluorescence(test_plate, test_plate.well(0),
                    excitation="587:nanometer", emission="610:nanometer",
                    dataref="test_reading")
     self.assertTrue(isinstance(p.instructions[0].wells, list))
    def runTest(self):
        p1 = Protocol()
        p2 = Protocol()

        p1.spin("dummy_ref", "2000:rpm", "560:second")
        self.assertEqual(len(p2.instructions), 0,
                         "incorrect number of instructions in empty protocol")
 def test_duplicates_not_allowed(self):
     p = Protocol()
     p.ref("test", None, "96-flat", discard=True)
     with self.assertRaises(AssertionError):
         p.ref("test", None, "96-flat", storage="cold_20")
     self.assertTrue(p.refs["test"].opts["discard"])
     self.assertFalse("where" in p.refs["test"].opts)
    def test_flow(self):
        """
        Desired Output:
        1. Perform flow cytometry on well0 with the respective FSC and SSC channel parameters
        """

        p = Protocol()
        dataref = "test_ref"
        well0 = p.ref("test_plate", None, "96-pcr",
                      discard=True).well(0)
        FSC = {"voltage_range": {"low": "230:volt", "high": "280:volt"},
               "area": True, "height": True, "weight": False}
        SSC = {"voltage_range": {"low": "230:volt", "high": "280:volt"},
               "area": True, "height": True, "weight": False}
        channel0 = [FSC, SSC]
        neg_controls = [{"well": well0, "volume": "100:microliter",
                         "captured_events": 5, "channel": channel0}]
        samples = [{"well": well0,
                    "volume": "100:microliter", "captured_events": 9}]

        p.flow_analyze(dataref, FSC, SSC, neg_controls,
                       samples)

        pjsonString = json.dumps(p.as_dict(), indent=2)
        pjson = json.loads(pjsonString)
        parser_instance = english.AutoprotocolParser(pjson)
        parser_instance.job_tree()

        parsed_output = parser_instance.parsed_output
        steps = parser_instance.object_list
        forest = parser_instance.forest_list

        self.assertEqual(
            parsed_output, ["Perform flow cytometry on test_plate/0 with the respective FSC and SSC channel parameters"])
        self.assertEqual(forest, [[1]])
 def test_one_tip(self):
     p = Protocol()
     c = p.ref("test", None, "96-flat", discard=True)
     p.transfer(c.wells_from(0, 2), c.wells_from(2, 2), "20:microliter",
         one_tip=True)
     self.assertEqual(c.well(2).volume, c.well(3).volume)
     self.assertEqual(1, len(p.instructions[0].groups))
 def test_single_transfer(self):
     p = Protocol()
     c = p.ref("test", None, "96-flat", discard=True)
     p.transfer(c.well(0), c.well(1), "20:microliter")
     self.assertEqual(Unit(20, "microliter"), c.well(1).volume)
     self.assertEqual(None, c.well(0).volume)
     self.assertTrue("transfer" in p.instructions[-1].groups[-1])
 def test_echo_max_vol(self):
     from autoprotocol.protocol import Protocol
     p = Protocol()
     echo_w = p.ref("echo", None, "384-echo", discard=True).well(0)
     echo_w.set_volume("135:microliter")
     assert echo_w.volume == Unit(135, "microliter")
     with pytest.raises(ValueError):
         echo_w.set_volume("136:microliter")
    def test_one_tip(self):

        p = Protocol()
        plateCount = 2
        plateList = [p.ref("plate_%s_384" % str(x+1), None, "384-flat", discard=True) for x in range(plateCount)]
        p.stamp(plateList[0], plateList[1], "330:microliter", one_tip=True)
        self.assertEqual(len(p.instructions[0].groups[0]["transfer"]), 12)
        self.assertEqual(len(p.instructions[0].groups), 1)
 def test_one_source(self):
     p = Protocol()
     echo = p.ref("echo", None, "384-echo", discard=True)
     dest = p.ref("dest", None, "384-flat", discard=True)
     p.acoustic_transfer(echo.wells(0,1).set_volume("2:microliter"),
                         dest.wells(0,1,2,3), "1:microliter", one_source=True)
     self.assertTrue(p.instructions[-1].data["groups"][0]["transfer"][-1]["from"] == echo.well(1))
     self.assertTrue(p.instructions[-1].data["groups"][0]["transfer"][0]["from"] == echo.well(0))
 def test_echo_max_vol(self):
     from autoprotocol.protocol import Protocol
     p = Protocol()
     echo_w = p.ref("echo", None, "384-echo", discard=True).well(0)
     echo_w.set_volume("135:microliter")
     assert echo_w.volume == Unit(135, "microliter")
     with pytest.raises(ValueError):
         echo_w.set_volume("136:microliter")
    def test_all_container_types(self):
        from autoprotocol.container_type import _CONTAINER_TYPES
        from autoprotocol.protocol import Protocol
        p = Protocol()

        for k, v in _CONTAINER_TYPES.items():
            p.ref(k, None, v.shortname, discard=True)

        assert (len(p.refs) == len(_CONTAINER_TYPES))
 def test_one_tip(self):
     p = Protocol()
     c = p.ref("test", None, "96-flat", discard=True)
     p.transfer(c.wells_from(0, 2),
                c.wells_from(2, 2),
                "20:microliter",
                one_tip=True)
     self.assertEqual(c.well(2).volume, c.well(3).volume)
     self.assertEqual(1, len(p.instructions[0].groups))
    def test_all_container_types(self):
        from autoprotocol.container_type import _CONTAINER_TYPES
        from autoprotocol.protocol import Protocol
        p = Protocol()

        for k, v in _CONTAINER_TYPES.items():
            p.ref(k, None, v.shortname, discard=True)

        assert (len(p.refs) == len(_CONTAINER_TYPES))
 def test_distribute_one_well(self):
     p = Protocol()
     c = p.ref("test", None, "96-flat", discard=True)
     p.distribute(c.well(0).set_volume("20:microliter"),
                  c.well(1),
                  "5:microliter")
     self.assertEqual(1, len(p.instructions))
     self.assertEqual("distribute",
                      list(p.as_dict()["instructions"][0]["groups"][0].keys())[0])
     self.assertTrue(5, c.well(1).volume.value)
     self.assertTrue(15, c.well(0).volume.value)
Beispiel #17
0
    def test_sequence_cover_instructions2(self):
        p = Protocol()
        cont1 = p.ref("c1", None, "96-pcr", storage="cold_4")
        p.incubate(cont1, "ambient", duration="1:minute")
        assert (p.instructions[0].op == "seal")

        cont2 = p.ref("c2", None, "96-pcr", storage="cold_4")
        p.incubate(cont2, "ambient", duration="1:minute", uncovered=True)
        assert (p.instructions[-2].op == "incubate")
        with pytest.raises(RuntimeError):
            p.incubate(cont1, "cold_4", duration="1:minute", uncovered=True)
 def test_distribute_multiple_wells(self):
     p = Protocol()
     c = p.ref("test", None, "96-flat", discard=True)
     p.distribute(c.well(0).set_volume("20:microliter"),
                  c.wells_from(1,3),
                  "5:microliter")
     self.assertEqual(1, len(p.instructions))
     self.assertEqual("distribute",
                      p.as_dict()["instructions"][0]["groups"][0].keys()[0])
     for w in c.wells_from(1,3):
         self.assertTrue(5, w.volume.value)
     self.assertTrue(5, c.well(0).volume.value)
 def test_gt_750uL_wellgroup_transfer(self):
     p = Protocol()
     c = p.ref("test", None, "96-deep", discard=True)
     p.transfer(
         c.wells_from(0, 8, columnwise=True),
         c.wells_from(1, 8, columnwise=True),
         '1800:microliter'
         )
     self.assertEqual(
         24,
         len(p.instructions[0].groups)
         )
 def test_as_dict(self):
     p = Protocol()
     cont1 = p.ref("cont_1", None, "96-flat", discard=True)
     well1 = WellGroup([cont1.well(0)])
     comp = Compound("Daylight Canonical SMILES", "C1=NC2=NC=NC(=C2N1)N")
     assert AttachCompounds(well1, [comp]).as_dict() == {
         "type": "attach_compounds",
         "data": {
             "wells": well1,
             "compounds": [comp]
         },
     }
Beispiel #21
0
    def test_web_example(self):

        p = Protocol()

        bacterial_sample = p.ref("bacteria", None, "micro-1.5", discard=True)
        test_plate = p.ref("test_plate", None, "96-flat", storage="cold_4")

        p.dispense_full_plate(test_plate, "lb-broth-noAB", "50:microliter")
        w = 0
        amt = 1
        while amt < 20:
            p.transfer(bacterial_sample.well(
                0), test_plate.well(w), "%d:microliter" % amt)
            amt += 2
            w += 1

        pjsonString = json.dumps(p.as_dict(), indent=2)
        pjson = json.loads(pjsonString)
        parser_instance = english.AutoprotocolParser(pjson)
        parser_instance.job_tree()

        parsed_output = parser_instance.parsed_output
        steps = parser_instance.object_list
        forest = parser_instance.forest_list

        self.assertEqual(forest, [[1], [2], [3], [4], [5], [
                         6], [7], [8], [9], [10], [11]])
 def test_validate(self):
     p = Protocol()
     cont1 = p.ref("cont_1", None, "96-flat", discard=True)
     well1 = WellGroup([cont1.well(0)])
     comp = Compound("Daylight Canonical SMILES", "C1=NC2=NC=NC(=C2N1)N")
     with pytest.raises(TypeError):
         AttachCompounds(well1, comp)
     with pytest.raises(TypeError):
         AttachCompounds("foo", [comp])
     with pytest.raises(TypeError):
         AttachCompounds(well1, "C1=NC2=NC=NC(=C2N1)N")
     with pytest.raises(CompoundError):
         AttachCompounds(
             well1, [Compound("Daylight Canonical SMILES", "InChI=xxx")])
    def test_attach_compounds(self):
        p = Protocol()
        cont1 = p.ref("cont_1", None, "96-flat", discard=True)
        well1 = cont1.well(0)
        well2 = cont1.well(1)
        wg1 = WellGroup([well1, well2])
        comp1 = Compound("Daylight Canonical SMILES",
                         "CN1C=NC2=C1C(=O)N(C(=O)N2C)C")
        comp2 = Compound("Daylight Canonical SMILES", "C1=NC2=NC=NC(=C2N1)N")

        assert AttachCompounds(well1, [comp1]).compounds == [comp1]
        assert AttachCompounds(well1, [comp1]).wells == well1
        assert AttachCompounds(wg1, [comp1, comp2]).compounds == [comp1, comp2]
        assert AttachCompounds(wg1, [comp1, comp2]).wells == wg1
 def test_single_transfers(self):
     p = Protocol()
     plate_96_list = []
     for plate_num in range(5):
         plate_name = ("test_96_"+str(plate_num))
         plate_96_list.append(p.ref(plate_name, None, "96-flat", discard=True))
     plate_384_list = []
     for plate_num in range(3):
         plate_name = ("test_384_"+str(plate_num))
         plate_384_list.append(p.ref(plate_name, None, "384-flat", discard=True))
     with self.assertRaises(RuntimeError):
         # Transfer 4 plates
         for pl, q in zip(plate_96_list, [0, 1, 24, 26]):
             p.stamp(pl, plate_384_list[0], "10:microliter", to_quad = q)
 def test_multiple_sources(self):
     p = Protocol()
     c = p.ref("test", None, "96-flat", discard=True)
     with self.assertRaises(AssertionError):
         p.consolidate(c.wells_from(0, 3), c.wells_from(2, 3),
                       "10:microliter")
         p.consolidate(c.wells_from(0, 3), c.well(4), ["10:microliter"])
     p.consolidate(c.wells_from(0, 3), c.well(4), "10:microliter")
     self.assertEqual(Unit(30, "microliter"), c.well(4).volume)
     self.assertEqual(
         3, len(p.instructions[0].groups[0]["consolidate"]["from"]))
Beispiel #26
0
 def __init__(self, barcode, well_count, part_num):
     """
     Initializes the class values and populates the
     plate information (e.g. barcode, no of wells, part no.)
     """
     self.barcode = barcode
     self.well_count = well_count
     self.part_num = part_num
     # define the REFs elements
     self.p = Protocol()
     self.id = self.p.ref(self.barcode,
                          id=self.barcode,
                          cont_type="96-pcr",
                          storage=None,
                          discard=True)
     self.plate_protocol()
 def test_multiple_sources(self):
     p = Protocol()
     c = p.ref("test", None, "96-flat", discard=True)
     with self.assertRaises(AssertionError):
         p.consolidate(c.wells_from(0,3), c.wells_from(2,3), "10:microliter")
         p.consolidate(c.wells_from(0,3), c.well(4), ["10:microliter"])
     p.consolidate(c.wells_from(0,3), c.well(4), "10:microliter")
     self.assertEqual(Unit(30,"microliter"), c.well(4).volume)
     self.assertEqual(3, len(p.instructions[0].groups[0]["consolidate"]["from"]))
 def test_unit_conversion(self):
     p = Protocol()
     c = p.ref("test", None, "96-flat", discard=True)
     with self.assertRaises(ValueError):
         p.transfer(c.well(0), c.well(1), "1:liter")
     p.transfer(c.well(0), c.well(1), "200:nanoliter")
     self.assertTrue(str(p.instructions[0].groups[0]['transfer'][0]['volume']) == "0.2:microliter")
     p.transfer(c.well(1), c.well(2), ".5:milliliter", new_group=True)
     self.assertTrue(str(p.instructions[-1].groups[0]['transfer'][0]['volume']) == "500.0:microliter")
 def test_unit_conversion(self):
     p = Protocol()
     c = p.ref("test", None, "96-flat", discard=True)
     with self.assertRaises(RuntimeError):
         with self.assertRaises(ValueError):
             p.distribute(c.well(0).set_volume("100:microliter"), c.well(1), ".0001:liter")
     p.distribute(c.well(0).set_volume("100:microliter"), c.well(1), "200:nanoliter")
     self.assertTrue(str(p.instructions[0].groups[0]["distribute"]["to"][0]["volume"]) == "0.2:microliter")
     p.distribute(c.well(2).set_volume("100:microliter"), c.well(3), ".1:milliliter", new_group=True)
     self.assertTrue(str(p.instructions[-1].groups[0]["distribute"]["to"][0]["volume"]) == "100.0:microliter")
Beispiel #30
0
class Plate(Protocol):
    """
    Object class for working with assay and reagent
    plates in the APmaker program. This object inherits
    from the Protocol object defined in AutoProtocol.
    """
    def __init__(self, barcode, well_count, part_num):
        """
        Initializes the class values and populates the
        plate information (e.g. barcode, no of wells, part no.)
        """
        self.barcode = barcode
        self.well_count = well_count
        self.part_num = part_num
        # define the REFs elements
        self.p = Protocol()
        self.id = self.p.ref(self.barcode,
                             id=self.barcode,
                             cont_type="96-pcr",
                             storage=None,
                             discard=True)
        self.plate_protocol()

    def plate_protocol(self):
        """
        Method to define the protocol that will be applied
        to the plate.
        """
        # weigh the mass of the plate before dispensing
        self.p.measure_mass(self.id, self.barcode + "_mass_before")
        self.p.dispense_full_plate(self.id, "water", "100:microliter")
        self.p.measure_mass(self.id, self.barcode + "_mass_after")
def generate_autoprotocol(instructions_dict):
    p = Protocol()
    part_ref_dict = {}  # ref name: ref_object
    # add destination plate to ref dict
    moclo_dest_plate_name = 'MoCloDestinationPlate'
    moclo_dest_plate_ref = p.ref(moclo_dest_plate_name,
                                 cont_type="96-pcr",
                                 discard=True)
    part_ref_dict[moclo_dest_plate_name] = moclo_dest_plate_ref

    # create refs
    for num, part_name in instructions_dict['parts'].items():
        part_ref = p.ref(part_name, cont_type="96-pcr", discard=True)
        part_ref_dict[part_name] = part_ref

    # create instructions
    for x in range(0, len(instructions_dict['source_wells'])):
        from_well = instructions_dict['source_wells'][x]
        part_name = instructions_dict['parts'][
            from_well]  # get part name in that well
        source_plate = part_ref_dict[part_name]  # get ref object
        volume = instructions_dict['volumes'][x]  # get volume
        volume_str = str(volume) + ':microliter'
        to_well = instructions_dict['dest_wells'][
            x]  # get destination well num

        p.transfer(source_plate.wells_from(from_well, 1),
                   moclo_dest_plate_ref.wells_from(to_well, 1), volume_str)

    return p.as_dict()
 def test_gt_110uL_transfer(self):
     p = Protocol()
     plateCount = 2
     plateList = [p.ref("plate_%s_96" % str(x+1), None, "96-flat", discard=True) for x in range(plateCount)]
     p.stamp(plateList[0], plateList[1], "300:microliter")
     self.assertEqual(3, len(p.instructions[0].groups))
     self.assertEqual(
         Unit(110, 'microliter'),
         p.instructions[0].groups[0]['transfer'][0]['volume']
         )
     self.assertEqual(
         Unit(95, 'microliter'),
         p.instructions[0].groups[1]['transfer'][0]['volume']
         )
     self.assertEqual(
         Unit(95, 'microliter'),
         p.instructions[0].groups[2]['transfer'][0]['volume']
         )
 def test_transfer_option_propagation(self):
     p = Protocol()
     c = p.ref("test", None, "96-deep", discard=True)
     p.transfer(
         c.well(0),
         c.well(1),
         "1800:microliter",
         aspirate_source=aspirate_source(
             depth("ll_bottom", distance=".004:meter")
             )
         )
     self.assertEqual(
         len(p.instructions[0].groups[0]['transfer'][0]),
         len(p.instructions[0].groups[1]['transfer'][0])
         )
     self.assertEqual(
         len(p.instructions[0].groups[0]['transfer'][0]),
         len(p.instructions[0].groups[2]['transfer'][0])
         )
 def test_one_source(self):
     p = Protocol()
     plateCount = 2
     plateList = [p.ref("plate_%s_384" % str(x+1), None, "384-flat", discard=True) for x in range(plateCount)]
     with self.assertRaises(RuntimeError):
             p.stamp(plateList[0].wells(list(range(4))), plateList[1].wells(list(range(12))), "30:microliter", shape={"rows": 8, "columns": 1}, one_source=True)
     plateList[0].wells_from(0, 64, columnwise=True).set_volume("10:microliter")
     with self.assertRaises(RuntimeError):
             p.stamp(plateList[0].wells(list(range(4))), plateList[1].wells(list(range(12))), "30:microliter", shape={"rows": 8, "columns": 1}, one_source=True)
     plateList[0].wells_from(0, 64, columnwise=True).set_volume("15:microliter")
     p.stamp(plateList[0].wells(list(range(4))), plateList[1].wells(list(range(12))), "5:microliter", shape={"rows": 8, "columns": 1}, one_source=True)
     self.assertEqual(len(p.instructions[0].groups), 12)
Beispiel #35
0
    def test_get_wells(self):
        p = Protocol()
        cont1 = p.ref("cont1", None, "6-flat", discard=True)
        cont2 = p.ref("cont2", None, "6-flat", discard=True)
        example_data = {
            "list": [cont1.well(0), cont1.well(1)],
            "well": cont2,
            "dict": {"key1": 1, "key2": "bar", "dict_well": cont1.well(2)},
            "bar": [
                {"key4": "value", "key5": {"well": cont1.well(3)}},
                {"key4": "value", "key5": {"well_group": WellGroup([cont1.well(4)])}},
            ],
            "duplicate": cont1.well(0),
            "nest": [{"list": [{"more_nested": [{"wells": [cont1.well(5)]}]}]}],
        }
        inst = Instruction(op="test", data=example_data)

        wells = set(cont1.all_wells().wells + cont2.all_wells().wells)
        assert set(inst.get_wells(example_data)) == wells
 def test_one_source(self):
     p = Protocol()
     c = p.ref("test", None, "96-flat", discard=True)
     with self.assertRaises(ValueError):
         p.transfer(c.wells_from(0, 2),
                c.wells_from(2, 2), "40:microliter", one_source=True)
     with self.assertRaises(RuntimeError):
         p.transfer(c.wells_from(0, 2).set_volume("1:microliter"),
                    c.wells_from(1, 5), "10:microliter", one_source=True)
     p.transfer(c.wells_from(0, 2).set_volume("50:microliter"),
                c.wells_from(2, 2), "40:microliter", one_source=True)
     self.assertEqual(2, len(p.instructions[0].groups))
     self.assertFalse(p.instructions[0].groups[0]["transfer"][0]["from"] == p.instructions[0].groups[1]["transfer"][0]["from"])
Beispiel #37
0
 def test_info_wells_checker(self):
     p = Protocol()
     cont1 = p.ref("cont1", None, "6-flat", discard=True)
     compd = Compound("Daylight Canonical SMILES", "CN1C=NC2=C1C(=O)N(C(=O)N2C)C")
     example_data = {"objects": [cont1.well(0), cont1.well(1)], "some_int": 1}
     instr = Instruction(
         op="test_instruction",
         data=example_data,
         informatics=[AttachCompounds(cont1.well(0), [compd])],
     )
     avail_wells = instr.get_wells(instr.data)
     with pytest.raises(ValueError):
         instr.informatics[0].wells = None
         instr._check_info_wells(instr.informatics[0], avail_wells)
     with pytest.raises(TypeError):
         instr.informatics[0].wells = "cont1/0"
         instr._check_info_wells(instr.informatics[0], avail_wells)
     with pytest.raises(ValueError):
         instr.informatics[0].wells = cont1.well(10)
         instr._check_info_wells(instr.informatics[0], avail_wells)
    def runTest(self):
        p = Protocol()
        self.assertEqual(len(p.instructions), 0,
            "should not be any instructions before appending to empty protocol")

        p.append(Spin("dummy_ref", "100:meter/second^2", "60:second"))
        self.assertEqual(len(p.instructions), 1,
            "incorrect number of instructions after single instruction append")
        self.assertEqual(p.instructions[0].op, "spin",
            "incorrect instruction appended")

        p.append([
                    Incubate("dummy_ref", "ambient", "30:second"),
                    Spin("dummy_ref", "2000:rpm", "120:second")
                ])
        self.assertEqual(len(p.instructions), 3,
            "incorrect number of instructions after appending instruction list")
        self.assertEqual(p.instructions[1].op, "incubate",
            "incorrect instruction order after list append")
        self.assertEqual(p.instructions[2].op, "spin",
            "incorrect instruction at end after list append.")
 def test_gt_750uL_transfer(self):
     p = Protocol()
     c = p.ref("test", None, "96-deep", discard=True)
     p.transfer(
         c.well(0),
         c.well(1),
         "1800:microliter"
         )
     self.assertEqual(3, len(p.instructions[0].groups))
     self.assertEqual(
         Unit(750, 'microliter'),
         p.instructions[0].groups[0]['transfer'][0]['volume']
         )
     self.assertEqual(
         Unit(750, 'microliter'),
         p.instructions[0].groups[1]['transfer'][0]['volume']
         )
     self.assertEqual(
         Unit(300, 'microliter'),
         p.instructions[0].groups[2]['transfer'][0]['volume']
         )
Beispiel #40
0
    def __init__(self,
                 protocol=Protocol(),
                 items=Items(),
                 db=SolutionDB(),
                 logger=init_logging(),
                 rprotocol=RProtocol()):

        self.protocol = protocol
        self.items = items
        self.db = db
        self.logger = logger
        self.rprotocol = rprotocol
 def test_duplicates_not_allowed(self):
     p = Protocol()
     p.ref("test", None, "96-flat", discard=True)
     with self.assertRaises(AssertionError):
         p.ref("test", None, "96-flat", storage="cold_20")
     self.assertTrue(p.refs["test"].opts["discard"])
     self.assertFalse("where" in p.refs["test"].opts)
    def runTest(self):
        p = Protocol()
        self.assertEqual(
            len(p.instructions), 0,
            "should not be any instructions before appending to empty protocol"
        )

        p.append(Spin("dummy_ref", "100:meter/second^2", "60:second"))
        self.assertEqual(
            len(p.instructions), 1,
            "incorrect number of instructions after single instruction append")
        self.assertEqual(p.instructions[0].op, "spin",
                         "incorrect instruction appended")

        p.append([
            Incubate("dummy_ref", "ambient", "30:second"),
            Spin("dummy_ref", "2000:rpm", "120:second")
        ])
        self.assertEqual(
            len(p.instructions), 3,
            "incorrect number of instructions after appending instruction list"
        )
        self.assertEqual(p.instructions[1].op, "incubate",
                         "incorrect instruction order after list append")
        self.assertEqual(p.instructions[2].op, "spin",
                         "incorrect instruction at end after list append.")
Beispiel #43
0
    def test_dispense_suite(self):
        """
        Desired Output:
        1. Dispense 100 microliters of water to the full plate of sample_plate5
        2. Dispense corresponding amounts of water to 12 column(s) of sample_plate5
        3. Dispense 50 microliters of reagent with resource ID rs17gmh5wafm5p to the full plate of sample_plate5
        """

        p = Protocol()
        sample_plate5 = p.ref("sample_plate5", None,
                              "96-flat", storage="warm_37")

        p.dispense_full_plate(sample_plate5, "water", "100:microliter")
        p.dispense(sample_plate5,
                   "water",
                   [{"column": 0, "volume": "10:microliter"},
                    {"column": 1, "volume": "20:microliter"},
                    {"column": 2, "volume": "30:microliter"},
                    {"column": 3, "volume": "40:microliter"},
                    {"column": 4, "volume": "50:microliter"},
                    {"column": 5, "volume": "60:microliter"},
                    {"column": 6, "volume": "70:microliter"},
                    {"column": 7, "volume": "80:microliter"},
                    {"column": 8, "volume": "90:microliter"},
                    {"column": 9, "volume": "100:microliter"},
                    {"column": 10, "volume": "110:microliter"},
                    {"column": 11, "volume": "120:microliter"}
                    ])
        p.dispense_full_plate(sample_plate5, "rs17gmh5wafm5p", "50:microliter", is_resource_id=True)
        pjsonString = json.dumps(p.as_dict(), indent=2)
        pjson = json.loads(pjsonString)
        parser_instance = english.AutoprotocolParser(pjson)
        parser_instance.job_tree()

        parsed_output = parser_instance.parsed_output
        forest = parser_instance.forest_list

        self.assertEqual(
            parsed_output, ["Dispense 100 microliters of water to the full plate of sample_plate5",
                            "Dispense corresponding amounts of water to 12 column(s) of sample_plate5",
                            "Dispense 50 microliters of resource with resource ID rs17gmh5wafm5p to the full plate of sample_plate5"])
        self.assertEqual(forest, [[1, [2, [3]]]])
 def test_outs(self):
     p = Protocol()
     self.assertFalse('outs' in p.as_dict())
     plate = p.ref("plate", None, "96-pcr", discard=True)
     plate.well(0).set_name("test_well")
     self.assertTrue(plate.well(0).name == "test_well")
     self.assertTrue(list(p.as_dict()['outs'].keys()) == ['plate'])
     self.assertTrue(list(list(p.as_dict()['outs'].values())[0].keys()) == ['0'])
     self.assertTrue(list(p.as_dict()['outs'].values())[0]['0'] == {'name': 'test_well'})
 def test_one_source(self):
     p = Protocol()
     c = p.ref("test", None, "96-flat", discard=True)
     with self.assertRaises(ValueError):
         p.transfer(c.wells_from(0, 2),
                    c.wells_from(2, 2),
                    "40:microliter",
                    one_source=True)
     with self.assertRaises(RuntimeError):
         p.transfer(c.wells_from(0, 2).set_volume("1:microliter"),
                    c.wells_from(1, 5),
                    "10:microliter",
                    one_source=True)
     p.transfer(c.wells_from(0, 2).set_volume("50:microliter"),
                c.wells_from(2, 2),
                "40:microliter",
                one_source=True)
     self.assertEqual(2, len(p.instructions[0].groups))
     self.assertFalse(p.instructions[0].groups[0]["transfer"][0]["from"] ==
                      p.instructions[0].groups[1]["transfer"][0]["from"])
Beispiel #46
0
    def test_informatics():
        p = Protocol()
        cont1 = p.ref("cont1", None, "6-flat", discard=True)
        compd = Compound("Daylight Canonical SMILES", "CN1C=NC2=C1C(=O)N(C(=O)N2C)C")
        example_data = {
            "wells": [cont1.well(0), cont1.well(1)],
            "some_int": 1,
        }
        example_informatics = [AttachCompounds(cont1.well(0), [compd])]
        instr = Instruction(
            op="test_instruction", data=example_data, informatics=example_informatics
        )
        assert isinstance(instr.informatics[0], AttachCompounds)
        assert instr.informatics[0].compounds[0].value == "CN1C=NC2=C1C(=O)N(C(=O)N2C)C"

        instr_multi = Instruction(
            op="test_instruction",
            data=example_data,
            informatics=[
                AttachCompounds(cont1.well(0), [compd]),
                AttachCompounds(cont1.well(1), [compd]),
            ],
        )
        assert len(instr_multi.informatics) == 2
Beispiel #47
0
    def test_illumina(self):
        """
        Desired Output:
        1. Illumina sequence wells test_plate6/0, test_plate6/1 with library size 34
        """

        p = Protocol()
        sample_wells6 = p.ref(
            "test_plate6", None, "96-pcr", discard=True).wells_from(0, 8)
        p.illuminaseq("PE", [{"object": sample_wells6[0], "library_concentration": 1.0},
                             {"object": sample_wells6[1], "library_concentration": 2}],
                      "nextseq", "mid", 'none', 34, "dataref")
        pjsonString = json.dumps(p.as_dict(), indent=2)
        pjson = json.loads(pjsonString)
        parser_instance = english.AutoprotocolParser(pjson)
        parser_instance.job_tree()

        parsed_output = parser_instance.parsed_output
        steps = parser_instance.object_list
        forest = parser_instance.forest_list

        self.assertEqual(
            parsed_output, ["Illumina sequence wells test_plate6/0, test_plate6/1 with library size 34"])
        self.assertEqual(forest, [[1]])
 def test_distribute_one_well(self):
     p = Protocol()
     c = p.ref("test", None, "96-flat", discard=True)
     p.distribute(
         c.well(0).set_volume("20:microliter"), c.well(1), "5:microliter")
     self.assertEqual(1, len(p.instructions))
     self.assertEqual("distribute",
                      p.as_dict()["instructions"][0]["groups"][0].keys()[0])
     self.assertTrue(5, c.well(1).volume.value)
     self.assertTrue(15, c.well(0).volume.value)
    def test_refifying_various(self):
        p = Protocol()
        # refify container
        refs = {"plate": p.ref("test", None, "96-flat", "cold_20")}
        self.assertEqual(p._refify(refs["plate"]), "test")
        # refify dict
        self.assertEqual(p._refify(refs), {"plate": "test"})

        # refify Well
        well = refs["plate"].well("A1")
        self.assertEqual(p._refify(well), "test/0")

        # refify WellGroup
        wellgroup = refs["plate"].wells_from("A2", 3)
        self.assertEqual(p._refify(wellgroup), ["test/1", "test/2", "test/3"])

        # refify other
        s = "randomstring"
        i = 24
        self.assertEqual("randomstring", p._refify(s))
        self.assertEqual(24, p._refify(i))
    def test_one_tip_variable_volume(self):

        p = Protocol()
        plateCount = 2
        plateList = [p.ref("plate_%s_384" % str(x+1), None, "384-flat", discard=True) for x in range(plateCount)]
        with self.assertRaises(RuntimeError):
            p.stamp(WellGroup([plateList[0].well(0), plateList[0].well(1)]), WellGroup([plateList[1].well(0), plateList[1].well(1)]), ["20:microliter", "90:microliter"], one_tip=True)
        p.stamp(WellGroup([plateList[0].well(0), plateList[0].well(1)]), WellGroup([plateList[1].well(0), plateList[1].well(1)]), ["20:microliter", "90:microliter"], mix_after=True, mix_vol="40:microliter", one_tip=True)
        self.assertEqual(len(p.instructions[0].groups[0]["transfer"]), 2)
        self.assertEqual(len(p.instructions[0].groups), 1)
 def test_distribute_multiple_wells(self):
     p = Protocol()
     c = p.ref("test", None, "96-flat", discard=True)
     p.distribute(
         c.well(0).set_volume("20:microliter"), c.wells_from(1, 3),
         "5:microliter")
     self.assertEqual(1, len(p.instructions))
     self.assertEqual(
         "distribute",
         list(p.as_dict()["instructions"][0]["groups"][0].keys())[0])
     for w in c.wells_from(1, 3):
         self.assertTrue(5, w.volume.value)
     self.assertTrue(5, c.well(0).volume.value)
    def test_refifying_various(self):
        p = Protocol()
        # refify container
        refs = {"plate": p.ref("test", None, "96-flat", "cold_20")}
        self.assertEqual(p._refify(refs["plate"]), "test")
        # refify dict
        self.assertEqual(p._refify(refs), {"plate": "test"})

        # refify Well
        well = refs["plate"].well("A1")
        self.assertEqual(p._refify(well), "test/0")

        # refify WellGroup
        wellgroup = refs["plate"].wells_from("A2", 3)
        self.assertEqual(p._refify(wellgroup), ["test/1", "test/2", "test/3"])

        # refify other
        s = "randomstring"
        i = 24
        self.assertEqual("randomstring", p._refify(s))
        self.assertEqual(24, p._refify(i))
    def test_fill_wells(self):
        p = Protocol()
        c = p.ref("test", None, "96-flat", discard=True)
        srcs = c.wells_from(1, 2).set_volume("100:microliter")
        dests = c.wells_from(7, 4)
        p.distribute(srcs, dests, "30:microliter", allow_carryover=True)
        self.assertEqual(2, len(p.instructions[0].groups))

        #track source vols
        self.assertEqual(10, c.well(1).volume.value)
        self.assertEqual(70, c.well(2).volume.value)

        # track dest vols
        self.assertEqual(30, c.well(7).volume.value)
        self.assertIs(None, c.well(6).volume)

        #test distribute from Well to Well
        p.distribute(
            c.well("A1").set_volume("20:microliter"), c.well("A2"),
            "5:microliter")
        self.assertTrue("distribute" in p.instructions[-1].groups[-1])
import json
from autoprotocol.protocol import Protocol
from utils import ul

inv = {
    'gblock_dna': 'ct18vs7cmjat2c',  # my inventory
    'te': 'rs17pwyc754v9t',  # catalog; TE
}

p = Protocol()

#existing inventory
dna_sample = p.ref("gblock_dna",
                   id=inv['gblock_dna'],
                   cont_type="micro-1.5",
                   storage='cold_20')

#tubes are thawed before being placed into workcell

#Centrifuge the tube for 3-5 sec at a minimum of 3000 x g to pellet the material to the bottom of the tube.
p.spin(dna_sample, '3000:g', '5:second')

#Add 500uL TE (to reach 1 ng/uL)
p.provision(inv["te"], dna_sample.well(0), ul(500))

#Briefly vortex (here we have to use mix) and centrifuge

p.mix(dna_sample.well(0),
      '480:microliter',
      speed='480:microliter/second',
      repetitions=10)
 def test_slashes_not_allowed(self):
     p = Protocol()
     with self.assertRaises(AssertionError):
         p.ref("test/bar", None, "96-flat", discard=True)
     self.assertEqual(0, len(p.refs))
Beispiel #56
0
 def setup(self):
     self.p = Protocol()
     self.flat = self.p.ref("flat", cont_type="96-flat", discard=True)
     self.deep = self.p.ref("deep", cont_type="96-deep", discard=True)
Beispiel #57
0
class LiquidHandleTester(object):
    @pytest.fixture(autouse=True)
    def setup(self):
        self.p = Protocol()
        self.flat = self.p.ref("flat", cont_type="96-flat", discard=True)
        self.deep = self.p.ref("deep", cont_type="96-deep", discard=True)
Beispiel #58
0
class TestProvision(object):
    @pytest.fixture(autouse=True)
    def setup(self):
        # pylint: disable=attribute-defined-outside-init
        self.p = Protocol()
        # pylint: disable=attribute-defined-outside-init
        self.w1 = (self.p.ref("w1", None, cont_type="96-pcr",
                              discard=True).well(0).set_volume("2:microliter"))

    def test_provision_well_capacity(self):
        self.p.provision("rs17gmh5wafm5p", self.w1, "50:microliter")
        actual_instruction_as_json = json.dumps(
            self.p.as_dict()["instructions"], indent=2, sort_keys=True)
        expected_instruction_as_json = TestUtils.read_json_file(
            "expected_provision.json")

        assert expected_instruction_as_json == actual_instruction_as_json

    def test_attempt_to_provision_more_than_well_capacity(self):
        with pytest.raises(ValueError):
            self.p.provision("rs17gmh5wafm5p", self.w1, "500:microliter")

    def test_with_invalid_resource_id(self):
        with pytest.raises(TypeError):
            self.p.provision(100, self.w1, "50:microliter")

    def test_with_destinations_count_not_same_as_volumes(self):
        volumes = ["50:microliter", "20:microliter"]
        with pytest.raises(RuntimeError):
            self.p.provision("rs17gmh5wafm5p", self.w1, volumes)

    def test_with_volume_above_max(self):
        with pytest.raises(ValueError):
            self.p.provision("rs17gmh5wafm5p", self.w1, "200:microliter")

    def test_with_multiple_wells(self):
        w2 = (self.p.ref("w2", None, cont_type="96-pcr",
                         discard=True).well(0).set_volume("2:microliter"))
        w3 = (self.p.ref("w3", None, cont_type="96-pcr",
                         discard=True).well(0).set_volume("2:microliter"))
        wells = [self.w1, w2, w3]
        self.p.provision("rs17gmh5wafm5p", wells, "50:microliter")
        actual_instruction_as_json = json.dumps(
            self.p.as_dict()["instructions"], indent=2, sort_keys=True)
        expected_instruction_as_json = TestUtils.read_json_file(
            "provision_multiple_wells.json")

        assert expected_instruction_as_json == actual_instruction_as_json

    def test_with_consecutive_repeated_wells(self):
        wells = [self.w1, self.w1]
        self.p.provision("rs17gmh5wafm5p", wells, "50:microliter")
        actual_instruction_as_json = json.dumps(
            self.p.as_dict()["instructions"], indent=2, sort_keys=True)
        expected_instruction_as_json = TestUtils.read_json_file(
            "provision_with_consecutive_repeated_wells.json")

        assert expected_instruction_as_json == actual_instruction_as_json

    def test_with_repeated_wells_but_discontinuous(self):
        w2 = (self.p.ref("w2", None, cont_type="96-pcr",
                         discard=True).well(0).set_volume("2:microliter"))
        wells = [self.w1, w2, self.w1]
        self.p.provision("rs17gmh5wafm5p", wells, "50:microliter")
        actual_instruction_as_json = json.dumps(
            self.p.as_dict()["instructions"], indent=2, sort_keys=True)
        expected_instruction_as_json = TestUtils.read_json_file(
            "provision_with_repeated_wells_but_discontinuous.json")

        assert expected_instruction_as_json == actual_instruction_as_json

    def test_with_multiple_wells_with_different_cont_types(self):
        self.p.refs.clear()
        w1 = (self.p.ref("w1", None, cont_type="1-flat",
                         discard=True).well(0).set_volume("2:microliter"))
        w2 = (self.p.ref("w2", None, cont_type="6-flat-tc",
                         discard=True).well(0).set_volume("2:microliter"))
        wells = [w1, w2]
        self.p.provision("rs17gmh5wafm5p", wells, "1500:microliter")
        actual_instruction_as_json = json.dumps(
            self.p.as_dict()["instructions"], indent=2, sort_keys=True)
        expected_instruction_as_json = TestUtils.read_json_file(
            "provision_multiple_wells_with_diff_cont_types.json")

        assert expected_instruction_as_json == actual_instruction_as_json

    def test_provision_with_covered_container(self):
        self.p.refs.clear()
        w1 = (self.p.ref("w1",
                         None,
                         cont_type="96-pcr",
                         discard=True,
                         cover="standard").well(0).set_volume("2:microliter"))
        self.p.provision("rs17gmh5wafm5p", w1, "50:microliter")
        actual_instruction_as_json = json.dumps(
            self.p.as_dict()["instructions"], indent=2, sort_keys=True)
        expected_instruction_as_json = TestUtils.read_json_file(
            "provision_with_cover.json")

        assert expected_instruction_as_json == actual_instruction_as_json

    def test_provision_with_sealed_container(self):
        self.p.refs.clear()
        w1 = (self.p.ref("w1",
                         None,
                         cont_type="96-pcr",
                         discard=True,
                         cover="foil").well(0).set_volume("2:microliter"))
        self.p.provision("rs17gmh5wafm5p", w1, "50:microliter")
        actual_instruction_as_json = json.dumps(
            self.p.as_dict()["instructions"], indent=2, sort_keys=True)
        expected_instruction_as_json = TestUtils.read_json_file(
            "provision_with_seal.json")

        assert expected_instruction_as_json == actual_instruction_as_json

    def test_for_multiple_dispenses_of_resource_in_containers_larger_than_900ml(
            self):
        self.p.refs.clear()
        w1 = (self.p.ref("w1", None, cont_type="micro-2.0",
                         discard=True).well(0).set_volume("2:microliter"))
        self.p.provision("rs17gmh5wafm5p", w1, volumes="1500:microliter")

        actual_instruction_as_json = json.dumps(
            self.p.as_dict()["instructions"], indent=2, sort_keys=True)
        expected_instruction_as_json = TestUtils.read_json_file(
            "split_provisions_by_volume.json")
        assert expected_instruction_as_json == actual_instruction_as_json

    def test_provision_well_with_mass(self):
        self.p.provision("rs17gmh5wafm5p", self.w1, amounts="50:ug")
        actual_instruction_as_json = json.dumps(
            self.p.as_dict()["instructions"], indent=2, sort_keys=True)
        expected_instruction_as_json = TestUtils.read_json_file(
            "provision_for_mass.json")

        assert expected_instruction_as_json == actual_instruction_as_json

    def test_provision_multiple_wells_with_diff_masses(self):
        w2 = (self.p.ref("w2", None, cont_type="96-pcr",
                         discard=True).well(0).set_volume("2:microliter"))
        self.p.provision("rs17gmh5wafm5p", [self.w1, w2], ["50:ug", "25:mg"])
        actual_instruction_as_json = json.dumps(
            self.p.as_dict()["instructions"], indent=2, sort_keys=True)
        expected_instruction_as_json = TestUtils.read_json_file(
            "provision_with_more_than_one_mass.json")

        assert expected_instruction_as_json == actual_instruction_as_json

    def test_provision_wells_with_amounts_of_varying_measurement_modes(self):
        w2 = (self.p.ref("w2", None, cont_type="96-pcr",
                         discard=True).well(0).set_volume("2:microliter"))
        with pytest.raises(ValueError):
            self.p.provision("rs17gmh5wafm5p", [self.w1, w2],
                             ["50:lb", "50:gallon"])

    def test_provision_passing_both_volumes_and_amounts(self):
        with pytest.raises(ValueError):
            self.p.provision("rs17gmh5wafm5p", self.w1, "25:ul", "50:mg")

    def test_provision_well_with_neither_mass_nor_volume(self):
        with pytest.raises(ValueError):
            self.p.provision("rs17gmh5wafm5p", self.w1)
Beispiel #59
0
 def setup(self):
     # pylint: disable=attribute-defined-outside-init
     self.p = Protocol()
     # pylint: disable=attribute-defined-outside-init
     self.w1 = (self.p.ref("w1", None, cont_type="96-pcr",
                           discard=True).well(0).set_volume("2:microliter"))