• Main Page
  • Namespaces
  • Classes
  • Files
  • File List

/home/mark/model/software/ScrumPy/ScrumPy/Bioinf/PyoCyc/AnnotatedOrganism.py

00001 import types
00002 import Annotate
00003 import Organism
00004 
00005 DefaultPath= Organism.Base.DefaultPath #'/home/unni/.ScrumPy/PyoCyc/testorg/'
00006 
00007 class AnnotatedOrganism(Organism.Organism):
00008 
00009     def __init__(self, *args, **kwargs):
00010 
00011         Organism.Organism.__init__(self, *args, **kwargs)
00012         
00013         AnnoDir = "/".join((self.path, Annotate.DefaultDir))
00014         AnnoFile= self.data+".dat"
00015         
00016         self.AnnoDB = adb = Annotate.DB(path=AnnoDir, file=AnnoFile)
00017         
00018         for id in adb.keys():
00019             if self.has_key(id):
00020                 self[id].Anno = adb[id]
00021  
00022     
00023     def HasAnnotation(self,id):
00024         return hasattr(self[id], "Anno")
00025           
00026     def AddAnnotation(self, id, AnnoDat={}):
00027         """
00028         pre:  True
00029                 AnnoDat = {'a' : ['annotation']}
00030         post: Annotations db[id] updated with AnnoDat (db[id] created if not already present.)
00031         """
00032 
00033         if not self.HasAnnotation(id):
00034             self[id].Anno = self.AnnoDB[id] = Annotate.Record(id)
00035 
00036         self.AnnoDB[id].update(AnnoDat)    
00037      
00038     def AddToField(self, id, fkey,  contents):
00039         """ pre: self[id].Anno.has_key(fkey)
00040            post: contents appended to self[id][fkey]
00041         """
00042         ann = self.AnnoDB[id]
00043         ann[fkey].append(contents)
00044 
00045     def DelField(self, id, fkey):
00046         """ pre: self[id].Anno.has_key(fkey)
00047            post: not AnnoDB[id].has_key(fkey) """
00048         del self.AnnoDB[id][fkey]
00049 
00050     def DelAnnotation(self, id):
00051         """ pre:  self.HasAnnotation(id)
00052            post: not self.HasAnnotation(id)
00053         """
00054         del self.AnnoDB[id]
00055         delattr(self[id], "Anno")
00056         
00057 
00058     def SaveAnnotations(self, file = None, message = ''):
00059         """
00060            Pre: True
00061         """
00062 
00063         if file != None:
00064             self.AnnoDB.SaveDBToFile(file)
00065         else:
00066             self.AnnoDB.Save(message)
00067 

Generated on Tue Sep 4 2012 15:38:01 for ScrumPy by  doxygen 1.7.1