Esempio n. 1
0
    def test_to_labcyte(self):
        """Create a labcyte picklist."""

        src = Well()
        dest = Well()
        instruction = Instruction(transfers=[Transfer(src, dest, volume=5.0)])
        picklist = to_labcyte(instruction, 0)
        lines = picklist.split("\n")

        self.assertIn("Source Plate Barcode", lines[0])
        self.assertIn("Source Well", lines[0])
        self.assertIn("Destination Plate Barcode", lines[0])
        self.assertIn("Destination Well", lines[0])
        self.assertEqual("Plate:1,A1,Plate:2,A1,5000.0", lines[1])

        # max is 10 uL, so a 20 uL needs to be split in half
        instruction = Instruction(transfers=[Transfer(src, dest, volume=20.0)])
        picklist = to_labcyte(instruction, 0)
        lines = picklist.split("\n")

        self.assertEqual(3, len(lines))  # one transfer split into two
        self.assertEqual("Plate:1,A1,Plate:2,A1,10000.0", lines[1])
        self.assertEqual("Plate:1,A1,Plate:2,A1,10000.0", lines[2])

        with self.assertRaises(ValueError):
            to_labcyte(Instruction(),
                       0)  # needs to have transfers to use in picklist
Esempio n. 2
0
    def test_setup(self):
        """Create a setup plate with multiple wells."""

        # the water here requires 300.0 uL
        # this exceeds the max for a well
        d1 = SeqRecord(Seq("AGATAGACCAGAAGATAGA", unambiguous_dna), id="r1")
        r1 = Reagent("water")

        w1 = Well([d1, r1], [50.0, 100.0])
        w2 = Well([d1, r1], [50.0, 100.0])

        target = [w1, w2]

        protocol = Protocol("", Plasmid())

        protocol = Setup(target)(protocol)

        setup_wells = protocol.containers

        self.assertEqual(3, len(setup_wells))

        water_wells = [w for w in setup_wells if r1 in w]
        self.assertEqual(2, len(water_wells))

        dna_wells = [w for w in setup_wells if d1 in w]
        self.assertEqual(1, len(dna_wells))

        self.assertTrue(all(w.volumes and w.volumes[0] for w in setup_wells))
Esempio n. 3
0
    def test_inputs(self):
        """Get a name,value map for protocol inputs."""

        protocol = Protocol("input test", Plasmid([]))
        protocol.instructions.append(
            Instruction(transfers=[
                Transfer(
                    src=Fridge(Reagent("e coli")), dest=Well(), volume=30.0)
            ]))
        protocol.instructions.append(
            Instruction(transfers=[
                Transfer(
                    src=Fridge(
                        SeqRecord(
                            Seq("GGGGGGAGAGAAACCCACAATAT", unambiguous_dna),
                            id="mock_part",
                        )),
                    dest=Well(),
                    volume=50.0,
                )
            ]))

        inputs = protocol.input
        self.assertIn("mock_part", inputs.keys())
        self.assertIn("e coli", inputs.keys())
Esempio n. 4
0
    def test_lt(self):
        """Compare two containers to see which should come first."""

        c1 = Well([Reagent("water")])
        c2 = Well([SeqRecord(Seq("ATGATAGAT"))])
        c3 = Well([Reagent("assembly-mix")])

        self.assertLess(c2, c1)
        self.assertLess(c3, c1)
Esempio n. 5
0
    def test_transfer_split(self):
        """Splitup a transfer based on max-volume."""

        transfer = Transfer(src=Well(), dest=Well(), volume=1000)  # millileter

        max_volume = 50.0
        split = transfer.split(max_volume, 1.0)
        self.assertEqual(20, len(split))
        self.assertTrue(all(t.volume and t.volume <= max_volume
                            for t in split))
Esempio n. 6
0
    def test_to_tecan(self):
        """Create a Tecan picklist."""

        src = Well()
        dest = Well()
        instruction = Instruction(transfers=[Transfer(src, dest, volume=5.0)])
        picklist = to_tecan(instruction, 0)
        lines = picklist.split("\n")

        self.assertEqual(3, len(lines))
        self.assertEqual("A;Plate:1;;;1;;5.0;;;", lines[0])
        self.assertEqual("D;Plate:2;;;1;;5.0;;;", lines[1])
        self.assertEqual("W;;;;;;;;;", lines[2])

        with self.assertRaises(ValueError):
            to_tecan(Instruction(),
                     0)  # needs to have transfers to use in picklist
