o
    Rŀg^                     @   s*   d Z ddlZddlmZ G dd dZdS )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                   @   sn   e Zd ZdZdddZdd Zdd Zd	d
 ZdddZdd Z	dd Z
dddZdd Zdd Zdd ZdS )
FeatureSetzFeatureSet object.Nc                 C   s"   || _ t| _d| _i | _|| _dS )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    r   Z/var/www/html/myenv/lib/python3.10/site-packages/Bio/Graphics/GenomeDiagram/_FeatureSet.py__init__#   s
   
zFeatureSet.__init__c                 K   st   | j }t| ||}|| j|< |D ] }|dks|dkr%| j| ||  qt| j| |||  q|  j d7  _ |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keyr   r   r   add_feature1   s   
zFeatureSet.add_featurec                 C   s   | j |= dS )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_idr   r   r   del_featureL   s   zFeatureSet.del_featurec                 C   s*   | j  D ]}t||rt||| qdS )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   r   r   r   set_all_featuresV   s
   

zFeatureSet.set_all_featuresc                    s    du sdu rt | j S |du r  fdd| j D S |dkr1 fdd| j D S |dkrB fdd| j D S |dkrS fd	d| j D S g S )
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.
        Nc                    s   g | ]}t | kr|qS r   getattr.0r   	attributer   r   r   
<listcomp>   
    z+FeatureSet.get_features.<locals>.<listcomp>notc                    s   g | ]}t | kr|qS r   r    r"   r$   r   r   r&      r'   
startswithc                    s    g | ]}t | r|qS r   )r!   r)   r"   r$   r   r   r&      s    likec                    s"   g | ]}t t| r|qS r   )researchr!   r"   r$   r   r   r&      s    )listr   r   )r
   r%   r   
comparatorr   r$   r   get_featuresj   s&   zFeatureSet.get_featuresc                 C   s   t | j S )z-Return a list of all ids for the feature set.)r-   r   keysr
   r   r   r   get_ids   s   zFeatureSet.get_idsc                 C   sj   g g }}| j  D ]}|jD ]\}}|| || qq
t|dkr3t|dkr3t|t|fS dS )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endr   r   r   range   s   

zFeatureSet.ranger   c                 C   sb   |s|  S d| j  d| j dg}|dt| j  | jD ]}|d| j|   qd|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	   r4   r5   r   join)r
   verboseoutstrr   r   r   r   	to_string   s   

zFeatureSet.to_stringc                 C   s
   t | jS )z)Return the number of features in the set.)r5   r   r1   r   r   r   __len__      
zFeatureSet.__len__c                 C   s
   | j | S )zReturn a feature, keyed by id.r   )r
   r   r   r   r   __getitem__   rE   zFeatureSet.__getitem__c                 C   s$   d| j | jt| jf g}d|S )zAReturn a formatted string with information about the feature set.z
<%s: %s %d features>r>   )r?   r	   r5   r   r@   )r
   rB   r   r   r   __str__   s   
zFeatureSet.__str__)NNN)r   )__name__
__module____qualname____doc__r   r   r   r   r/   r2   r<   rC   rD   rF   rG   r   r   r   r   r       s    


8
r   )rK   r+   _Featurer   r   r   r   r   r   <module>   s   	