Back to index

python-biopython  1.60
Public Member Functions | Public Attributes | Static Public Attributes
Bio.UniGene.UniGene.UniGeneParser Class Reference

List of all members.

Public Member Functions

def reset
def parse
def feed
def handle_data
def start_a
def end_a
def start_b
def end_b
def extract_key
def start_table
def end_table
def start_tr
def end_tr
def start_td
def end_td
def print_item
def print_tags

Public Attributes

 text
 queue
 open_tag_stack
 open_tag
 key_waiting
 master_key
 context

Static Public Attributes

tuple handle = open( 'Hs13225.htm')
tuple undo_handle = Bio.File.UndoHandle( handle )
tuple unigene_parser = UniGeneParser()

Detailed Description

Definition at line 36 of file UniGene.py.


Member Function Documentation

Definition at line 89 of file UniGene.py.

00089 
00090     def end_a( self ):
00091         if( self.context == 'seq_info' ):
00092             if( self.open_tag != 'open_b' ):
00093                 if( self.key_waiting == '' ):
00094                     self.key_waiting = self.text
00095                     self.text = ''

Definition at line 103 of file UniGene.py.

00103 
00104     def end_b( self ):
00105         if( self.text[ :15 ] == 'UniGene Cluster' ):
00106             self.queue[ 'UniGene Cluster' ] = self.text[ 16: ]
00107             self.text = ''
00108         elif( self.key_waiting == '' ):
00109             self.extract_key()

Here is the call graph for this function:

Definition at line 145 of file UniGene.py.

00145 
00146     def end_table( self ):
00147         try:
00148             self.open_tag = self.open_tag_stack.pop()
00149         except:
00150             self.open_tag = 'open_html'
00151         self.key_waiting = ''

Definition at line 189 of file UniGene.py.

00189 
00190     def end_td( self ):
00191         try:
00192             self.open_tag = self.open_tag_stack.pop()
00193         except:
00194             self.open_tag = 'open_html'
00195         if( self.context == 'seq_info' ):
00196             self.text = self.text + ' '

Definition at line 157 of file UniGene.py.

00157 
00158     def end_tr( self ):
00159         try:
00160             self.open_tag = self.open_tag_stack.pop()
00161         except:
00162             self.open_tag = 'open_html'
00163         text = self.text
00164         if text:
00165             self.text = ''
00166             if( text[ 0 ] == ':' ):
00167                 text = text[ 1: ]
00168             text = string.join( string.split( text ) )
00169             if( ( self.context == 'general_info' ) or \
00170                 ( self.context == 'seq_info' ) ):
00171                 try:
00172                     contents = self.queue[ self.master_key ][ self.key_waiting ]
00173                     if( type( contents ) == type( [] ) ):
00174                         contents.append( text )
00175                     else:
00176                         self.queue[ self.master_key ][ self.key_waiting ] = \
00177                             [ contents , text ]
00178                 except:
00179                     self.queue[ self.master_key ][ self.key_waiting ] = text
00180 
00181 
00182                 self.key_waiting = ''
00183 
00184 

Definition at line 110 of file UniGene.py.

00110 
00111     def extract_key( self ):
00112         text = string.strip( self.text )
00113         key = string.join( string.split( text ) )
00114         words = string.split( key )
00115         key = string.join( words[ :2 ] )
00116         self.text = ''
00117 
00118         try:
00119             self.open_tag = self.open_tag_stack.pop()
00120         except:
00121             self.open_tag = 'open_html'
00122         if( self.open_tag == 'open_table_data' ):
00123             if( self.context == 'general_info' ):
00124                 if( self.key_waiting == '' ):
00125                     self.key_waiting = key
00126                     self.text = ''
00127             elif( self.context == 'seq_info' ):
00128                 if( text == 'Key to Symbols' ):
00129                     self.context = 'legend'
00130                     self.master_key = key
00131         elif( self.context == 'general_info' ):
00132             self.master_key = key
00133             if( string.find( key, 'SEQUENCE' ) != -1 ):
00134                 self.context = 'seq_info'
00135             self.queue[ key ] = UserDict.UserDict()
00136         elif( self.context == 'seq_info' ):
00137             self.queue[ key ] = UserDict.UserDict()
00138             self.master_key = key
00139 
00140 

Here is the caller graph for this function:

def Bio.UniGene.UniGene.UniGeneParser.feed (   self,
  handle 
)

Definition at line 61 of file UniGene.py.

00061 
00062     def feed( self, handle ):
00063         if isinstance(handle, Bio.File.UndoHandle):
00064             uhandle = handle
00065         else:
00066             uhandle = Bio.File.UndoHandle(handle)
00067         text = ''
00068         while 1:
00069             line = uhandle.readline()
00070             line = string.strip( line )
00071             if( line == '' ):
00072                 break
00073             text = text + ' ' + line
00074 
00075         sgmllib.SGMLParser.feed( self, text )
00076 
00077 

