Package biana :: Package BianaObjects :: Module ExternalDatabase'
[hide private]
[frames] | no frames]

Source Code for Module biana.BianaObjects.ExternalDatabase'

  1  """ 
  2      BIANA: Biologic Interactions and Network Analysis 
  3      Copyright (C) 2009  Javier Garcia-Garcia, Emre Guney, Baldo Oliva 
  4   
  5      This program is free software: you can redistribute it and/or modify 
  6      it under the terms of the GNU General Public License as published by 
  7      the Free Software Foundation, either version 3 of the License, or 
  8      (at your option) any later version. 
  9   
 10      This program is distributed in the hope that it will be useful, 
 11      but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 13      GNU General Public License for more details. 
 14   
 15      You should have received a copy of the GNU General Public License 
 16      along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 17   
 18  """ 
 19   
 20  import time 
 21  import sets 
 22   
 23   
24 -class ExternalDatabase(object):
25 """ 26 Class to represent an external database (any database giving biologic relevant information) 27 """ 28 29
30 - def __init__(self, databaseName, databaseVersion, databaseFile, databaseDescription, defaultExternalEntityAttribute, databaseDate=None, externalDatabaseID=None, isPromiscuous=False):
31 """ 32 Initializes a ExternalDatabase Object 33 34 "databaseName" is the name for the external database (i.e. swissprot, IntAct, Reactome...) 35 36 "datavaseVersion" is the version of the database. The combination of databaseName and databaseVersion must be unique! 37 38 "databaseFile" is the parsed database file. If there are multiple files, it is an empty string 39 40 "databaseDescription" is a longer description of the database (for example, "public repository of interactions of ncbi", etc.) 41 42 "externalDatabaseID" is a unique identifier for the database. When parsing it should not be added, only when this information is persistent in the database 43 44 "defaultExternalEntityAttribute" is the default attribute type of the data an external database is providing 45 46 "databaseDate" Parsing date. If it is None, automatically assigns to current date to it 47 "isPromiscuous" Flag deciding whether database gives information that is going to be added to more than one user entiries 48 """ 49 50 self.databaseName = databaseName.lower() 51 self.databaseVersion = databaseVersion.lower() 52 self.databaseFile = databaseFile 53 self.databaseDescription = databaseDescription 54 self.defaultExternalEntityAttribute = defaultExternalEntityAttribute 55 self.isPromiscuous = isPromiscuous 56 57 self.externalDatabaseID = externalDatabaseID # Only it is setted to a value when it is inserted or loaded from the database. If it is not loaded, it is None 58 59 if( databaseDate is None ): 60 date = time.localtime() 61 actual_date = "%s-%s-%s" %(date[0],date[1],date[2]) 62 self.databaseDate = actual_date 63 else: 64 self.databaseDate = databaseDate 65 66 self.valid_eE_attributes = sets.Set() 67 self.valid_eEr_attributes = sets.Set() 68 self.valid_eE_types = sets.Set() 69 self.valid_eEr_types = sets.Set() 70 71 self.parsing_time = None # Parsing time is set to None by default
72
73 - def add_valid_external_entity_attribute_type(self, attribute_identifier):
74 self.valid_eE_attributes.add(attribute_identifier.lower())
75
76 - def add_valid_external_entity_relation_attribute_type(self, attribute_identifier):
77 self.valid_eEr_attributes.add(attribute_identifier.lower())
78
79 - def add_valid_external_entity_type(self, eE_type):
80 self.valid_eE_types.add(eE_type.lower())
81
82 - def add_valid_external_entity_relation_type(self, eEr_type):
83 self.valid_eEr_types.add(eEr_type.lower())
84
86 return self.valid_eE_attributes
87
89 return self.valid_eEr_attributes
90
92 return self.valid_eE_types
93
94 - def has_external_entity_type(self, eE_type):
95 """ 96 Checks if this external database contains external entities of the type "eE_type" 97 """ 98 return self.valid_eE_types.has_key(eE_type)
99
101 return self.valid_eEr_types
102
103 - def get_name(self):
104 return self.databaseName
105
106 - def get_version(self):
107 return self.databaseVersion
108
109 - def get_parsed_file(self):
110 return self.databaseFile
111
112 - def get_parsing_date(self):
113 return self.databaseDate
114
115 - def get_description(self):
116 return self.databaseDescription
117
118 - def get_default_eE_attribute(self):
119 return self.defaultExternalEntityAttribute
120
121 - def get_id(self):
122 return self.externalDatabaseID
123
124 - def set_id(self, externalDatabaseID):
125 self.externalDatabaseID = externalDatabaseID
126
127 - def set_parsing_time(self, time):
128 self.parsing_time = time
129
130 - def get_parsing_time(self):
131 return self.parsing_time
132
133 - def get_promiscuity(self):
134 return self.isPromiscuous
135
136 - def __str__(self):
137 return "%s [%s]" %(self.databaseName,self.databaseVersion)
138