예제 #1
0
    def test_sequence_cover_instructions(self):
        p = Protocol()
        cont1 = p.ref("c1", None, "384-pcr", storage="cold_4")
        cont2 = p.ref("c2", None, "384-pcr", storage="cold_4")
        cont3 = p.ref("c3", None, "96-deep", storage="cold_4")
        cont4 = p.ref("c4", None, "micro-1.5", storage="cold_4")
        cont5 = p.ref("c5", None, "384-echo", discard=True)
        therm_groups = [
            {
                "cycles": 1,
                "steps": [
                    {
                        "temperature": "37:celsius",
                        "duration": "60:minute"
                    },
                ]
            }
        ]
        p.incubate(cont1, "ambient", duration="1:minute")
        self.assertEqual(p.instructions[0].op, "seal")
        self.assertEqual(p.instructions[1].op, "incubate")
        self.assertEqual(cont1.cover, 'ultra-clear')
        p.spin(cont1, acceleration="1000:g", duration="2:minute")
        self.assertEqual(cont1.cover, "ultra-clear")
        self.assertEqual(cont2.cover, None)
        p.thermocycle(cont2, groups=therm_groups)

        self.assertEqual(cont2.cover, "ultra-clear")
        p.transfer(cont2.well(0), cont1.well(1), volume="1:microliter")
        self.assertEqual(cont1.cover, None)
        self.assertEqual(cont2.cover, None)
        with self.assertRaises(RuntimeError):
            p.cover(cont2)
        p.seal(cont2)
        p.thermocycle(cont1, groups=therm_groups)
        self.assertEqual(cont1.cover, "ultra-clear")
        p.spin(cont1, acceleration="1000:g", duration="2:minute")
        p.spin(cont2, acceleration="1000:g", duration="2:minute")
        p.spin(cont5, acceleration="1000:g", duration="2:minute")
        self.assertEqual(cont1.cover, "ultra-clear")
        self.assertEqual(cont2.cover, "ultra-clear")
        self.assertEqual(cont5.cover, "universal")
        p.uncover(cont5)
        p.unseal(cont1)
        p.transfer(cont4.well(0), cont3.well(0), "1:microliter")
        p.spin(cont4, acceleration="1000:g", duration="2:minute")
        self.assertEqual(cont4.cover, None)
        with self.assertRaises(RuntimeError):
            p.thermocycle(cont4, groups=therm_groups)
        seal_on_store(p)
        self.assertEqual(cont1.cover, "ultra-clear")
        self.assertEqual(cont2.cover, "ultra-clear")
        self.assertEqual(cont3.cover, "standard")
        self.assertEqual(cont4.cover, None)
        self.assertEqual(cont5.cover, None)
예제 #2
0
 def test_seal_type_on_store(self):
     seal_on_store(self.protocol)
     test = self.protocol.ref("test", None, "384-pcr", storage="cold_20")
     self.protocol.seal(test, "foil")
     self.protocol.unseal(test)
     seal_on_store(self.protocol)
     assert (self.protocol.instructions[-1].type == "ultra-clear")
     test2 = self.protocol.ref("test2", None, "384-pcr", storage="cold_20")
     self.protocol.seal(test2, "ultra-clear")
     self.protocol.unseal(test2)
     seal_on_store(self.protocol)
     assert (self.protocol.instructions[-1].type == "ultra-clear")
예제 #3
0
 def test_cover_type_on_store(self):
     seal_on_store(self.protocol)
     test = self.protocol.ref("test", None, "96-flat-uv", storage="cold_20")
     self.protocol.cover(test, "universal")
     self.protocol.uncover(test)
     seal_on_store(self.protocol)
     self.assertTrue(self.protocol.instructions[-1].lid == "standard")
     test2 = self.protocol.ref("test2", None, "96-flat-uv", storage="cold_20")
     self.protocol.cover(test2)
     self.protocol.uncover(test2)
     seal_on_store(self.protocol)
     self.assertTrue(self.protocol.instructions[-1].lid == "standard")