Here is the caller graph for this function:

def Bio.UniGene.UniGene.UniGeneParser.handle_data (   self,
  newtext 
)

Definition at line 78 of file UniGene.py.

00078 
00079     def handle_data(self, newtext ):
00080         newtext = string.strip( newtext )
00081         self.text = self.text + newtext

def Bio.UniGene.UniGene.UniGeneParser.parse (   self,
  handle 
)

Definition at line 48 of file UniGene.py.

00048 
00049     def parse( self, handle ):
00050         self.reset()
00051         self.feed( handle )
00052         for key in self.queue:
00053             if( self.queue[ key ] == {} ):
00054                 if( key[ :15 ] == 'UniGene Cluster' ):
00055                     self.queue[ 'UniGene Cluster' ] = key[ 16: ]
00056                 del self.queue[ key ]
00057         return self.queue
00058 
00059 #
00060 # Assumes an empty line between records
#

Here is the call graph for this function:

def Bio.UniGene.UniGene.UniGeneParser.print_item (   self,
  item,
  level = 1 
)

Definition at line 197 of file UniGene.py.

00197 
00198     def print_item( self, item, level = 1 ):
00199         indent = '    '
00200         for j in range( 0, level ):
00201             indent = indent + '    '
00202         if( type( item ) == type( '' ) ):
00203             if( item != '' ):
00204                 print '%s%s' % ( indent, item )
00205         elif( type( item ) == type([])):
00206             for subitem in item:
00207                 self.print_item( subitem, level + 1 )
00208         elif( isinstance( item, UserDict.UserDict ) ):
00209             for subitem in item:
00210                 print '%skey is %s' % ( indent, subitem )
00211                 self.print_item( item[ subitem ], level + 1 )
00212         else:
00213             print item

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 214 of file UniGene.py.

00214 
00215     def print_tags( self ):
00216         for key in self.queue:
00217             print 'key %s' % key
00218             self.print_item( self.queue[ key ] )
00219 
00220 
00221 
if( __name__ == '__main__' ):

Here is the call graph for this function:

Definition at line 38 of file UniGene.py.

00038 
00039     def reset( self ):
00040         sgmllib.SGMLParser.reset( self )
00041         self.text = ''
00042         self.queue = UserDict.UserDict()
00043         self.open_tag_stack = []
00044         self.open_tag = 'open_html'
00045         self.key_waiting = ''
00046         self.master_key = ''
00047         self.context = 'general_info'

Here is the caller graph for this function:

def Bio.UniGene.UniGene.UniGeneParser.start_a (   self,
  attrs 
)

Definition at line 82 of file UniGene.py.

00082 
00083     def start_a( self, attrs ):
00084         if( self.context == 'seq_info' ):
00085             if( self.open_tag != 'open_b' ):
00086                 self.text = ''
00087 
00088 #        self.queue.append( attrs )

def Bio.UniGene.UniGene.UniGeneParser.start_b (   self,
  attrs 
)

Definition at line 96 of file UniGene.py.

00096 
00097     def start_b( self, attrs ):
00098 
00099         self.open_tag_stack.append( self.open_tag )
00100         self.open_tag = 'open_b'
00101         if( self.key_waiting == '' ):
00102             self.text = ''

def Bio.UniGene.UniGene.UniGeneParser.start_table (   self,
  attrs 
)

Definition at line 141 of file UniGene.py.

00141 
00142     def start_table( self, attrs ):
00143         self.open_tag_stack.append( self.open_tag )
00144         self.open_tag = 'open_table'

def Bio.UniGene.UniGene.UniGeneParser.start_td (   self,
  attrs 
)

Definition at line 185 of file UniGene.py.

00185 
00186     def start_td( self, attrs ):
00187         self.open_tag_stack.append( self.open_tag )
00188         self.open_tag = 'open_table_data'

def Bio.UniGene.UniGene.UniGeneParser.start_tr (   self,
  attrs 
)

Definition at line 152 of file UniGene.py.

00152 
00153     def start_tr( self, attrs ):
00154         self.open_tag_stack.append( self.open_tag )
00155         self.open_tag = 'open_table_row'
00156         self.text = ''


Member Data Documentation

Definition at line 46 of file UniGene.py.

tuple Bio.UniGene.UniGene.UniGeneParser.handle = open( 'Hs13225.htm') [static]

Definition at line 222 of file UniGene.py.

Definition at line 44 of file UniGene.py.

Definition at line 45 of file UniGene.py.

Definition at line 43 of file UniGene.py.

Definition at line 42 of file UniGene.py.

Definition at line 41 of file UniGene.py.

Definition at line 40 of file UniGene.py.

Definition at line 223 of file UniGene.py.

Definition at line 224 of file UniGene.py.


The documentation for this class was generated from the following file: