
    Ri^                     0    d Z ddlZddlmZ  G d d      Zy)zFeatureSet module.

Provides:
 - FeatureSet - container for Feature objects

For drawing capabilities, this module uses reportlab to draw and write
the diagram: http://www.reportlab.com
    N   )Featurec                   X    e Zd ZdZddZd Zd Zd ZddZd Z	d	 Z
dd
Zd Zd Zd Zy)
FeatureSetzFeatureSet object.Nc                 R    || _         t        | _        d| _        i | _        || _        y)zCreate the object.

        Arguments:
         - set_id: Unique id for the set
         - name: String identifying the feature set

        r   N)parentidnext_idfeaturesname)selfset_idr   r   s       ^/home/agent/.friday_env/lib/python3.12/site-packages/Bio/Graphics/GenomeDiagram/_FeatureSet.py__init__zFeatureSet.__init__#   s'     	    c                     | j                   }t        | ||      }|| j                  |<   |D ]K  }|dk(  s|dk(  r"| j                  |   j                  ||          /t	        | j                  |   |||          M | xj                   dz  c_         |S )a%  Add a new feature.

        Arguments:
         - feature: Bio.SeqFeature object
         - kwargs: Keyword arguments for Feature.  Named attributes
           of the Feature

        Add a Bio.SeqFeature object to the diagram (will be stored
        internally in a Feature wrapper).
        colourcolorr   )r
   r   r   	set_colorsetattr)r   featurekwargsr	   fkeys         r   add_featurezFeatureSet.add_feature1   s     \\D"g&b 		9Ch#. b!++F3K8DMM"%sF3K8		9 	r   c                     | j                   |= y)zDelete a feature.

        Arguments:
         - feature_id: Unique id of the feature to delete

        Remove a feature from the set, indicated by its id.
        Nr   )r   
feature_ids     r   del_featurezFeatureSet.del_featureL   s     MM*%r   c                 v    | j                   j                         D ]  }t        ||      st        |||        y)a  Set an attribute of all the features.

        Arguments:
         - attr: An attribute of the Feature class
         - value: The value to set that attribute to

        Set the passed attribute of all features in the set to the
        passed value.
        N)r   valueshasattrr   )r   attrvaluer   s       r   set_all_featureszFeatureSet.set_all_featuresV   s6     }}++- 	.Gw%u-	.r   c           
         ||#t        | j                  j                               S |7| j                  j                         D cg c]  }t        ||      |k(  r| c}S |dk(  r7| j                  j                         D cg c]  }t        ||      |k7  r| c}S |dk(  rC| j                  j                         D cg c]  }t        ||      j	                  |      r|! c}S |dk(  rH| j                  j                         D cg c]$  }t        j                  |t        ||            r|& c}S g S c c}w c c}w c c}w c c}w )a  Retrieve features.

        Arguments:
         - attribute: String, attribute of a Feature object
         - value: The value desired of the attribute
         - comparator: String, how to compare the Feature attribute to the
           passed value

        If no attribute or value is given, return a list of all features in the
        feature set.  If both an attribute and value are given, then depending
        on the comparator, then a list of all features in the FeatureSet
        matching (or not) the passed value will be returned.  Allowed comparators
        are: 'startswith', 'not', 'like'.

        The user is expected to make a responsible decision about which feature
        attributes to use with which passed values and comparator settings.
        not
startswithlike)listr   r!   getattrr(   research)r   	attributer$   
comparatorr   s        r   get_featureszFeatureSet.get_featuresj   sW   & ,,.//   $}}3357I.%7   5   $}}3357I.%7   <'  $}}3357I.99%@   6!  $}}33599UGGY$?@   	=s   D4D9>$D>)Ec                 H    t        | j                  j                               S )z-Return a list of all ids for the feature set.)r*   r   keysr   s    r   get_idszFeatureSet.get_ids   s    DMM&&())r   c                    g g }}| j                   j                         D ]8  }|j                  D ]'  \  }}|j                  |       |j                  |       ) : t	        |      dk7  r$t	        |      dk7  rt        |      t        |      fS y)z@Return the lowest and highest base (or mark) numbers as a tuple.r   )r   r   )r   r!   	locationsappendlenminmax)r   lowshighsr   startends         r   rangezFeatureSet.range   s    "e}}++- 	"G%// "
sE"S!"	" t9>c%jAoIs5z**r   c                    |s|  S d| j                    d| j                   dg}|j                  dt        | j                        z         | j                  D ]#  }|j                  d| j                  |           % dj                  |      S )zReturn a formatted string with information about the set.

        Arguments:
         - verbose: Boolean indicating whether a short (default) or
           complete account of the set is required

        z
<z: >z%d featuresz	feature: 
)	__class__r   r7   r8   r   join)r   verboseoutstrr   s       r   	to_stringzFeatureSet.to_string   s     VDNN+2dii[:;FMM-#dmm*<<=}} @	$--*<)=>?@99V$$r   c                 ,    t        | j                        S )z)Return the number of features in the set.)r8   r   r3   s    r   __len__zFeatureSet.__len__   s    4==!!r   c                      | j                   |   S )zReturn a feature, keyed by id.r   )r   r   s     r   __getitem__zFeatureSet.__getitem__   s    }}S!!r   c                     d| j                   | j                  t        | j                        fz  g}dj	                  |      S )zAReturn a formatted string with information about the feature set.z
<%s: %s %d features>rB   )rC   r   r8   r   rD   )r   rF   s     r   __str__zFeatureSet.__str__   s<     %		3t}}CU'VV
 yy  r   )NNN)r   )__name__
__module____qualname____doc__r   r   r   r%   r0   r4   r?   rG   rI   rK   rM    r   r   r   r       s=    6&.(6p*	%"""!r   r   )rQ   r,   _Featurer   r   rR   r   r   <module>rT      s   $ 
 o! o!r   