[Tutor] object question

Kim Branson kim.branson at csiro.au
Mon May 31 06:38:20 EDT 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi all,

i'm having a go at using classes.  below is my attempt (a long time ago 
i posted a question to this list and received a great reply from Karl 
suggesting an object based approach, i filed it away to understand at a 
later date :)  This object  sets up some dictionaries, and  these are 
then filled with the update method. This changes to the appropriate 
directory at reads in a results file.

this file looks like:

  PK=  5.38 Qual=  1.58 PMF= -75.04 PMF_rb= -75.04 SMoG= -85.09 SMoG_H= 
- - -8.51 ChemScore= -29.01 Clash= 0.00 Int=  0.00 DockNRG= -13.07 
AutoDock= -15.71

my problem is in the matching done in the update method. the assignment 
of m=self.score_lines.search(line) does not
produce a object with <type 'NoneType'> and prints as None.  I've 
tested with  the test code i've attached.  I think its a scope issue as 
it seems to work when its not in the object?  Can someone explain this 
to me.

cheers

Kim

- - -----begin test code----
import re, string, os

path = os.getcwd()
results_path= path + "/dock"
os.chdir("%s" % results_path)

data =open("results_summary", 'r')
data= data.readlines()

score_lines =re.compile("""PK= (?P<score>.*) Qual= (?P<qual>.*) PMF= 
(?P<pmf>.*)\
PMF_rb= (?P<pmf_rb>.*) SMoG= (?P<smog>.*) SMoG_H= (?P<smog_h>.*) 
ChemScore= (?P<chemscore>.*)\
Clash= (?P<clash>.*) Int= (?P<int>.*) DockNRG= (?P<docknrg>.*) 
AutoDock= (?P<autodock>.*)""")

for line in data:
         #print line
         m=score_lines.search(line)
         #print type(m)
         print m.group("score")
         print m
         for grp, val in m.groupdict().items():
                 print grp,val

- - ---- end test code---



*/
***********Begin Code******
*/
import string, os, re

#we get the data from the SCORER outout

class scorer_values:
	score_lines =re.compile("""PK= (?P<score>.*) Qual= (?P<qual>.*) PMF= 
(?P<pmf>.*)\
	PMF_rb= (?P<pmf_rb>.*) SMoG= (?P<smog>.*) SMoG_H= (?P<smog_h>.*) 
ChemScore= (?P<chemscore>.*)\
	Clash= (?P<clash>.*) Int= (?P<int>.*) DockNRG= (?P<docknrg>.*) 
AutoDock= (?P<autodock>.*)""")
	def __init__(self):
		self.counter=0;
		#make the dictionaries
		self.tables=dict([(name,{}) for name in 
["score","qual","pmf","pmf_rb","smog","smog_h",\
							 "chemscore","clash","int","docknrg","autodock"]])
		
	#def __str__(self):
		#s = []
		#for key in self.tables:
			#s.append(key + '\n')
			#s.append("-" * len(key) + '\n')
			#items =self.tables[key].items()
			#items.sort()
			#for key, val in items:
				#s.append(str(key) + '->' + val + "\n")
		#return ''.join(s)
				
	def _pull(self,program="dock"):
		os.chdir("%s"% program)
		self.results=open("results_summary", 'r')
		return self.results.readlines()
	def update(self,program="dock"):
		for line in (self._pull(program)):
			m=self.score_lines.search(line)
			print type(m)
			print m
			if m:
				for grp,val in m.groupdict().items():
					tables=self.tables[grp]
					tables[self.counter]=val
					print  self.tables
				self.counter += 1
				
		
		



dock_values=scorer_values()
dock_values.update("dock")

print dock_values





Kim Branson
Diffraction and Theory
CSIRO Health Sciences and Nutrition
343 Royal Parade, Parkville
Melbourne
Ph +613 9662 7136
kim.branson at csiro.au

Kim Branson
Diffraction and Theory
CSIRO Health Sciences and Nutrition
343 Royal Parade, Parkville
Melbourne
Ph +613 9662 7136
kim.branson at csiro.au
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)

iD8DBQFAuwsjer2hmGbHcokRAvszAJ9Ws1Vcbc43OKDodbJjam03By+GHwCffdjV
F4VKwwXqeFkQVkS+fmzO1Ro=
=q1TV
-----END PGP SIGNATURE-----




More information about the Tutor mailing list