Back to index

python-biopython  1.60
Public Member Functions | Public Attributes
Bio.Graphics.GenomeDiagram._FeatureSet.FeatureSet Class Reference

List of all members.

Public Member Functions

def __init__
def add_feature
def del_feature
def set_all_features
def get_features
def get_ids
def range
def to_string
def __len__
def __getitem__
def __str__

Public Attributes

 parent
 id
 next_id
 features
 name

Detailed Description

FeatureSet

    Provides:

    Methods:

    o __init__(self, set_id=None, name=None) Called on instantiation

    o add_feature(self, feature, color=colors.lightgreen)  Add a Feature
                    object to the set

    o del_feature(self, feature_id) Remove a feature from the set, by id

    o set_all_features(self, attr, value)   Set the passed attribute to the
                    passed value in all features in the set

    o get_features(self)    Returns a list of Features from the set

    o get_ids(self)     Returns a list of unique ids for features in the set

    o range(self)       Returns the range of bases covered by features in 
                        the set

    o to_string(self, verbose=0)    Returns a string describing the set

    o __len__(self)     Returns the length of sequence covered by the set

    o __getitem__(self, key)    Returns a feature from the set, keyed by id

    o __str__(self)     Returns a string describing the set

    Attributes:

    o id    Unique id for the set

    o name  String describing the set

Definition at line 52 of file _FeatureSet.py.


Constructor & Destructor Documentation

def Bio.Graphics.GenomeDiagram._FeatureSet.FeatureSet.__init__ (   self,
  set_id = None,
  name = None,
  parent = None 
)
__init__(self, set_id=None, name=None)

    o set_id    Unique id for the set

    o name      String identifying the feature set

Definition at line 90 of file _FeatureSet.py.

00090 
00091     def __init__(self, set_id=None, name=None, parent=None):
00092         """ __init__(self, set_id=None, name=None)
00093 
00094             o set_id    Unique id for the set
00095 
00096             o name      String identifying the feature set
00097         """
00098         self.parent = parent
00099         self.id = id            # Unique id for the set
00100         self.next_id = 0       # counter for unique feature ids
00101         self.features = {}     # Holds features, keyed by ID
00102         self.name = name        # String describing the set
00103 

Here is the caller graph for this function:


Member Function Documentation

__getitem__(self, key) -> Feature

    Return a feature, keyed by id

Definition at line 261 of file _FeatureSet.py.

00261 
00262     def __getitem__(self, key):
00263         """ __getitem__(self, key) -> Feature
00264 
00265             Return a feature, keyed by id
00266         """
00267         return self.features[key]
00268 

Here is the caller graph for this function:

__len__(self) -> int

    Return the number of features in the set

Definition at line 253 of file _FeatureSet.py.

00253 
00254     def __len__(self):
00255         """ __len__(self) -> int
00256 
00257             Return the number of features in the set
00258         """
00259         return len(self.features)
00260 

__str__(self) -> ""

    Returns a formatted string with information about the feature set

Definition at line 269 of file _FeatureSet.py.

00269 
00270     def __str__(self):
00271         """ __str__(self) -> ""
00272 
00273             Returns a formatted string with information about the feature set
00274         """
00275         outstr = ["\n<%s: %s %d features>" % (self.__class__, self.name, 
00276                                               len(self.features))]
00277         return "\n".join(outstr)

Here is the caller graph for this function:

def Bio.Graphics.GenomeDiagram._FeatureSet.FeatureSet.add_feature (   self,
  feature,
  kwargs 
)
add_feature(self, feature, **args)

    o feature       Bio.SeqFeature object

    o **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

Definition at line 104 of file _FeatureSet.py.

00104 
00105     def add_feature(self, feature, **kwargs):
00106         """ add_feature(self, feature, **args)
00107 
00108             o feature       Bio.SeqFeature object
00109 
00110             o **kwargs      Keyword arguments for Feature.  Named attributes
00111                             of the Feature
00112                                                         
00113 
00114             Add a Bio.SeqFeature object to the diagram (will be stored
00115             internally in a Feature wrapper
00116         """
00117         id = self.next_id                                  # get id number
00118         f = Feature(self, id, feature)
00119         self.features[id] = f # add feature
00120         for key in kwargs:
00121             if key == "colour" or key == "color":
00122                 #Deal with "colour" as a special case by also mapping to color.
00123                 #If Feature.py used a python property we wouldn't need to call
00124                 #set_color explicitly.  However, this is important to make sure
00125                 #every color gets mapped to a colors object - for example color
00126                 #numbers, or strings (may not matter for PDF, but does for PNG).
00127                 self.features[id].set_color(kwargs[key])
00128                 continue
00129             setattr(self.features[id], key, kwargs[key])
00130         self.next_id += 1                                  # increment next id
00131         return f

del_feature(self, feature_id)

    o feature_id        Unique id of the feature to delete

    Remove a feature from the set, indicated by its id

Definition at line 132 of file _FeatureSet.py.

00132 
00133     def del_feature(self, feature_id):
00134         """ del_feature(self, feature_id)
00135 
00136             o feature_id        Unique id of the feature to delete
00137 
00138             Remove a feature from the set, indicated by its id
00139         """
00140         del self.features[feature_id]
00141 

