Exemple #1
0
    def draw(self):
        hierarchy = self.hierarchy.rescale()

        self_data = np.array([(c.res1, c.res1_seq, c.res2, c.res2_seq,
                               c.raw_score, c.status) for c in hierarchy])
        _drange = np.append(self_data[:, 1], self_data[:, 3]).astype(np.int64)
        self_data_range = np.arange(_drange.min(), _drange.max() + 1)

        npoints = self_data_range.shape[0]
        coords = np.array(get_points_on_circle(npoints))

        bezier_path = np.arange(0, 1.01, 0.01)
        for c in self_data:
            x1, y1 = coords[int(c[1]) - self_data_range.min()]
            x2, y2 = coords[int(c[3]) - self_data_range.min()]
            xb, yb = [0, 0]
            x = (1 - bezier_path)**2 * x1 + 2 * (
                1 - bezier_path) * bezier_path * xb + bezier_path**2 * x2
            y = (1 - bezier_path)**2 * y1 + 2 * (
                1 - bezier_path) * bezier_path * yb + bezier_path**2 * y2
            alpha = float(c[4]) if self.use_conf else 1.0
            color = {
                ContactMatchState.false_positive: ColorDefinitions.MISMATCH,
                ContactMatchState.true_positive: ColorDefinitions.MATCH,
            }.get(int(c[5]), ColorDefinitions.MATCH)
            self.ax.plot(x,
                         y,
                         color=color,
                         alpha=alpha,
                         linestyle="-",
                         zorder=0)
            if int(c[5]) == ContactMatchState.true_positive:
                self.ax.plot(x,
                             y,
                             color=color,
                             alpha=alpha,
                             linestyle="-",
                             zorder=1,
                             linewidth=1)
            else:
                self.ax.plot(x,
                             y,
                             color=color,
                             alpha=alpha,
                             linestyle="-",
                             zorder=0,
                             linewidth=1)

        residue_data = np.append(self_data[:, [1, 0]], self_data[:, [3, 2]])
        residue_data = residue_data.reshape(self_data[:, 0].shape[0] * 2, 2)
        color_codes = dict([(k, ColorDefinitions.AA_ENCODING["X"])
                            for k in self_data_range])
        for k, v in np.vstack([tuple(row) for row in residue_data]):
            color_codes[int(k)] = ColorDefinitions.AA_ENCODING[v]
        colors = [color_codes[k] for k in sorted(color_codes.keys())]

        # TODO: Use tools module to process this
        x, _ = zip(*residue_data)
        label_data = set(map(int, x))
        label_coords = np.zeros((npoints, 2))
        space = 2 * np.pi / npoints
        for i in np.arange(npoints):
            label_coords[i] = [
                (npoints + npoints / 10) * np.cos(space * i) - npoints / 20,
                (npoints + npoints / 10) * np.sin(space * i) - npoints / 40,
            ]

        xy_highlight = []
        for r in sorted(label_data)[::int(npoints / (npoints / 10))]:
            i = r - self_data_range.min()
            xy = coords[i]
            xytext = label_coords[i]
            self.ax.annotate(r, xy=xy, xytext=xytext)
            xy_highlight.append(xy.tolist())

        radius = get_radius_around_circle(coords[0], coords[1])
        self._patch_scatter(coords[:, 0],
                            coords[:, 1],
                            symbol="o",
                            facecolor=colors,
                            linewidth=0.0,
                            radius=radius)
        self._patch_scatter(*zip(*xy_highlight),
                            symbol="o",
                            facecolor="none",
                            edgecolor="#000000",
                            radius=radius)

        arrow_x, arrow_y = (npoints + npoints / 5, 0)
        self.ax.arrow(arrow_x,
                      arrow_y,
                      0,
                      npoints / 10,
                      head_width=1.5,
                      color="#000000")

        self.ax.set_xlim(-arrow_x, arrow_x + 2)
        self.ax.set_ylim(-arrow_x, arrow_x)
        self.ax.axis("off")

        # TODO: deprecate this in 0.14
        if self._file_name:
            self.savefig(self._file_name, dpi=self._dpi)
Exemple #2
0
 def test_get_points_on_circle_6(self):
     coords = tools.get_points_on_circle(4, h=2)
     self.assertEqual([6.0, 0.0], coords[0])
     self.assertEqual([2.0, 4.0], coords[1])
     self.assertEqual([-2.0, 0.0], coords[2])
     self.assertEqual([2, -4], coords[3])
Exemple #3
0
 def test_get_points_on_circle_7(self):
     coords = tools.get_points_on_circle(4, k=-3)
     self.assertEqual([4.0, -3.0], coords[0])
     self.assertEqual([0.0, 1.0], coords[1])
     self.assertEqual([-4.0, -3.0], coords[2])
     self.assertEqual([0, -7], coords[3])
Exemple #4
0
 def test_get_points_on_circle_5(self):
     coords = tools.get_points_on_circle(4)
     self.assertEqual([4.0, 0.0], coords[0])
     self.assertEqual([0.0, 4.0], coords[1])
     self.assertEqual([-4.0, 0.0], coords[2])
     self.assertEqual([0, -4], coords[3])
Exemple #5
0
 def test_get_points_on_circle_4(self):
     coords = tools.get_points_on_circle(3)
     self.assertEqual([3.0, 0.0], coords[0])
     self.assertEqual([-1.5, 2.598076], coords[1])
     self.assertEqual([-1.5, -2.598076], coords[2])
Exemple #6
0
 def test_get_points_on_circle_3(self):
     coords = tools.get_points_on_circle(2)
     self.assertEqual([2.0, 0.0], coords[0])
     self.assertEqual([-2.0, 0], coords[1])
Exemple #7
0
 def test_get_points_on_circle_2(self):
     coords = tools.get_points_on_circle(1)
     self.assertEqual([[1.0, 0.0]], coords)
Exemple #8
0
 def test_get_points_on_circle_1(self):
     coords = tools.get_points_on_circle(0)
     self.assertEqual([[]], coords)