Пример #1
0
 def test_rasterize_2d_coordinates_single_point_with_origin(self):
     a = np.array([[109.99, 0.]])
     b = np.array([[0., 109.99]])
     a_rast = fpp.rasterized_2d_coordinates(a, 10, np.array([-0.5, -25]))
     b_rast = fpp.rasterized_2d_coordinates(b, 10, np.array([-0.5, -25]))
     nptest.assert_array_equal(a_rast, np.array([[11, 2]]))
     nptest.assert_array_equal(b_rast, np.array([[0, 13]]))
Пример #2
0
 def test_rasterize_2d_coordinates_single_point_with_origin(self):
     a = np.array([[109.99, 0.]])
     b = np.array([[0., 109.99]])
     a_rast = fpp.rasterized_2d_coordinates(a, 10, np.array([-0.5, -25]))
     b_rast = fpp.rasterized_2d_coordinates(b, 10, np.array([-0.5, -25]))
     nptest.assert_array_equal(a_rast, np.array([[11, 2]]))
     nptest.assert_array_equal(b_rast, np.array([[0, 13]]))
Пример #3
0
 def test_rasterize_2d_coordinates_many_points_with_origin(self):
     a = np.array([[100., 0.], [109.99, 0.], [110., 0.], [0., 100.],
                   [0., 109.99], [0., 110.]])
     a_rast = fpp.rasterized_2d_coordinates(a, 10, np.array([-0.5, -25]))
     nptest.assert_array_equal(
         a_rast,
         np.array([[10, 2], [11, 2], [11, 2], [0, 12], [0, 13], [0, 13]]))
Пример #4
0
 def test_rasterize_2d_coordinates_many_points(self):
     a = np.array([[100., 0.], [109.99, 0.], [110., 0.], [0., 100.],
                   [0., 109.99], [0., 110.]])
     a_rast = fpp.rasterized_2d_coordinates(a, 10)
     nptest.assert_array_equal(
         a_rast,
         np.array([[10, 0], [10, 0], [11, 0], [0, 10], [0, 10], [0, 11]]))
Пример #5
0
 def test_rasterize_2d_coordinates_many_points_with_rotation2(self):
     a = np.array([[100., 0.], [109.99, 0.], [110., 0.],
                   [0., 100.], [0., 109.99], [0., 110.]])
     a_rast = fpp.rasterized_2d_coordinates(a, 10, rotate=-90)
     print(a_rast)
     nptest.assert_array_equal(a_rast, np.array(
         [[0, 10], [0, 10], [0, 11], [-10, 0], [-11, 0], [-11, 0]]))
Пример #6
0
 def test_rasterize_2d_coordinates_many_points_with_rotation_and_origin(self):
     a = np.array([[100., 0.], [109.99, 0.], [110., 0.],
                   [0., 100.], [0., 109.99], [0., 110.]])
     a_rast = fpp.rasterized_2d_coordinates(
         a, 10, np.array([-0.5, -25]), rotate=-90)
     print(a_rast)
     nptest.assert_array_equal(a_rast, np.array(
         [[0, 12], [0, 13], [0, 13], [-10, 2], [-11, 2], [-11, 2]]))
Пример #7
0
    def update(self, _=None):
        width = self.width.get()
        rest = width % 10
        if rest < 5:
            self.width.set(width - rest)
        else:
            self.width.set(width - rest + 10)
        proj = self.proj
        # Offset
        box = self.getBox()
        # Rasterize the image
        if self.showVres.get():
            img, _ = proj.rasterize(self.dpi.get(),
                                    box,
                                    virtual_atoms=True,
                                    rotate=self.inplane_rot.get(),
                                    warn=False)
        else:
            img, _ = proj.rasterize(self.dpi.get(),
                                    box,
                                    virtual_atoms=True,
                                    rotate=self.inplane_rot.get(),
                                    virtual_residues=False,
                                    warn=False)
            img = fpp.to_rgb(img)
        pilImg = Image.fromarray(img)
        pilImg = pilImg.convert("RGB")
        # Show stems
        if self.showStems.get():
            stemres = []
            for s in self.cg.defines.keys():
                if s[0] != "s":
                    continue
                for pos in self.cg.define_residue_num_iterator(s):
                    stemres.append(proj.get_vres_by_position(pos))
            stemres = np.array(stemres)
            rast = fpp.rasterized_2d_coordinates(
                stemres,
                self.width.get() / self.dpi.get(),
                origin=np.array([box[0], box[2]]),
                rotate=self.inplane_rot.get())
            for x, y in rast:
                if 0 <= x < self.dpi.get() and 0 <= y < self.dpi.get():
                    pilImg.putpixel((int(y), int(x)), (100, 255, 0))
        # Selected Nucleotide
        x, y = self.getSelected()
        if 0 <= x < self.dpi.get() and 0 <= y < self.dpi.get():
            pilImg.putpixel((int(y), int(x)), (255, 0, 0))

        # Zoom
        zoom = int(self.zoom.get())
        newsize = (self.dpi.get() * int(zoom), self.dpi.get() * int(zoom))
        pilImg = pilImg.resize(newsize, Image.NEAREST)
        # Show
        tkImg = ImageTk.PhotoImage(pilImg)
        self.imgDisplay.configure(image=tkImg)
        self.image = tkImg  # Keep a reference!
        self.pilImage = pilImg  # For saving