Esempio n. 7
0
    def setUp(self):
        """Instantiate a test Protocol with SeqRecords in containers."""

        self.r1 = SeqRecord(Seq("AGATAGACCAGAAGATAGA", unambiguous_dna),
                            id="r1")
        self.r2 = SeqRecord(Seq("GGGGGGAGAGAAACCCACAATAT", unambiguous_dna),
                            id="r2")
        self.r3 = SeqRecord(Seq("TTTTGAGAGAGATTTAGAGATA", unambiguous_dna),
                            id="r3")
        self.r4 = SeqRecord(Seq("GAGATAGATAGACCAGATAGA", unambiguous_dna),
                            id="r4")

        self.protocol = Protocol("", Combinatorial())

        self.protocol.containers = [
            Well([self.r1, self.r2], volumes=[50.0, 50.0]),
            Well([self.r3, self.r4], volumes=[50.0, 50.0]),
        ]
Esempio n. 8
0
    def test_layout(self):
        """Layout creation and serialization to CSV format."""

        plate_contents = [
            Well(SeqRecord(Seq("ATGATAGAT"))) for i in range(140)
        ]
        plates = Layout(plate_contents)

        plate_csv = plates.to_csv()

        self.assertIn("Plate:1", plate_csv)
        self.assertIn(",,Plate:2", plate_csv)
        self.assertIn("B,", plate_csv)  # row label
        self.assertIn(",".join([str(n) for n in range(1, 13)]),
                      plate_csv)  # col labels
        self.assertGreaterEqual(len(plate_csv.split("\n")), 9)

        # test plates name, well index (within plates) and well name (within plates)
        self.assertEqual("Plate:1",
                         plates.container_to_plate_name[plate_contents[1]])
        self.assertEqual("Plate:1",
                         plates.container_to_plate_name[plate_contents[95]])
        self.assertEqual("Plate:2",
                         plates.container_to_plate_name[plate_contents[96]])

        self.assertEqual("Plate:2",
                         plates.container_to_plate_name[plate_contents[105]])
        self.assertEqual(2, plates.container_to_well_index[plate_contents[1]])
        self.assertEqual("B1",
                         plates.container_to_well_name[plate_contents[1]])
        self.assertEqual(2, len(plates))  # two plates

        # STILL just two plates, no reagents in contents
        plates = Layout(plate_contents, separate_reagents=True)
        self.assertEqual(2, len(plates))

        # Three plates, reagents are in a separate plate
        plate_reagent_contents = plate_contents + [
            Well(Reagent("water")),
            Well(Reagent("mix")),
        ]
        plates = Layout(plate_reagent_contents, separate_reagents=True)
        self.assertEqual(3, len(plates))
Esempio n. 9
0
    def test_pipette(self):
        """Test Pipette step to move SeqRecords into new wells."""
        def contents(
                containers):  # get lists of ids (SeqRecords not comparable)
            return [c.id for container in containers for c in container]

        target = [
            Well([self.r1, self.r3], volumes=[20.0, 20.0]),
            Well([self.r2, self.r4], volumes=[20.0, 20.0]),
        ]

        pipette_step = Pipette(target=target)

        self.assertNotEqual(contents(self.protocol.containers),
                            contents(target))

        pipette_step(self.protocol)

        self.assertEqual(contents(self.protocol.containers), contents(target))
Esempio n. 10
0
    def test_init_err(self):
        """Throw an error if init arguments are invalid."""

        self.assertEqual(
            Well(
                contents=[
                    Reagent("water"),
                    Reagent("water"),
                    Reagent("water")
                ],
                volumes=[2.0, 2.0, 0.0],
            ).volumes,
            [2.0, 2.0, 0.0],
        )
Esempio n. 11
0
    def test_withdraw(self):
        """Withdraw from a well, know when 'empty'"""

        c1 = Well([Reagent("e coli"), Reagent("water")], [50.0, 30.0])
        c1.volume_max = 100.0

        self.assertFalse(c1.empty())
        self.assertEqual(80.0, c1.volume())

        c1.withdraw(20.0)

        self.assertFalse(c1.empty())

        self.assertEqual(80.0, c1.volume())  # didn't change
        self.assertEqual(20.0, c1.withdrawn)
        self.assertTrue(c1.empty(70.0))  # there isn't 70 uL left

        with self.assertRaises(RuntimeError):
            c1.withdraw(100.0)
Esempio n. 12
0
    def test_hash(self):
        """Hash containers."""

        well_set = {Well(), Well()}
        self.assertEqual(2, len(well_set))