o
    RÅ€g€  ã                   @   s@   d Z ddlmZ ddlmZ G dd„ dƒZedkreƒ ZdS dS )	zÇFeature module.

Provides:
 - Feature - class to wrap Bio.SeqFeature objects with drawing information

For drawing capabilities, this module uses reportlab to define colors:
http://www.reportlab.com
é    )Úcolorsé   )ÚColorTranslatorc                   @   sZ   e Zd ZdZdddejdddfdd„Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ Zdd„ ZdS )ÚFeaturea«  Class to wrap Bio.SeqFeature objects for GenomeDiagram.

    Attributes:
     - parent    FeatureSet, container for the object
     - id        Unique id
     - color    color.Color, color to draw the feature
     - hide      Boolean for whether the feature will be drawn or not
     - sigil     String denoting the type of sigil to use for the feature.
       Currently either "BOX" or "ARROW" are supported.
     - arrowhead_length  Float denoting length of the arrow head to be drawn,
       relative to the bounding box height.  The arrow shaft
       takes up the remainder of the bounding box's length.
     - arrowshaft_height  Float denoting length of the representative arrow
       shaft to be drawn, relative to the bounding box height.
       The arrow head takes the full height of the bound box.
     - name_qualifiers   List of Strings, describes the qualifiers that may
       contain feature names in the wrapped Bio.SeqFeature object
     - label     Boolean, 1 if the label should be shown
     - label_font    String describing the font to use for the feature label
     - label_size    Int describing the feature label font size
     - label_color  color.Color describing the feature label color
     - label_angle   Float describing the angle through which to rotate the
       feature label in degrees (default = 45, linear only)
     - label_position    String, 'start', 'end' or 'middle' denoting where
       to place the feature label. Leave as None for the default
       which is 'start' for linear diagrams, and at the bottom of
       the feature as drawn on circular diagrams.
     - label_strand  Integer -1 or +1 to explicitly place the label on the
       forward or reverse strand. Default (None) follows th
       feature's strand. Use -1 to put labels under (linear) or
       inside (circular) the track, +1 to put them above (linear)
       or outside (circular) the track.
     - locations     List of tuples of (start, end) ints describing where the
       feature and any subfeatures start and end
     - type      String denoting the feature type
     - name      String denoting the feature name
     - strand    Int describing the strand on which the feature is found

    Nr   c                 C   sš   |dur|}t ƒ | _|| _|| _|| _|| _d| _d| _d| _d| _	d| _
g d¢| _|| _d| _d| _tj| _d	| _d| _d| _|durK|  |¡ dS dS )
a  Initialize.

        Arguments:
         - parent    FeatureSet containing the feature
         - feature_id    Unique id for the feature
         - feature   Bio.SeqFeature object to be wrapped
         - color    color.Color Color to draw the feature (overridden
           by backwards compatible argument with UK spelling, colour).
           Either argument is overridden if 'color' is found in feature
           qualifiers
         - border   color.Color Color to draw the feature border, use
           None for the same as the fill color, False for no border.
         - label     Boolean, 1 if the label should be shown

        Nr   ÚBOXg      à?gš™™™™™Ù?)ÚgeneÚlabelÚnameÚ	locus_tagÚproductÚ	Helveticaé   é-   )r   Ú_colortranslatorÚparentÚidÚcolorÚborderÚ_featureÚhideÚsigilÚarrowhead_lengthÚarrowshaft_heightÚname_qualifiersr   Ú
label_fontÚ
label_sizer   ÚblackÚlabel_colorÚlabel_angleÚlabel_positionÚlabel_strandÚset_feature)Úselfr   Ú
feature_idÚfeaturer   r   r   Úcolour© r&   úW/var/www/html/myenv/lib/python3.10/site-packages/Bio/Graphics/GenomeDiagram/_Feature.pyÚ__init__F   s.   
ÿzFeature.__init__c                 C   s   || _ |  ¡  dS )z/Define the Bio.SeqFeature object to be wrapped.N)r   Ú_Feature__process_feature)r"   r$   r&   r&   r'   r!   {   s   zFeature.set_featurec                 C   sô   g | _ g }| jjjD ]}t|jƒ}t|jƒ}| j  ||f¡ |||g7 }q
t| jj	ƒ| _	| jjj
du r7d| _
nt| jjj
ƒ| _
d| jjv rR| j | jjd d ¡| _| j	| _| jD ]}|| jjv rl| jj| d | _ nqYt|ƒt|ƒ| _| _dS )zFExamine wrapped feature and set some properties accordingly (PRIVATE).Nr   r   )Ú	locationsr   ÚlocationÚpartsÚintÚstartÚendÚappendÚstrÚtypeÚstrandÚ
qualifiersr   Úartemis_colorr   r	   r   ÚminÚmax)r"   Úboundsr+   r.   r/   Ú	qualifierr&   r&   r'   Ú__process_feature€   s,   

ÿ
þzFeature.__process_featurec                 C   s   | j S )z+Return the unwrapped Bio.SeqFeature object.)r   )r"   r&   r&   r'   Úget_feature    s   zFeature.get_featurec                 C   s   | j  |¡}|| _dS )zIBackwards compatible variant of set_color(self, color) using UK spelling.N©r   Ú	translater   )r"   r%   r   r&   r&   r'   Ú
set_colour¤   s   
zFeature.set_colourc                 C   s   | j  |¡}|| _dS )a  Set the color in which the feature will be drawn.

        Arguments:
         - color    The color to draw the feature - either a colors.Color
           object, an RGB tuple of floats, or an integer corresponding a
           colors in colors.txt

        Nr<   )r"   r   r&   r&   r'   Ú	set_color©   s   

zFeature.set_colorc                 C   s   t | j|ƒS )z‹Get attribute by name.

        If the Feature class doesn't have the attribute called for,
        check in self._feature for it.
        )Úgetattrr   )r"   r	   r&   r&   r'   Ú__getattr__¶   s   zFeature.__getattr__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú
lightgreenr(   r!   r)   r;   r>   r?   rA   r&   r&   r&   r'   r      s     *
ø5 r   Ú__main__N)rE   Úreportlab.libr   Ú_Colorsr   r   rB   Úgdfr&   r&   r&   r'   Ú<module>   s   
 '
þ