Exemplo n.º 1
0
 def test_heatmap_wrong_x_shape(self):
     with pytest.raises(ValueError) as excinfo:
         eda.heatmap(np.random.ranf(1),
                     col_labels=[0],
                     title='test heatmap',
                     xlab='col label',
                     ylab='row label',
                     figsize=(10, 10))
     with pytest.raises(ValueError) as excinfo:
         eda.heatmap(np.random.ranf(1),
                     title='test heatmap',
                     xlab='col label',
                     ylab='row label',
                     figsize=(10, 10))
Exemplo n.º 2
0
    def test_heatmap_wrong_col_lab_len(self):
        with pytest.raises(ValueError) as excinfo:
            eda.heatmap(self.x_10x5, ['cc'] * 1 + ['bb'] * 3 + ['aa'] * 6,
                        ['a'] * 3 + ['b'] * 1,
                        title='test heatmap',
                        xlab='col label',
                        ylab='row label',
                        figsize=(10, 10))

        with pytest.raises(ValueError) as excinfo:
            eda.heatmap(self.x_10x5, ['cc'] * 1 + ['bb'] * 3 + ['aa'] * 6,
                        ['a'] * 5 + ['b'] * 1,
                        title='test heatmap',
                        xlab='col label',
                        ylab='row label',
                        figsize=(10, 10))
Exemplo n.º 3
0
 def test_heatmap_nolabs(self):
     fig = eda.heatmap(self.x_10x5,
                       title='test heatmap',
                       xlab='col label',
                       ylab='row label',
                       figsize=(10, 10))
     return fig
Exemplo n.º 4
0
 def test_heatmap_clabs(self):
     fig = eda.heatmap(self.x_10x5,
                       col_labels=['a'] * 3 + ['b'] * 2,
                       title='test heatmap',
                       xlab='col label',
                       ylab='row label',
                       figsize=(10, 10))
     return fig
Exemplo n.º 5
0
 def test_heatmap_str_crlabs(self):
     fig = eda.heatmap(self.x_10x5, ['cc'] * 1 + ['bb'] * 3 + ['aa'] * 6,
                       ['a'] * 3 + ['b'] * 2,
                       title='test heatmap',
                       xlab='col label',
                       ylab='row label',
                       figsize=(10, 10))
     return fig
Exemplo n.º 6
0
 def test_heatmap_rlabs(self):
     fig = eda.heatmap(self.x_10x5,
                       row_labels=[0] * 1 + [1] * 3 + [2] * 6,
                       title='test heatmap',
                       xlab='col label',
                       ylab='row label',
                       figsize=(10, 10))
     return fig
Exemplo n.º 7
0
 def test_heatmap_crlabs(self):
     fig = eda.heatmap(self.x_10x5, [2] * 1 + [1] * 3 + [5] * 6,
                       [0] + [1] * 2 + [2] + [3],
                       title='test heatmap',
                       xlab='col label',
                       ylab='row label',
                       figsize=(10, 10))
     return fig
Exemplo n.º 8
0
 def test_heatmap_bilinear_interpolation(self):
     fig = eda.heatmap(self.x_10x5, [2] * 1 + [1] * 3 + [5] * 6,
                       [0] * 3 + [1] * 2,
                       title='test heatmap',
                       xlab='col label',
                       ylab='row label',
                       interpolation='bilinear',
                       figsize=(10, 10))
     return fig
Exemplo n.º 9
0
 def test_heatmap_cmap(self):
     fig = eda.heatmap(self.x_10x5, [2] * 1 + [1] * 3 + [5] * 6,
                       [0] * 3 + [1] * 2,
                       title='test heatmap',
                       xlab='col label',
                       ylab='row label',
                       cmap='viridis',
                       figsize=(10, 10))
     return fig
Exemplo n.º 10
0
 def test_heatmap_crlabs_cl_ord(self):
     fig = eda.heatmap(self.x_10x5, [2] * 1 + [1] * 3 + [5] * 6,
                       [0] + [1] * 2 + [2] + [3],
                       title='test heatmap',
                       xlab='col label',
                       ylab='row label',
                       figsize=(10, 10),
                       col_label_order=[2, 1, 3, 0])
     return fig
Exemplo n.º 11
0
 def test_heatmap_crlabs_shuffle_colc(self):
     fig = eda.heatmap(self.x_10x5, [2] * 1 + [1] * 3 + [5] * 6,
                       [0] + [1] * 2 + [2] + [3],
                       title='test heatmap',
                       xlab='col label',
                       ylab='row label',
                       figsize=(10, 10),
                       shuffle_col_colors=True,
                       random_state=17)
     return fig
Exemplo n.º 12
0
 def dmat_heatmap(self,
                  selected_labels=None,
                  col_labels=None,
                  transform=None,
                  title=None,
                  xlab=None,
                  ylab=None,
                  figsize=(10, 10),
                  **kwargs):
     # hierarchical clustering tree leaf sample inds ordered from
     # left to right
     leaf_order = self._hac_tree.leaf_ids()
     if len(leaf_order) == 0:
         return None
     # leaf labels from left to right
     leaf_ordered_labs = np.array(self._labs)[leaf_order].tolist()
     # check labels not interrupted in leaf order
     # in other word, same labels should be adjacent to each other
     # Examples:
     # - good: [1] and [1, 1, 2, 2, 3]
     # - bad: [1, 2, 1, 1, 3, 3]
     curr_lab = leaf_ordered_labs[0]
     lab_set = set([curr_lab])
     for ilab in leaf_ordered_labs:
         if ilab != curr_lab:
             # reached the next group of labels
             if ilab in lab_set:
                 raise ValueError("Same labels should be grouped "
                                  "together.\n\t"
                                  "iterating lab: {}\n\t"
                                  "iterated lab set: {}\n\t"
                                  "leaf order: {}\n\t"
                                  "leaf ordered labs: {}".format(
                                      ilab, lab_set, leaf_order,
                                      leaf_ordered_labs))
             lab_set.add(ilab)
             curr_lab = ilab
     # generate heatmap
     # select labels to plot
     s_lab_bool_inds = SLCS.select_labs_bool_inds(leaf_ordered_labs,
                                                  selected_labels)
     s_leaf_order = list(itertools.compress(leaf_order, s_lab_bool_inds))
     s_leaf_ordered_labs = list(
         itertools.compress(leaf_ordered_labs, s_lab_bool_inds))
     s_d = self._sdm._d[s_leaf_order][:, s_leaf_order]
     return eda.heatmap(s_d,
                        row_labels=s_leaf_ordered_labs,
                        col_labels=col_labels,
                        transform=transform,
                        title=title,
                        xlab=xlab,
                        ylab=ylab,
                        figsize=figsize,
                        **kwargs)
Exemplo n.º 13
0
    def test_heatmap_transform(self):
        # not callable transform
        with pytest.raises(ValueError) as excinfo:
            eda.heatmap(self.x_10x5, [2] * 1 + [1] * 3 + [5] * 6,
                        [0] * 3 + [1] * 2,
                        title='test heatmap',
                        xlab='col label',
                        ylab='row label',
                        transform=1,
                        figsize=(10, 10))

        with pytest.raises(ValueError) as excinfo:
            eda.heatmap(self.x_10x5, [2] * 1 + [1] * 3 + [5] * 6,
                        [0] * 3 + [1] * 2,
                        title='test heatmap',
                        xlab='col label',
                        ylab='row label',
                        transform=[],
                        figsize=(10, 10))

        with pytest.raises(ValueError) as excinfo:
            eda.heatmap(self.x_10x5, [2] * 1 + [1] * 3 + [5] * 6,
                        [0] * 3 + [1] * 2,
                        title='test heatmap',
                        xlab='col label',
                        ylab='row label',
                        transform=self.x_10x5,
                        figsize=(10, 10))

        fig = eda.heatmap(np.arange(50).reshape(10, 5),
                          [2] * 1 + [1] * 3 + [5] * 6, [0] * 3 + [1] * 2,
                          title='test heatmap',
                          xlab='col label',
                          ylab='row label',
                          transform=lambda x: x + 100,
                          figsize=(10, 10))
        return fig
Exemplo n.º 14
0
 def test_heatmap_empty_x(self):
     with pytest.raises(ValueError) as excinfo:
         eda.heatmap([[]],
                     col_labels=[],
                     title='test heatmap',
                     xlab='col label',
                     ylab='row label',
                     figsize=(10, 10))
     with pytest.raises(ValueError) as excinfo:
         eda.heatmap([[]],
                     col_labels=[],
                     title='test heatmap',
                     xlab='col label',
                     ylab='row label',
                     figsize=(10, 10))
     with pytest.raises(ValueError) as excinfo:
         eda.heatmap([[]],
                     row_labels=[],
                     col_labels=[],
                     title='test heatmap',
                     xlab='col label',
                     ylab='row label',
                     figsize=(10, 10))
Exemplo n.º 15
0
 def test_heatmap_no_xylab_title(self):
     fig = eda.heatmap(self.x_10x5, [2] * 1 + [1] * 3 + [5] * 6,
                       [0] * 3 + [1] * 2,
                       figsize=(10, 10))
     return fig