Пример #1
0
 def test_base_row_column(self):
     self.assertEqual(BioPlateMatrix._base_row_column("A1"), ("1", "A"))
     self.assertEqual(BioPlateMatrix._base_row_column("A[2,5]"),
                      ("[2,5]", "A"))
     self.assertEqual(BioPlateMatrix._base_row_column("1[A-C]"),
                      ("1", "[A-C]"))
     self.assertEqual(BioPlateMatrix._base_row_column("A-B[1-6]"),
                      ("1-6", "A-B"))
Пример #2
0
 def __getitem__(
     self, index: Tuple[Union[int, slice], Union[int, slice], int, str]
 ) -> np.ndarray:
     if isinstance(index, str):
         well = BioPlateMatrix(index)
         return self[well.row, well.column]
     return super(Array, self).__getitem__(index)
Пример #3
0
 def __getitem__(self, index):
     if isinstance(index, tuple):
         if any(isinstance(i, str) for i in index):
             ind = {"top": 0, "bot": 1, "0": 0, "1": 1, 0: 0, 1: 1}
             plt = self[ind[index[0]]]
             if isinstance(index[1], str):
                 well = BioPlateMatrix(index[1])
                 return plt[well.row, well.column]
     return super(Inserts, self).__getitem__(index)
Пример #4
0
 def __setitem__(self, index, value):
     if isinstance(index, tuple):
         if any(isinstance(i, str) for i in index):
             ind = {"top": 0, "bot": 1, 0: 0, 1: 1}
             plt = self[ind[index[0]]]
             if isinstance(index[1], str):
                 well = BioPlateMatrix(index[1])
                 plt[index[1]] = value
                 return
     super(Inserts, self).__setitem__(index, value)
Пример #5
0
    def test_general(self):
        self.assertEqual(BioPlateMatrix("A2"), bpu.EL("W", 1, 2))
        self.assertEqual(BioPlateMatrix("5G"), bpu.EL("W", 7, 5))

        self.assertEqual(BioPlateMatrix("B[2,8]"),
                         bpu.EL("R", 2, slice(2, 9, 1)))
        self.assertEqual(BioPlateMatrix("2[B-G]"),
                         bpu.EL("C", slice(2, 8, 1), 2))

        self.assertEqual(BioPlateMatrix("A-G[1-8]"),
                         bpu.EL("R", slice(1, 8, 1), slice(1, 9, 1)))
        self.assertEqual(BioPlateMatrix("1-8[A-G]"),
                         bpu.EL("C", slice(1, 8, 1), slice(1, 9, 1)))

        self.assertEqual(BioPlateMatrix("C"), bpu.EL("R", 3, slice(1, None)))
        self.assertEqual(BioPlateMatrix("12"), bpu.EL("C", slice(1, None), 12))
Пример #6
0
 def test_index_row_column(self):
     self.assertEqual(BioPlateMatrix._index_row_column("A", "1"),
                      bpu.EL("W", 1, 1))
     self.assertEqual(BioPlateMatrix._index_row_column("D", "10"),
                      bpu.EL("W", 4, 10))
     self.assertEqual(
         BioPlateMatrix._index_row_column("D-G", "10"),
         bpu.EL("C", slice(4, 8, 1), 10),
     )
     self.assertEqual(
         BioPlateMatrix._index_row_column("G-I", "5-8"),
         bpu.EL("R", slice(7, 10, 1), slice(5, 9, 1)),
     )
     self.assertEqual(BioPlateMatrix._index_row_column("G", "5-8"),
                      bpu.EL("R", 7, slice(5, 9, 1)))
     self.assertEqual(BioPlateMatrix._index_row_column("B-E", "5"),
                      bpu.EL("C", slice(2, 6, 1), 5))
Пример #7
0
 def __setitem__(
     self,
     index: Tuple[Union[int, slice], Union[int, slice]],
     value: Union[List[int], List[str], int, str],
 ) -> None:
     if isinstance(index, str):
         well = BioPlateMatrix(index)
         if isinstance(value, list):
             plate_shape = self[well.row, well.column].shape
             len_plate_shape = len(plate_shape)
             if len_plate_shape > 1:
                 if well.pos == "R":
                     resh_val = np.reshape(value, (plate_shape[0], 1))
                 else:
                     resh_val = value
                 self[well.row, well.column] = resh_val
                 return
             else:
                 self[well.row, well.column][: len(value)] = value
                 return
         else:
             self[well.row, well.column] = value
             return
     super(Array, self).__setitem__(index, value)
Пример #8
0
 def test_all_row_column(self):
     self.assertEqual(BioPlateMatrix._all_row_column("A"),
                      bpu.EL("R", 1, slice(1, None)))
     self.assertEqual(BioPlateMatrix._all_row_column(3),
                      bpu.EL("C", slice(1, None), 3))
Пример #9
0
 def test_well_letter_index(self):
     self.assertEqual(BioPlateMatrix._well_letter_index("A"), 1)
     self.assertEqual(BioPlateMatrix._well_letter_index("G"), 7)
Пример #10
0
 def test_multi_row_column(self):
     self.assertEqual(BioPlateMatrix._multi_row_column("A-B"), ("A", "B"))
     self.assertEqual(BioPlateMatrix._multi_row_column("C,G"), ("C", "G"))
     self.assertEqual(BioPlateMatrix._multi_row_column("U,D"), ("D", "U"))
Пример #11
0
 def test__test_row_or_column(self):
     self.assertTrue(BioPlateMatrix._test_row_or_column("A"))
     self.assertTrue(BioPlateMatrix._test_row_or_column("12"))
     self.assertTrue(BioPlateMatrix._test_row_or_column(10))
Пример #12
0
    def set(self, *args, merge=False):
        """Main entry point to assign value on plate 
           
        Parameters 
        ----------
          well : dict or str
              - if dict, well must contain well identifier as key and value to assign as value.eg : {"A2" : "value", "A[3-6]" : 42} 
              - if string, well is only a well identifier eg : "G5" 

         value : list or str or int or float 
             - if list, value should be presented with multiple well identifer "B-D[2-5]", ["value1", "value2", "value3"]

        merge : bool (by default False) 
            Value on well are not overide but added
        Returns
        -------
         BioPlate : BioPlate
             return instance of plate

         Exemples
         --------    
         see :ref:`Set-values-on-plate`
                 
        """
        well, value = self._args_analyse(*args)
        if not isinstance(well, str) and isinstance(well, Iterable):
            generator = well.items() if isinstance(well, dict) else well
            for key, val in generator:
                if merge:
                    self.set(key, val, merge=True)
                else:
                    self.set(key, val)
            return self
        well = BioPlateMatrix(str(well))
        if isinstance(value, list):
            plate_shape = self[well.row, well.column].shape
            len_plate_shape = len(plate_shape)
            if len_plate_shape > 1:
                if well.pos == "R":
                    resh_val = np.reshape(value, (plate_shape[0], 1))
                else:
                    resh_val = value
                if merge:
                    self[well.row,
                         well.column] = ncd.add(self[well.row, well.column],
                                                resh_val)
                    return self
                self[well.row, well.column] = resh_val
                return self
            else:
                if merge:
                    self[well.row, well.column][:len(value)] = ncd.add(
                        self[well.row, well.column][:len(value)], value)
                    return self
                self[well.row, well.column][:len(value)] = value
                return self
        if merge:
            self[well.row, well.column] = ncd.add(self[well.row, well.column],
                                                  value)
            return self
        self[well.row, well.column] = value
        return self