27d331c946cd8dc45d63b37be2dfe0e5cf342f50,src/biotite/sequence/graphics/plasmid.py,,,#,257

Before Change





try:
    // Only create these classes when matplotlib is installed
    from matplotlib.artist import Artist
    from matplotlib.transforms import Bbox
    from matplotlib.patches import Rectangle, Polygon


    class PlasmidMap(Artist):
        pass


    class Feature_Indicator(Artist):
        def __init__(self, axes, zorder, feature, loc, bbox, head_width,
                     arrow_properties, label_properties, feature_formatter):
            super().__init__()
            self._axes = axes
            self.zorder = zorder
            self._direction = loc.strand
            self._bbox = bbox
            self._head_width = head_width
            
            // Determine how to draw the feature
            directional, face_color, label_color, label \
                = feature_formatter(feature)
            
            // Draw arrow as composition of a rectangle and a triangle,
            // as FancyArrow does not properly work for polar plots

            self._arrow_tail = axes.add_patch(Rectangle(
                // Set positions in "draw()" method
                (0, 0), 0, 0,
                // Line width is set to 1 to avoid strange artifact in
                // the transition from rectangle (tail) to polygon (head)
                color=face_color, linewidth=1, zorder = self.zorder + 1,
                **arrow_properties
            ))
            
            if directional:
                // Only draw any arrow head when feature has a direction,
                // otherwise simply draw the tail (rectangle)
                self._arrow_head = axes.add_patch(Polygon(
                    // Set positions in "draw()" method
                    [(0, 0), (0, 0), (0, 0)],
                    color=face_color, linewidth=1, zorder = self.zorder + 1,
                    **arrow_properties
                ))
            else:
                self._arrow_head = None

            if label is not None:
                self._label = axes.add_artist(CurvedText(
                    // Set positions in "draw()" method
                    axes, self.zorder + 1, 0, 0, label, label_properties
                ))
            else:
                self._label = None


        def draw(self, renderer, *args, **kwargs):
            bbox = self._bbox
            center_x = (bbox.x0 + bbox.x1) / 2
            center_y = (bbox.y0 + bbox.y1) / 2
            
            // Check if the feature location is too small for
            // arrow tail AND head to be drawn
            if self._arrow_head is None:
                head_width = 0
            elif self._head_width > bbox.width:
                // Limit size of arrow head to range of location
                head_width = bbox.width
            else:
                head_width = self._head_width

            if self._direction == Location.Strand.FORWARD:
                rect_pos = (bbox.x0, bbox.y0)
                // (x0, y0), (x1, y1), (x2, y2)
                triangle_coord = [
                    (bbox.x1 - head_width, bbox.y0), // base 1
                    (bbox.x1 - head_width, bbox.y1), // base 2
                    (bbox.x1,              center_y) // tip
                ]
            else:
                rect_pos = (bbox.x0+head_width, bbox.y0)
                triangle_coord = [
                    (bbox.x0 + head_width, bbox.y0), // base 1
                    (bbox.x0 + head_width, bbox.y1), // base 2
                    (bbox.x0,              center_y) // tip
                ]
            
            // Update coordinates of sub-artists
            self._arrow_tail.set_xy(rect_pos)
            self._arrow_tail.set_width(bbox.width-head_width)
            self._arrow_tail.set_height(bbox.height)
            if self._arrow_head is not None:
                self._arrow_head.set_xy(triangle_coord)
            if self._label is not None:
                self._label.set_position(center_x, center_y)


    class CurvedText(Artist):

        def __init__(self, axes, zorder, angle, radius, string,
                     text_properties):
            super().__init__()
            self._axes = axes
            self.zorder = zorder
            self._angle = angle
            self._radius = radius

            self._texts = []
            for word in _split_into_words(string):
                text = axes.text(
                    // Set position in "draw()" method
                    0, 0,
                    word,
                    ha="center", va="center",
                    zorder=self.zorder + 1,
                    **text_properties,
                )
                self._texts.append(text)
        
        def set_position(self, angle, radius):
            self._angle = angle
            self._radius = radius
        
        def draw(self, renderer, *args, **kwargs):
            xlim = self._axes.get_xlim()
            ylim = self._axes.get_ylim()
            
            ax_px_radius = self._axes.get_window_extent(renderer).width / 2
            circle_px_radius = ax_px_radius * self._radius / ylim[1]
            
            value_range = xlim[1] - xlim[0]
            units_per_px = value_range / (circle_px_radius * 2*np.pi)

            rad_angle = 360 - np.rad2deg(self._angle)
            // Avoid to draw the text upside down, when drawn on the
            // bottom half of the map
            if rad_angle > 90 and rad_angle < 270:
                turn_around = True
            else:
                turn_around = False
            
            unit_widths = []
            total_unit_width = 0
            for text in self._texts:
                // Reset rotation for correct window extent calculation
                text.set_rotation(0)
                word_px_width = text.get_window_extent(renderer).width
                word_unit_width = word_px_width * units_per_px
                unit_widths.append(word_unit_width)
                total_unit_width += word_unit_width
            
            // Now that the width is known,
            // the appropriate position and rotation can be set
            if turn_around:
                // curr_angle is the left-aligned position of the
                // upcoming word
                curr_angle = self._angle + total_unit_width / 2
            else:
                curr_angle = self._angle - total_unit_width / 2
            for text, width in zip(self._texts, unit_widths):
                if turn_around:
                    // The text itself is centered
                    // -> The position itself must be corrected with
                    // half of the word width
                    angle_corrected = curr_angle - width / 2
                    text_rot = 360 - np.rad2deg(angle_corrected) + 180
                    curr_angle -= width
                else:
                    angle_corrected = curr_angle + width / 2
                    text_rot = 360 - np.rad2deg(angle_corrected)
                    curr_angle += width
                text.set_position((angle_corrected, self._radius))
                text.set_rotation(text_rot)


except ImportError:
    pass

After Change




// " ", "-" and "_" are word delimiters
separators = re.compile("\s|_|-")
def _split_into_words(string):
    match_indices = sorted(
        [match.start() for match in separators.finditer(string)]
    )
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 2

Instances


Project Name: biotite-dev/biotite
Commit Name: 27d331c946cd8dc45d63b37be2dfe0e5cf342f50
Time: 2020-02-20
Author: patrick.kunzm@gmail.com
File Name: src/biotite/sequence/graphics/plasmid.py
Class Name:
Method Name:


Project Name: vatlab/SoS
Commit Name: b0e2dcf03895421b651ee286ddf244addec7e9c5
Time: 2019-02-25
Author: ben.bog@gmail.com
File Name: src/sos/executor_utils.py
Class Name:
Method Name: prepare_env


Project Name: pyinstaller/pyinstaller
Commit Name: 9595af8e4f8779735d581af067ea213e27376679
Time: 2015-06-01
Author: h.goebel@crazy-compilers.com
File Name: PyInstaller/lib/modulegraph/modulegraph.py
Class Name: ModuleGraph
Method Name: run_script