Source code for Features

# Features.py
# By MW, Jul 2013
# GPLv3+
#
# Module managing features. A feature is a set of time periods representing
#+something like a phase in the cellular cycle. This feature can have various
#+time representations: a single point, multiple point, a time segment...
# For the moment, there is no constraint between features (e.g.: metaphase
#+ must be followed by anaphase, etc.), but my idea is to add a constraint 
#+function in the definition of a feature. For instance, this constraint can
#+be a Markov model or something like that.

import sys
sys.path.append('./bin/Features/')
sys.path.append('./conf/')
import Feature, features

[docs]class Features : def __init__(self) : self.features_dict = {} self.features_typ ={'point' : Feature.Point, 'multipoint' : Feature.Multipoint, 'segment' : Feature.Segment, 'multisegment' : Feature.Multisegment, 'cell' : Feature.Cell } features.get_features(self) # Load user-defined features.
[docs] def new_feature(self, typ, name, shortname, color, descr, model=None) : """This function instanciate a feature (from the Feature class), register it in the features_dict, check ifS the name is not already in use (and also the color). typ in ['point', 'multipoint', 'segment', 'multisegment'] color as a RGB color (tuple) descr: a str """ cols = [] for f in self.features_dict.values() : cols.append(f.get_color()) if name in self.features_dict.keys() or color in cols: return False else : f = self.features_typ[typ](name, shortname, color, descr, model) self.features_dict[name] = f return f
[docs] def get_features_dict(self) : return self.features_dict
[docs] def get_save_dict(self) : dic = {} f_d = {} for n in self.features_dict.keys() : f_d[n] = self.features_dict[n].get_save_dict() dic['features_dic'] = {'descr' : 'Dict containting all the features', 'value' : f_d} dic['features_typ'] = {'descr' : 'A dict object linking the type of the feature (Point, Segment) with the class to initialize', 'value' : self.features_typ} return {'descr' : 'Class describing all the features for a cell', 'value' : dic}
[docs] def load_save_dict(self, dic) : #self.features_typ = dic['value']['features_typ']['value'] for n in dic['value']['features_dic']['value'].keys() : d = dic['value']['features_dic']['value'][n]['value'] if (not self.features_dict.has_key(n)) : typ = d['typ']['value'] col = d['color']['value'] sn = d['short_name']['value'] desc = d['descr']['value'] # TYPO TO BE CORRECTED IN V6 mod = d['model']['value'] f=self.new_feature(typ, n, sn, col, desc, mod) else : f = self.features_dict[n] f.load_save_dict(d)