*
:c       s     d  Z  ' ) d f  d     YZ b d f  d     YZ  d f  d     YZ  d f  d     YZ  d	 e f d
     YZ  d e f d     YZ  d e f d     YZ d e f d     YZ d e f d     YZ	 d S(   s  Represent a Sequence Feature holding info about a part of a sequence.

This is heavily modeled after the Biocorba SeqFeature objects, and
may be pretty biased towards GenBank stuff since I'm writing it
for the GenBank parser output...

What's here:

Base class to hold a Feature.
----------------------------
classes:
o SeqFeature

Hold information about a Reference.
----------------------------------

This is an attempt to create a General class to hold Reference type
information.

classes:
o Reference

Specify locations of a feature on a Sequence.
---------------------------------------------

This aims to handle, in Ewan's words, 'the dreaded fuzziness issue' in
much the same way as Biocorba. This has the advantages of allowing us
to handle fuzzy stuff in case anyone needs it, and also be compatible
with Biocorba.

classes:
o FeatureLocation - Specify the start and end location of a feature.

o ExactPosition - Specify the position as being exact.
o WithinPosition - Specify a position occuring within some range.
o BetweenPosition - Specify a position occuring between a range.
o BeforePosition - Specify the position as being found before some base.
o AfterPosition - Specify the position as being found after some base.
s
   SeqFeaturec      s&   ) d  Z  > ? d   Z K d   Z RS(   s  Represent a Sequence Feature on an object.

    Attributes:
    o location - the location of the feature on the sequence
    o type - the specified type of the feature (ie. CDS, exon, repeat...)
    o ref - A reference to another sequence. This could be an accession
    number for some different sequence.
    o ref_db - A different database for the reference accession number.
    o qualifier - A dictionary of qualifiers on the feature. These are
    analagous to the qualifiers from a GenBank feature table. The keys of
    the dictionary are qualifier names, the values are the qualifier
    values.
    o sub_features - Additional SeqFeatures which fall under this 'parent'
    feature. For instance, if we having something like:

    CDS    join(1..10,30..40,50..60)

    The the top level feature would be a CDS from 1 to 60, and the sub
    features would be of 'CDS_span' type and would be from 1 to 10, 30 to
    40 and 50 to 60, respectively.
    c    s^   ? A B t  |  _ D d |  _ E t  |  _ F t  |  _ G d |  _ H h  |  _ I g  |  _ d S(   s/   Initialize a SeqFeature on a Sequence.
        s    i    N(	   s   Nones   selfs   locations   types   refs   ref_dbs   strands
   qualifierss   sub_features(   s   self(    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   __init__? s   c    s   K M N d |  i } O | d |  i 7} P | d |  i |  i f 7} Q | d |  i 7} R | d 7} S |  i i   } T | i
   U x1 | d U r$ } V | d | |  i | f 7} q WX t |  i  d j o> Y | d 7} Z x' |  i d Z r } [ | d	 | 7} q Wn ] | Sd
 S(   s*   Make it easier to debug features.
        s	   type: %s
s   location: %s
s   ref: %s:%s
s   strand: %s
s   qualifiers: 
i    s   	Key: %s, Value: %s
s   Sub-Features
s   %s
N(   s   selfs   types   outs   locations   refs   ref_dbs   strands
   qualifierss   keyss   qualifier_keyss   sorts   qual_keys   lens   sub_featuress   sub_feature(   s   selfs   outs   qual_keys   qualifier_keyss   sub_feature(    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   __str__K s"    	" 	(   s   __doc__s   __init__s   __str__(    (    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys
   SeqFeature) s   	s	   Referencec      s&   b d  Z  p q d   Z z d   Z RS(   sf  Represent a Generic Reference object.

    Attributes:
    o location - A list of Location objects specifying regions of
    the sequence that the references correspond to. If no locations are
    specified, the entire sequence is assumed.
    o authors - A big old string, or a list split by author, of authors
    for the reference.
    o title - The title of the reference.
    o journal - Journal the reference was published in.
    o medline_id - A medline reference for the article.
    o pubmed_id - A pubmed reference for the article.
    o comment - A place to stick any comments about the reference.
    c    s[   q r g  |  _ s d |  _ t d |  _ u d |  _ v d |  _ w d |  _ x d |  _ d  S(   Ns    (   s   selfs   locations   authorss   titles   journals
   medline_ids	   pubmed_ids   comment(   s   self(    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   __init__q s   c    s   z | } d } ~ x' |  i d ~ r }  | d | 7} q W | d |  i 7}  | d |  i 7}  | d |  i 7}  | d |  i 7}  | d |  i 7}  | d	 |  i	 7}  | Sd
 S(   s4   Output an informative string for debugging.
        s    i    s   location: %s
s   authors: %s
s
   title: %s
s   journal: %s
s   medline id: %s
s   pubmed id: %s
s   comment: %s
N(
   s   outs   selfs   locations   single_locations   authorss   titles   journals
   medline_ids	   pubmed_ids   comment(   s   selfs   outs   single_location(    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   __str__z s   	 	(   s   __doc__s   __init__s   __str__(    (    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys	   Referenceb s   		s   FeatureLocationc      s2    d  Z    d   Z  d   Z  d   Z RS(   s  Specify the location of a feature along a sequence.

    This attempts to deal with fuzziness of position ends, but also
    make it easy to get the start and end in the 'normal' case (no
    fuzziness).

    You should access the start and end attributes with
    your_location.start and your_location.end. If the start and
    end are exact, this will return the positions, if not, we'll return
    the approriate Fuzzy class with info about the position and fuzziness.
    c    st      t  | t  o  | |  _ n  t |  |  _  t  | t  o  | |  _ n  t |  |  _ d S(   s  Specify the start and end of a sequence feature.

        start and end arguments specify the values where the feature begins
        and ends. These can either by any of the *Position objects that
        inherit from AbstractPosition, or can just be integers specifying the
        position. In the case of integers, the values are assumed to be
        exact and are converted in ExactPosition arguments. This is meant
        to make it easy to deal with non-fuzzy ends.
        N(   s
   isinstances   starts   AbstractPositions   selfs   _starts   ExactPositions   ends   _end(   s   selfs   starts   end(    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   __init__ s   	c    s     d |  i |  i f Sd  S(   Ns   (%s..%s)(   s   selfs   _starts   _end(   s   self(    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   __str__ s   c    s      | d j o  |  i Sn  | d j o  |  i Sn  | d j o-  t |  i i  |  i i |  i i  SnQ  | d j o-  t |  i i  |  i i |  i i  Sn  t d |   d S(   s#  Make it easy to get non-fuzzy starts and ends.

        We override get_attribute here so that in non-fuzzy cases we
        can just return the start and end position without any hassle.

        To get fuzzy start and ends, just ask for item.start and
        item.end. To get non-fuzzy attributes (ie. the position only)
        ask for 'item.nofuzzy_start', 'item.nofuzzy_end'. These should return
        the largest range of the fuzzy position. So something like:
        (10.20)..(30.40) should return 10 for start, and 40 for end.
        s   starts   ends   nofuzzy_starts   nofuzzy_ends   Cannot evaluate attribute %s.N(	   s   attrs   selfs   _starts   _ends   mins   positions	   extensions   maxs   AttributeError(   s   selfs   attr(    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   __getattr__ s   (   s   __doc__s   __init__s   __str__s   __getattr__(    (    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   FeatureLocation s   	s   AbstractPositionc      s    d  Z    d   Z RS(   s1   Abstract base class representing a position.
    c    s     | |  _   | |  _ d  S(   N(   s   positions   selfs	   extension(   s   selfs   positions	   extension(    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   __init__ s   (   s   __doc__s   __init__(    (    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   AbstractPosition s   	s   ExactPositionc      s)    d  Z    d d  Z  d   Z RS(   so  Specify the specific position of a boundary.

    o position - The position of the boundary.
    o extension - An optional argument which must be zero since we don't
    have an extension. The argument is provided so that the same number of
    arguments can be passed to all position types.

    In this case, there is no fuzziness associated with the position.
    i    c    sD     | d j o  t d |   n  t i |  | d  d  S(   Ni    s)   Non-zero extension %s for exact position.(   s	   extensions   AttributeErrors   AbstractPositions   __init__s   selfs   position(   s   selfs   positions	   extension(    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   __init__ s   c    s     t  |  i  Sd  S(   N(   s   strs   selfs   position(   s   self(    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   __str__ s   (   s   __doc__s   __init__s   __str__(    (    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   ExactPosition s   		s   WithinPositionc      s)    d  Z    d d  Z  d   Z RS(   s  Specify the position of a boundary within some coordinates.

    Arguments:
    o position - The start position of the boundary
    o extension - The range to which the boundary can extend.

    This allows dealing with a position like ((1.4)..100). This
    indicates that the start of the sequence is somewhere between 1
    and 4. To represent that with this class we would set position as
    1 and extension as 3.
    i    c    s     t  i |  | |  d  S(   N(   s   AbstractPositions   __init__s   selfs   positions	   extension(   s   selfs   positions	   extension(    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   __init__ s   c    s%     d |  i |  i |  i f Sd  S(   Ns   (%s.%s)(   s   selfs   positions	   extension(   s   self(    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   __str__ s   (   s   __doc__s   __init__s   __str__(    (    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   WithinPosition s   	s   BetweenPositionc      s)    d  Z    d d  Z d   Z RS(   s  Specify the position of a boundary between two coordinates.

    Arguments:
    o position - The start position of the boundary.
    o extension - The range to the other position of a boundary.

    This specifies a coordinate which is found between the two positions.
    So this allows us to deal with a position like ((1^2)..100). To
    represent that with this class we set position as 1 and the
    extension as 1.
    i    c    s     t  i |  | |  d  S(   N(   s   AbstractPositions   __init__s   selfs   positions	   extension(   s   selfs   positions	   extension(    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   __init__ s   c    s%   d |  i |  i |  i f Sd  S(   Ns   (%s^%s)(   s   selfs   positions	   extension(   s   self(    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   __str__s   (   s   __doc__s   __init__s   __str__(    (    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   BetweenPosition s   	s   BeforePositionc      s)   d  Z  d d  Z d   Z RS(   s  Specify a position where the actual location occurs before it.

    Arguments:
    o position - The upper boundary of where the location can occur.
    o extension - An optional argument which must be zero since we don't
    have an extension. The argument is provided so that the same number of
    arguments can be passed to all position types.

    This is used to specify positions like (<10..100) where the location
    occurs somewhere before position 10.
    i    c    sD   | d j o t d |   n t i |  | d  d  S(   Ni    s)   Non-zero extension %s for exact position.(   s	   extensions   AttributeErrors   AbstractPositions   __init__s   selfs   position(   s   selfs   positions	   extension(    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   __init__s   c    s   d |  i Sd  S(   Ns   <%s(   s   selfs   position(   s   self(    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   __str__s   (   s   __doc__s   __init__s   __str__(    (    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   BeforePositions   	s   AfterPositionc      s)   d  Z  %&d d  Z ,d   Z RS(   s  Specify a position where the actual location is found after it.

    Arguments:
    o position - The lower boundary of where the location can occur.
    o extension - An optional argument which must be zero since we don't
    have an extension. The argument is provided so that the same number of
    arguments can be passed to all position types.

    This is used to specify positions like (>10..100) where the location
    occurs somewhere after position 10.
    i    c    sD   &'| d j o (t d |   n *t i |  | d  d  S(   Ni    s)   Non-zero extension %s for exact position.(   s	   extensions   AttributeErrors   AbstractPositions   __init__s   selfs   position(   s   selfs   positions	   extension(    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   __init__&s   c    s   ,-d |  i Sd  S(   Ns   >%s(   s   selfs   position(   s   self(    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   __str__,s   (   s   __doc__s   __init__s   __str__(    (    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   AfterPositions   	N(
   s   __doc__s
   SeqFeatures	   References   FeatureLocations   AbstractPositions   ExactPositions   WithinPositions   BetweenPositions   BeforePositions   AfterPosition(	   s
   SeqFeatures   BetweenPositions   AbstractPositions   AfterPositions   FeatureLocations	   References   ExactPositions   WithinPositions   BeforePosition(    (    s'   /mit/seven/lib/python/Bio/SeqFeature.pys   ?' s   9)<