def Bio.Graphics.GenomeDiagram._FeatureSet.FeatureSet.get_features (   self,
  attribute = None,
  value = None,
  comparator = None 
)
get_features(self, attribute=None, value=None, comparator=None) ->
                            [Feature, Feature, ...]

    o attribute        String, attribute of a Feature object

    o value            The value desired of the attribute

    o 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.

Definition at line 165 of file _FeatureSet.py.

00165 
00166     def get_features(self, attribute=None, value=None, comparator=None):
00167         """ get_features(self, attribute=None, value=None, comparator=None) ->
00168                                             [Feature, Feature, ...]
00169 
00170             o attribute        String, attribute of a Feature object
00171 
00172             o value            The value desired of the attribute
00173 
00174             o comparator       String, how to compare the Feature attribute to the
00175                                passed value
00176             
00177             If no attribute or value is given, return a list of all features in the
00178             feature set.  If both an attribute and value are given, then depending
00179             on the comparator, then a list of all features in the FeatureSet
00180             matching (or not) the passed value will be returned.  Allowed comparators
00181             are: 'startswith', 'not', 'like'.
00182 
00183             The user is expected to make a responsible decision about which feature
00184             attributes to use with which passed values and comparator settings.
00185         """
00186         # If no attribute or value specified, return all features
00187         if attribute is None or value is None:
00188             return self.features.values()
00189         # If no comparator is specified, return all features where the attribute
00190         # value matches that passed
00191         if comparator is None:
00192             return [feature for feature in self.features.values() if\
00193                     getattr(feature, attribute) == value]
00194         # If the comparator is 'not', return all features where the attribute
00195         # value does not match that passed
00196         elif comparator == 'not':
00197             return [feature for feature in self.features.values() if\
00198                     getattr(feature, attribute) != value]
00199         # If the comparator is 'startswith', return all features where the attribute
00200         # value does not match that passed
00201         elif comparator == 'startswith':
00202             return [feature for feature in self.features.values() if\
00203                     getattr(feature, attribute).startswith(value)]
00204         # If the comparator is 'like', use a regular expression search to identify
00205         # features
00206         elif comparator == 'like':
00207             return [feature for feature in self.features.values() if\
00208                     re.search(value, getattr(feature, attribute))]
00209         # As a final option, just return an empty list
00210         return []
00211 
00212 

get_ids(self) -> [int, int, ...]

    Return a list of all ids for the feature set

Definition at line 213 of file _FeatureSet.py.

00213 
00214     def get_ids(self):
00215         """ get_ids(self) -> [int, int, ...]
00216 
00217             Return a list of all ids for the feature set
00218         """
00219         return self.features.keys()
00220 

range(self)

    Returns the lowest and highest base (or mark) numbers as a tuple

Definition at line 221 of file _FeatureSet.py.

00221 
00222     def range(self):
00223         """ range(self)
00224 
00225             Returns the lowest and highest base (or mark) numbers as a tuple
00226         """
00227         lows, highs = [], []
00228         for feature in self.features.values():
00229             for start, end in feature.locations:
00230                 lows.append(start)
00231                 highs.append(end)
00232         if len(lows) != 0 and len(highs) != 0:      # Default in case there is 
00233             return (min(lows), max(highs))          # nothing in the set
00234         return 0, 0
00235 

Here is the caller graph for this function:

set_all_features(self, attr, value)

    o attr      An attribute of the Feature class

    o value     The value to set that attribute

    Set the passed attribute of all features in the set to the
    passed value

Definition at line 142 of file _FeatureSet.py.

00142 
00143     def set_all_features(self, attr, value):
00144         """ set_all_features(self, attr, value)
00145 
00146             o attr      An attribute of the Feature class
00147 
00148             o value     The value to set that attribute
00149 
00150             Set the passed attribute of all features in the set to the
00151             passed value
00152         """
00153         changed = 0
00154         for feature in self.features.values():
00155             # If the feature has the attribute, and the value should change
00156             if hasattr(feature, attr):    
00157                 if getattr(feature, attr) != value:
00158                     setattr(feature, attr, value) # set it to the passed value
00159 
00160         #For backwards compatibility, we support both colour and color.
00161         #As a quick hack, make "colour" set both "colour" and "color".
00162         #if attr=="colour":
00163         #    self.set_all_feature("color",value)
00164 

to_string(self, verbose=0) -> ""

    o verbose       Boolean indicating whether a short or complete 
            account of the set is required

    Returns a formatted string with information about the set

Definition at line 236 of file _FeatureSet.py.

00236 
00237     def to_string(self, verbose=0):
00238         """ to_string(self, verbose=0) -> ""
00239 
00240             o verbose       Boolean indicating whether a short or complete 
00241                             account of the set is required
00242 
00243             Returns a formatted string with information about the set
00244         """
00245         if not verbose:         # Short account only required
00246             return "%s" % self
00247         else:                   # Long account desired
00248             outstr = ["\n<%s: %s>" % (self.__class__, self.name)]
00249             outstr.append("%d features" % len(self.features))
00250             for key in self.features:
00251                 outstr.append("feature: %s" % self.features[key])
00252             return "\n".join(outstr)

Here is the caller graph for this function:


Member Data Documentation

Definition at line 100 of file _FeatureSet.py.

Definition at line 98 of file _FeatureSet.py.

Definition at line 101 of file _FeatureSet.py.

Definition at line 99 of file _FeatureSet.py.

Definition at line 97 of file _FeatureSet.py.


The documentation for this class was generated from the following file: