comparison commons/pyRepetUnit/profilesDB/Profiles.py @ 18:94ab73e8a190

Uploaded
author m-zytnicki
date Mon, 29 Apr 2013 03:20:15 -0400
parents
children
comparison
equal deleted inserted replaced
17:b0e8584489e6 18:94ab73e8a190
1 import re
2
3 #------------------------------------------------------------------------------
4
5 class Profiles:
6 '''
7 Hmm profile Class
8 Attributes are name, desc, length, accNumber, GA_cut_off and retrieve
9 '''
10
11 #--------------------------------------------------------------------------
12
13 def __init__( self, name="", desc="", length=0, accNumber = "", GA_cut_off = 0, retrieve = False ):
14 self.name = name
15 self.desc = desc
16 self.length = length
17 self.accNumber = accNumber
18 self.GA_cut_off = GA_cut_off
19 self.retrieve = retrieve
20 self.tab_profile = []
21
22 #--------------------------------------------------------------------------
23
24 def _noProfileInFile(self):
25 self.name = None
26 self.desc = None
27 self.length = None
28 self.accNumber = None
29 self.GA_cut_off = None
30
31 #--------------------------------------------------------------------------
32
33 def _initialisation(self):
34 self.name = ""
35 self.desc = ""
36 self.length = 0
37 self.accNumber = ""
38 GA_cut_off = 0
39 self.tab_profile = []
40
41 #--------------------------------------------------------------------------
42
43 def read( self, hmmFile ):
44 '''
45 Read a profile and characterize the object profile
46 attributes name, length, desc, accNumber and GA_cut_off are specified
47 '''
48 line = hmmFile.readline()
49 if line == "":
50 self._noProfileInFile()
51 return
52 self._initialisation()
53 if self.retrieve:
54 self.tab_profile.append(line)
55 while not re.match("\/\/.*", line):
56 line = hmmFile.readline()
57 if self.retrieve:
58 self.tab_profile.append(line)
59 name = re.match("NAME\s*(.*)", line)
60 if name:
61 self.name = name.group(1)
62 desc = re.match("DESC\s*(.*)", line)
63 if desc:
64 self.desc = desc.group(1)
65 length = re.match("LENG\s*(.*)", line)
66 if length:
67 self.length = int(length.group(1))
68 accNumber = re.match("ACC\s*(.*)", line)
69 if accNumber:
70 self.accNumber = accNumber.group(1)
71 GA_cut_off = re.match("GA\s*\d*\.\d*\s*(.*);", line)
72 if GA_cut_off:
73 self.GA_cut_off = float(GA_cut_off.group(1))
74 else :
75 if (self.GA_cut_off == 0):
76 self.GA_cut_off = "NA"
77 if self.retrieve:
78 return self.tab_profile
79 else:
80 return 1
81
82 #--------------------------------------------------------------------------
83
84 def readAndRetrieve( self, hmmFile ):
85 '''
86 Read a profile and characterize the object profile
87 attributes name, length, desc, accNumber and GA_cut_off are specified
88 And a list of each line of profile is returned
89 '''
90 self.retrieve = True
91 return self.read(hmmFile)