Skip to content

Commit

Permalink
updated Andreas Kuntazagk's fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jchang committed Jun 24, 2003
1 parent 0f8a6ce commit e8d3999
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 77 deletions.
6 changes: 3 additions & 3 deletions Bio/Align/AlignInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,10 @@ def _get_column_info_content(self, obs_freq, e_freq_table, log_base,
# check the expected freq information to make sure it is good
for key in obs_freq.keys():
if (key != self.alignment._alphabet.gap_char and
key not in e_freq_table.data.keys()):
key not in e_freq_table):
raise ValueError("Expected frequency letters %s" +
" do not match observed %s"
% (e_freq_table.data.keys(), obs_freq.keys() -
% (e_freq_table.keys(), obs_freq.keys() -
[self.alignment._alphabet.gap_char]))

total_info = 0
Expand All @@ -549,7 +549,7 @@ def _get_column_info_content(self, obs_freq, e_freq_table, log_base,
# should just be the observed frequency.
if letter != self.alignment._alphabet.gap_char:
if e_freq_table:
inner_log = obs_freq[letter] / e_freq_table.data[letter]
inner_log = obs_freq[letter] / e_freq_table[letter]
else:
inner_log = obs_freq[letter] / random_expected
# if the observed frequency is zero, we don't add any info to the
Expand Down
9 changes: 4 additions & 5 deletions Bio/CDD/Record.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,16 @@ class Record( dict ):
"""
def __init__(self):
dict.__init__( self )
self.data[ 'references' ] = []
self.data[ 'alignment_lookup' ] = {}

self[ 'references' ] = []
self[ 'alignment_lookup' ] = {}

def __str__( self ):
output = ''
keys = self.data.keys()
keys = self.keys()
keys.sort()
for key in keys:
output = output + '%s:\n\n' % key.upper()
contents = self.data[ key ]
contents = self[ key ]
if( type( contents ) == type( '' ) ):
if( key == 'Sequence' ):
output = output + out_multiline( contents )
Expand Down
21 changes: 10 additions & 11 deletions Bio/Ndb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,16 @@
class Record( dict ):

def __init__( self ):
self.data = {}
self.data[ 'Id' ] = ''
self.data[ 'Features' ] = ''
self.data[ 'Name' ] = ''
self.data[ 'Sequence' ] = Crystal( {} )
self.data[ 'Citation' ] = Reference()
self.data[ 'Space Group' ] = ''
self.data[ 'Cell Constants' ] = {}
self.data[ 'Crystallization Conditions' ] = []
self.data[ 'Refinement' ] = ''
self.data[ 'Coordinates' ] = ''
self[ 'Id' ] = ''
self[ 'Features' ] = ''
self[ 'Name' ] = ''
self[ 'Sequence' ] = Crystal( {} )
self[ 'Citation' ] = Reference()
self[ 'Space Group' ] = ''
self[ 'Cell Constants' ] = {}
self[ 'Crystallization Conditions' ] = []
self[ 'Refinement' ] = ''
self[ 'Coordinates' ] = ''

def __str__( self ):
keys = self.keys()
Expand Down
18 changes: 6 additions & 12 deletions Bio/PropertyManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,8 @@
# The new elements are always dictionaries.
class CreateDict(dict):
def __getitem__(self, key):
try:
return self.data[key]
except KeyError:
pass
x = {}
self.data[key] = x
return x

return self.setdefault(key,{})

class PropertyManager:
def __init__(self):
self.class_property = CreateDict()
Expand All @@ -41,13 +35,13 @@ def resolve(self, obj, property):
def resolve_class(self, klass, property):
# Hopefully, we'll find the hit right away
try:
return self.class_property.data[klass][property]
return self.class_property[klass][property]
except KeyError:
pass

# Is there a property resolver?
try:
return self.class_property_resolver.data[klass][property](
return self.class_property_resolver[klass][property](
self, klass, property)
except KeyError:
pass
Expand All @@ -67,11 +61,11 @@ def resolve_class(self, klass, property):
while bases:
base = bases.pop()
try:
return self.class_property.data[base][property]
return self.class_property[base][property]
except KeyError:
pass
try:
return self.class_property_resolver.data[base][property](
return self.class_property_resolver[base][property](
self, klass, property)
except KeyError:
pass
Expand Down
3 changes: 1 addition & 2 deletions Bio/SubsMat/FreqTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
class FreqTable(dict):

def _freq_from_count(self):
self.data = {}
sum = 0.
for i in self.count.values():
sum = sum + i
Expand All @@ -72,7 +71,7 @@ def __init__(self,in_dict,dict_type,alphabet=None):
self._freq_from_count()
elif dict_type == FREQ:
self.count = {}
self.data = in_dict
self.update(in_dict)
else:
raise ValueError,"bad dict_type"
if not alphabet:
Expand Down
8 changes: 3 additions & 5 deletions Bio/SubsMat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,8 @@ def __init__(self,data=None, alphabet=None,
data == None)
if data == None:
data = {}
if type(data) == type({}):
self.data = copy.copy(data)
else:
self.data = copy.copy(data.data)
self.update(data)
if alphabet == None:
alphabet = Alphabet.Alphabet()
assert Alphabet.generic_alphabet.contains(alphabet)
Expand Down Expand Up @@ -277,8 +275,8 @@ def print_full_mat(self,f=None,format="%4d",topformat="%4s",
# printing
assert non_sym == None or type(non_sym) == type(1.) or \
type(non_sym) == type(1)
full_mat = copy.copy(self.data)
for i in full_mat.keys():
full_mat = copy.copy(self)
for i in self:
if i[0] <> i[1]:
full_mat[(i[1],i[0])] = full_mat[i]
if not alphabet:
Expand Down
68 changes: 29 additions & 39 deletions Martel/Parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,57 +129,51 @@ def _do_callback(s, begin, end, taglist, cont_handler, attrlookup):
'cont_handler' is the SAX ContentHandler
'attrlookup' is a dict mapping the encoded tag name to the element info
"""
for item in taglist:
tag, l, r, subtags = item
# bind functions to local names for a slight speedup
characters = cont_handler.characters
startElement = cont_handler.startElement
endElement = cont_handler.endElement

for tag, l, r, subtags in taglist:
# If the tag's beginning is after the current position, then
# the text from here to the tag's beginning are characters()
assert begin <= l, "begin = %d and l = %d" % (begin, l)
if begin < l:
cont_handler.characters(s[begin:l])
else:
# Some integrity checking
assert begin == l, "begin = %d and l = %d" % (begin, l)

if tag[0] == ">":
if tag == ">ignore":
# Named groups doesn't create ">ignore" tags, so pass them on
# to the ContentHandler. Unnamed groups still need a name so
# mxTextTools can create subtags for them. I named them
# ">ignore" - don't create events for them.
pass

elif tag[:2] == ">G":
characters(s[begin:l])

if tag.startswith(">"):
# Named groups doesn't create ">ignore" tags, so pass them on
# to the ContentHandler. Unnamed groups still need a name so
# mxTextTools can create subtags for them. I named them
# ">ignore" - don't create events for them.
if not tag == ">ignore":
assert tag.startswith(">G"),"Unknown special tag %s" % repr(tag)
# This needs a lookup to get the full attrs
realtag, attrs = attrlookup[tag]
cont_handler.startElement(realtag, attrs)

else:
raise AssertionError("Unknown special tag %s" % repr(tag))
startElement(realtag, attrs)

else:
# Normal tags
cont_handler.startElement(tag, _attribute_list)
startElement(tag, _attribute_list)

# Recurse if it has any children
if subtags:
_do_callback(s, l, r, subtags, cont_handler, attrlookup)
else:
cont_handler.characters(s[l:r])
characters(s[l:r])
begin = r

if tag[0] == ">":
if tag == ">ignore":
pass
elif tag[:2] == ">G":
if tag.startswith(">"):
if tag.startswith(">G"):
realtag, attrs = attrlookup[tag]
cont_handler.endElement(realtag)
else:
raise AssertionError("Unknown special tag %s" % repr(tag))
endElement(realtag)
else:
cont_handler.endElement(tag)
endElement(tag)

# anything after the last tag and before the end of the current
# range are characters
if begin < end:
cont_handler.characters(s[begin:end])
characters(s[begin:end])

def _do_dispatch_callback(s, begin, end, taglist,
start_table_get, cont_handler, save_stack,
Expand All @@ -199,16 +193,12 @@ def _do_dispatch_callback(s, begin, end, taglist,
'cont_handler' is the SAX ContentHandler
'attrlookup' is a dict mapping the encoded tag name to the element info
"""
for item in taglist:
tag, l, r, subtags = item
for tag, l, r, subtags in taglist:
# If the tag's beginning is after the current position, then
# the text from here to the tag's beginning are characters()
if begin < l:
if save_stack:
cont_handler._save_text += s[begin:l]
else:
# Some integrity checking
assert begin == l, "begin = %d and l = %d" % (begin, l)
assert begin <= l, "begin = %d and l = %d" % (begin, l)
if begin < l and save_stack:
cont_handler._save_text += s[begin:l]

# Normal tags, see if the start function exists and call it
# ** This is a bit of a hack, in that this check also occurs
Expand Down

0 comments on commit e8d3999

Please sign in to comment.