def test_clear1(self): bd1 = SetBDMap() for k, v in self.mdat2: bd1[k] = v bd1.clear() self.assertItemsEqual({}, bd1.fwd_map) self.assertItemsEqual({}, bd1.bwd_map)
def __init__(self, **kwargs): r""" Parameters ---------- kwargs : dict any keyworded arguments that may be used by the user for finer control (e.g. in sublass); currently, no arguments are used """ self._jgmap = SetBDMap()
def configure(self, domains=None, recognized_relations=None): r""" Configure this manager. Parameters ---------- domains : iterable of string/None iterable of GO domains that this manager will recognize; if None, all domains are recognized; None by default recognized_relations : iterable of string/None iterable of inter--term relations that this manager will recognize; if None, default relations will be recognized (:data:`GO_DEF_RECOGNIZED_RELATIONS`); None by default """ # resolve recognized relations if recognized_relations is None: self.recognizedRelations = list(GO_DEF_RECOGNIZED_RELATIONS) else: self.recognizedRelations = recognized_relations # constant iterable of PK recognized domains if domains is None: self.domains = tuple(GO_DS) else: self.domains = tuple(domains) # direct dictionary of term data self.terms = dict() # additional map of synonym GO terms self.synonyms = SetBDMap() # additional map of terms grouped according to recognized relations self.termsRelationsHierarchy = dict([ (r, SetBDMap()) for r in self.recognizedRelations ]) # additional map of term hierarchy (parent->child independently of relations) self.termsPlainHierarchy = SetBDMap() # configuration is finished self.configured = True
def test_del1(self): bd1 = SetBDMap() bd1['a'] = 1 bd1['a'] = 1 bd1['a'] = 2 bd1['a'] = 2 bd1['b'] = 1 bd1['b'] = 1 bd1['b'] = 2 bd1['b'] = 2 ref1_fwd = {'a': set([1, 2]), 'b': set([1, 2])} ref1_bwd = {1: set(['a', 'b']), 2: set(['a', 'b'])} self.assertEqual(ref1_fwd, bd1.dumpFwdMap()) self.assertEqual(ref1_bwd, bd1.dumpBwdMap()) del bd1['b'] ref2_fwd = {'a': set([1, 2])} ref2_bwd = {1: set(['a']), 2: set(['a'])} self.assertEqual(ref2_fwd, bd1.dumpFwdMap()) self.assertEqual(ref2_bwd, bd1.dumpBwdMap())
def __init__(self): super(PKCIDMapGOGPL, self).__init__() self.domains_map = dict([(d, SetBDMap()) for d in GO_DS]) self.dbt = None self.built = False
class JobGroupManager(object): r""" Simple manager of groups of jobs. Can be used for finer execution control and to facilitate reporting. """ def __init__(self, **kwargs): r""" Parameters ---------- kwargs : dict any keyworded arguments that may be used by the user for finer control (e.g. in sublass); currently, no arguments are used """ self._jgmap = SetBDMap() def addJobIDToGroup(self, group_name, jobID): r""" Add requested job to specified job group. If group was not defined before, it will be created. Parameters ---------- group_name : string name of the group jobID : string job ID """ self._jgmap[group_name] = jobID def addGroup(self, group_name, group_job_ids): r""" Add series of jobs to specified job group (shortcut). If group was not defined before, it will be created. Parameters ---------- group_name : string name of the group group_job_ids : iterable of string job IDs """ for jid in group_job_ids: self.addJobIDToGroup(group_name, jid) def remGroup(self, group_name): r""" Remove specified job group from this manager. All associated job IDs are removed as well. NOTE: physical jobs are left intact. Parameters ---------- group_name : string name of the group """ del self._jgmap[group_name] def clear(self): r""" Removes all job groups from this manager. """ self._jgmap.clear() def getGroupJobsIDs(self, group_name): r""" Get list of job IDs associated with specified job group name. Parameters ---------- group_name : string name of the group Returns ------- jobIDs : iterable of string all job IDs from requested group, if exists """ return list(self._jgmap.getFwdMap()[group_name]) def findGroupByJobID(self, jobID): r""" Identify job group of the requested job ID. Parameters ---------- jobID : string job ID Returns ------- group_name : string name of the group with requested job, if exists Raises ------ Error if jobID is found in more than one group """ gr = self._jgmap.getBwdMap()[jobID] if len(gr) > 1: # should not happen with SetBDMap but to be safe... raise Error( 'Job shall be internally assigned to single group! (got %s)' % gr) # return single element from the set return next(iter(gr)) def getGroups(self): r""" Get list of all job group names managed by this manager. """ return self._jgmap.getFwdMap().keys()
def __init__(self): # all considered prior knowledge domains (separated groups of concepts, e.g. thematic) self.domains = tuple() # concept IDs grouped according to domains self.domain2concepts = SetBDMap() self.configured = False
def test_get1(self): bd1 = SetBDMap() bd1['a'] = 1 self.assertEqual(set([1]), bd1['a']) self.assertEqual(bd1.keyIsMissing(), bd1['XXX'])
def test_set3(self): bd1 = SetBDMap() for k, v in self.mdat3: bd1[k] = v self.assertEqual(self.fwdmap3, bd1.dumpFwdMap()) self.assertEqual(self.bwdmap3, bd1.dumpBwdMap())
def test_set1(self): bd1 = SetBDMap() bd1['a'] = 1 bd1[1] = 'a' self.assertEqual(self.circular, bd1.dumpFwdMap()) self.assertEqual(self.circular, bd1.dumpBwdMap())
def test_init2(self): bd1 = SetBDMap(initial_map=self.mdict1) self.assertEqual(self.fwdmap1, bd1.dumpFwdMap()) self.assertEqual(self.bwdmap1, bd1.dumpBwdMap())
def test_init1(self): bd1 = SetBDMap() self.assertEqual(self.emptyFwdMap, bd1.getFwdMap()) self.assertEqual(self.emptyBwdMap, bd1.getBwdMap())