Пример #8
0
 def getSelected(self):
     box = self.getBox()
     selected = int(self.nucleotidePosition.get())
     nucPos = self.proj.get_vres_by_position(selected)
     x, y = fpp.rasterized_2d_coordinates(np.array([[nucPos[0], nucPos[1]]]),
                                          self.width.get() / self.dpi.get(),
                                          origin=np.array([box[0], box[2]]),
                                          rotate=self.inplane_rot.get())[0]
     return x, y
Пример #9
0
 def test_rasterize_2d_coordinates_many_points_with_rotation2(self):
     a = np.array([[100., 0.], [109.99, 0.], [110., 0.], [0., 100.],
                   [0., 109.99], [0., 110.]])
     a_rast = fpp.rasterized_2d_coordinates(a, 10, rotate=-90)
     print(a_rast)
     nptest.assert_array_equal(
         a_rast,
         np.array([[0, 10], [0, 10], [0, 11], [-10, 0], [-11, 0], [-11,
                                                                   0]]))
Пример #10
0
 def getSelected(self):
     box = self.getBox()
     selected = int(self.nucleotidePosition.get())
     nucPos = self.proj.get_vres_by_position(selected)
     x, y = fpp.rasterized_2d_coordinates(np.array([[nucPos[0],nucPos[1]]]), 
                                          self.width.get()/self.dpi.get(), 
                                          origin = np.array([box[0],box[2]]), 
                                          rotate = self.inplane_rot.get())[0]
     return x,y
Пример #11
0
    def update(self, _=None):
        width = self.width.get()
        rest = width % 10
        if rest < 5:
            self.width.set(width - rest)
        else:
            self.width.set(width - rest + 10)
        proj = self.proj
        # Offset
        box = self.getBox()
        # Rasterize the image
        if self.showVres.get():
            img, _ = proj.rasterize(self.dpi.get(), box, virtual_atoms=True,
                                    rotate=self.inplane_rot.get(), warn=False)
        else:
            img, _ = proj.rasterize(self.dpi.get(), box, virtual_atoms=True,
                                    rotate=self.inplane_rot.get(),
                                    virtual_residues=False, warn=False)
            img = fpp.to_rgb(img)
        pilImg = Image.fromarray(img)
        pilImg = pilImg.convert("RGB")
        # Show stems
        if self.showStems.get():
            stemres = []
            for s in self.cg.defines.keys():
                if s[0] != "s":
                    continue
                for pos in self.cg.define_residue_num_iterator(s):
                    stemres.append(proj.get_vres_by_position(pos))
            stemres = np.array(stemres)
            rast = fpp.rasterized_2d_coordinates(stemres, self.width.get() / self.dpi.get(),
                                                 origin=np.array(
                                                     [box[0], box[2]]),
                                                 rotate=self.inplane_rot.get())
            for x, y in rast:
                if 0 <= x < self.dpi.get() and 0 <= y < self.dpi.get():
                    pilImg.putpixel((int(y), int(x)), (100, 255, 0))
        # Selected Nucleotide
        x, y = self.getSelected()
        if 0 <= x < self.dpi.get() and 0 <= y < self.dpi.get():
            pilImg.putpixel((int(y), int(x)), (255, 0, 0))

        # Zoom
        zoom = int(self.zoom.get())
        newsize = (self.dpi.get() * int(zoom), self.dpi.get() * int(zoom))
        pilImg = pilImg.resize(newsize, Image.NEAREST)
        # Show
        tkImg = ImageTk.PhotoImage(pilImg)
        self.imgDisplay.configure(image=tkImg)
        self.image = tkImg  # Keep a reference!
        self.pilImage = pilImg  # For saving
Пример #12
0
 def test_rasterize_2d_coordinates_single_point_Y3(self):
     a = np.array([[0., 110.]])
     a_rast = fpp.rasterized_2d_coordinates(a, 10)
     nptest.assert_array_equal(a_rast, np.array([[0, 11]]))
Пример #13
0
 def test_rasterize_2d_coordinates_single_point_X2(self):
     a = np.array([[109.99, 0.]])
     a_rast = fpp.rasterized_2d_coordinates(a, 10)
     nptest.assert_array_equal(a_rast, np.array([[10, 0]]))
Пример #14
0
 def test_rasterize_2d_coordinates_many_points(self):
     a = np.array([[100., 0.], [109.99, 0.], [110., 0.],
                   [0., 100.], [0., 109.99], [0., 110.]])
     a_rast = fpp.rasterized_2d_coordinates(a, 10)
     nptest.assert_array_equal(a_rast, np.array(
         [[10, 0], [10, 0], [11, 0], [0, 10], [0, 10], [0, 11]]))
Пример #15
0
 def test_rasterize_2d_coordinates_single_point_Y3(self):
     a = np.array([[0., 110.]])
     a_rast = fpp.rasterized_2d_coordinates(a, 10)
     nptest.assert_array_equal(a_rast, np.array([[0, 11]]))
Пример #16
0
 def test_rasterize_2d_coordinates_single_point_X2(self):
     a = np.array([[109.99, 0.]])
     a_rast = fpp.rasterized_2d_coordinates(a, 10)
     nptest.assert_array_equal(a_rast, np.array([[10, 0]]))