예제 #4
0
 def test_seal_type_on_store(self):
     seal_on_store(self.protocol)
     test = self.protocol.ref("test", None, "384-pcr", storage="cold_20")
     self.protocol.seal(test, "foil")
     self.protocol.unseal(test)
     seal_on_store(self.protocol)
     self.assertTrue(self.protocol.instructions[-1].type == "ultra-clear")
     test2 = self.protocol.ref("test2", None, "384-pcr", storage="cold_20")
     self.protocol.seal(test2, "ultra-clear")
     self.protocol.unseal(test2)
     seal_on_store(self.protocol)
     self.assertTrue(self.protocol.instructions[-1].type == "ultra-clear")
 def test_cover_type_on_store(self):
     seal_on_store(self.protocol)
     test = self.protocol.ref("test", None, "96-flat-uv", storage="cold_20")
     self.protocol.cover(test, "universal")
     self.protocol.uncover(test)
     seal_on_store(self.protocol)
     assert self.protocol.instructions[-1].lid == "low_evaporation"
     test2 = self.protocol.ref("test2", None, "96-flat-uv", storage="cold_20")
     self.protocol.cover(test2)
     self.protocol.uncover(test2)
     seal_on_store(self.protocol)
     assert self.protocol.instructions[-1].lid == "low_evaporation"
예제 #6
0
 def test_seal_on_store(self):
     seal_on_store(self.protocol)
     test = self.protocol.ref("test", None, "96-pcr", storage="cold_20")
     test2 = self.protocol.ref("test2", None, "96-flat", storage="cold_20",
                               cover="standard")
     self.protocol.spin(test, "2000:g", "5:minute")
     self.protocol.spin(test2, "2000:g", "5:minute")
     self.assertEqual(len(self.protocol.instructions), 3)
     self.protocol.uncover(test2)
     seal_on_store(self.protocol)
     self.assertEqual(len(self.protocol.instructions), 5)
     self.assertTrue(self.protocol.instructions[-1].op == "cover")
     self.assertTrue(self.protocol.instructions[-1].lid == "standard")
     self.protocol.uncover(test2)
     seal_on_store(self.protocol)
     self.assertEqual(len(self.protocol.instructions), 7)
     self.assertTrue(self.protocol.instructions[-1].op == "cover")
     self.assertTrue(self.protocol.instructions[-1].lid == "standard")
 def test_seal_on_store(self):
     seal_on_store(self.protocol)
     test = self.protocol.ref("test", None, "96-pcr", storage="cold_20")
     test2 = self.protocol.ref("test2", None, "96-flat", storage="cold_20",
                               cover="standard")
     self.protocol.spin(test, "2000:g", "5:minute")
     self.protocol.spin(test2, "2000:g", "5:minute")
     assert (len(self.protocol.instructions) == 3)
     self.protocol.uncover(test2)
     seal_on_store(self.protocol)
     assert (len(self.protocol.instructions) == 5)
     assert (self.protocol.instructions[-1].op == "cover")
     assert (self.protocol.instructions[-1].lid == "low_evaporation")
     self.protocol.uncover(test2)
     seal_on_store(self.protocol)
     assert (len(self.protocol.instructions) == 7)
     assert (self.protocol.instructions[-1].op == "cover")
     assert (self.protocol.instructions[-1].lid == "low_evaporation")
 def test_seal_on_store(self):
     seal_on_store(self.protocol)
     test = self.protocol.ref("test", None, "96-pcr", storage="cold_20")
     test2 = self.protocol.ref(
         "test2", None, "96-flat", storage="cold_20", cover="standard"
     )
     self.protocol.spin(test, "2000:g", "5:minute")
     self.protocol.spin(test2, "2000:g", "5:minute")
     assert len(self.protocol.instructions) == 3
     self.protocol.uncover(test2)
     seal_on_store(self.protocol)
     assert len(self.protocol.instructions) == 5
     assert self.protocol.instructions[-1].op == "cover"
     assert self.protocol.instructions[-1].lid == "low_evaporation"
     self.protocol.uncover(test2)
     seal_on_store(self.protocol)
     assert len(self.protocol.instructions) == 7
     assert self.protocol.instructions[-1].op == "cover"
     assert self.protocol.instructions[-1].lid == "low_evaporation"
