Package biana :: Package BianaParser :: Module XMLNode
[hide private]
[frames] | no frames]

Source Code for Module biana.BianaParser.XMLNode

 1   
 2  """ 
 3  File        : uniprot2piana.py 
 4  Author      : Ramon Aragues, Javier Garcia Garcia 
 5  Creation    : 16.3.2004 
 6  Modified    : Javier Garcia Garcia December 2007 
 7  Contents    : fills up tables in database piana with information from uniprot 
 8  Called from :  
 9   
10  ======================================================================================================= 
11   
12  This file implements a program that fills up tables in database piana with information of uniprot databases 
13   
14  This parser uses biopython libraries and methods 
15   
16  Command line option '--help' describes usage of this program 
17   
18  For more details on how to use it, read piana/README.populate_piana_db 
19  """ 
20   
21   
22 -class XMLNode(object):
23
24 - def __init__(self, name, attrs):
25 26 self.name = name 27 self.attrs = attrs 28 self.childs = {} 29 self.value = []
30 31
32 - def addChild(self, XMLNodeChild):
33 self.childs.setdefault(XMLNodeChild.name.lower(), []).append(XMLNodeChild)
34
35 - def getValue(self):
36 return "".join(self.value)
37
38 - def addValue(self, value):
39 self.value.append(value)
40
41 - def getChilds(self, child_name=None):
42 #print [ y.name for x in self.childs.values() for y in x ] 43 if child_name is None: 44 c = [] 45 [ c.extend(x) for x in self.childs.values() ] 46 return c 47 return self.childs[child_name.lower()]
48
49 - def getChild(self, child_name):
50 if( len(self.childs[child_name.lower()])!=1 ): 51 #raise ValueError("You are trying to obtain a single child when it has %s childs" %(len(self.childs[child_name.lower()]) ) ) 52 return None 53 return self.childs[child_name.lower()][0]
54