예제 #9
0
def run(
        fn,
        protocol_name=None,
        seal_after_run=True,
        #this is new to allow testing
        config=None):
    """
    Run the protocol specified by the function.

    If protocol_name is passed, use preview parameters from the protocol with
    the matching "name" value in the manifest.json file to run the given
    function.  Otherwise, take configuration JSON file from the command line
    and run the given function.

    Parameters
    ----------
    fn : function
        Function that generates Autoprotocol
    protocol_name :  str, optional
        str matching the "name" value in the manifest.json file
    seal_after_run : bool, optional
        Implicitly add a seal/cover to all stored refs within the protocol
        using seal_on_store()
    """
    #new to allow config
    if not config:
        parser = argparse.ArgumentParser()
        parser.add_argument('config',
                            help='JSON-formatted protocol configuration file')
        args = parser.parse_args()
        #new
        config = args.config

    source = json.loads(io.open(config, encoding='utf-8').read())
    protocol = Protocol()
    if protocol_name:
        manifest_json = io.open('manifest.json', encoding='utf-8').read()
        manifest = Manifest(json.loads(manifest_json))

        # ---- This block is custom to dtx -----

        if not source:
            print(io.open('fake_protocol.json', encoding='utf-8').read())
            return

        # ------End of custom block ------

        params = manifest.protocol_info(protocol_name).parse(protocol, source)
    else:
        params = protocol._ref_containers_and_wells(source["parameters"])

    #----- This block is custom to dtx -----

    protocol.set_test_mode(params.get("test_mode", True))
    #protocol.init_all_refs()

    #----- End of New Block ------

    try:
        fn(protocol, params)
        if seal_after_run:
            seal_on_store(protocol)

        #---- This block is custom to dtx -----

        protocol.assert_valid_state()

        #---- End of New Block -------

    except UserError as e:
        print(
            json.dumps({'errors': [{
                'message': e.message,
                'info': e.info
            }]},
                       indent=2))
        return
    #----- This block is custom to dtx -----
    except:
        e = sys.exc_info()[1]

        additional_information = '\n'+'*'*50+\
            '\n inputs were %s\n'%json.dumps(source,
                                             indent=4)\
            +'*'*50+'\n'
        print(additional_information, file=sys.stderr)
        #aise type(e), e.message, sys.exc_info()[2]
        raise

    #----- End of New Block ------

    print(json.dumps(protocol.as_dict(), indent=2))
    def test_sequence_cover_instructions(self):
        p = Protocol()
        cont1 = p.ref("c1", None, "384-pcr", storage="cold_4")
        cont2 = p.ref("c2", None, "384-pcr", storage="cold_4")
        cont3 = p.ref("c3", None, "96-deep", storage="cold_4")
        cont4 = p.ref("c4", None, "micro-1.5", storage="cold_4")
        cont5 = p.ref("c5", None, "384-echo", discard=True)
        therm_groups = [
            {
                "cycles": 1,
                "steps": [
                    {
                        "temperature": "37:celsius",
                        "duration": "60:minute"
                    },
                ]
            }
        ]
        p.incubate(cont1, "ambient", duration="1:minute")
        assert (p.instructions[0].op == "seal")
        assert (p.instructions[1].op == "incubate")
        assert (cont1.cover == "ultra-clear")

        p.spin(cont1, acceleration="1000:g", duration="2:minute")
        assert (cont1.cover == "ultra-clear")
        assert (cont2.cover is None)

        p.thermocycle(cont2, groups=therm_groups)
        assert (cont2.cover == "ultra-clear")

        p.transfer(cont2.well(0), cont1.well(1), volume="1:microliter")
        assert (cont1.cover is None)
        assert (cont2.cover is None)
        with pytest.raises(RuntimeError):
            p.cover(cont2)

        p.seal(cont2)
        p.thermocycle(cont1, groups=therm_groups)
        assert (cont1.cover == "ultra-clear")

        p.spin(cont1, acceleration="1000:g", duration="2:minute")
        p.spin(cont2, acceleration="1000:g", duration="2:minute")
        p.spin(cont5, acceleration="1000:g", duration="2:minute")
        assert (cont1.cover == "ultra-clear")
        assert (cont2.cover == "ultra-clear")
        assert (cont5.cover == "universal")

        p.uncover(cont5)
        p.unseal(cont1)
        p.transfer(cont4.well(0), cont3.well(0), "1:microliter")
        p.spin(cont4, acceleration="1000:g", duration="2:minute")
        assert (cont4.cover is None)
        with pytest.raises(RuntimeError):
            p.thermocycle(cont4, groups=therm_groups)

        seal_on_store(p)
        assert (cont1.cover == "ultra-clear")
        assert (cont2.cover == "ultra-clear")
        assert (cont3.cover == "standard")
        assert (cont4.cover is None)
        assert (cont5.cover is None)