comparison commons/core/parsing/SsrParser.py @ 6:769e306b7933

Change the repository level.
author yufei-luo
date Fri, 18 Jan 2013 04:54:14 -0500
parents
children
comparison
equal deleted inserted replaced
5:ea3082881bf8 6:769e306b7933
1 # Copyright INRA (Institut National de la Recherche Agronomique)
2 # http://www.inra.fr
3 # http://urgi.versailles.inra.fr
4 #
5 # This software is governed by the CeCILL license under French law and
6 # abiding by the rules of distribution of free software. You can use,
7 # modify and/ or redistribute the software under the terms of the CeCILL
8 # license as circulated by CEA, CNRS and INRIA at the following URL
9 # "http://www.cecill.info".
10 #
11 # As a counterpart to the access to the source code and rights to copy,
12 # modify and redistribute granted by the license, users are provided only
13 # with a limited warranty and the software's author, the holder of the
14 # economic rights, and the successive licensors have only limited
15 # liability.
16 #
17 # In this respect, the user's attention is drawn to the risks associated
18 # with loading, using, modifying and/or developing or reproducing the
19 # software by the user in light of its specific status of free software,
20 # that may mean that it is complicated to manipulate, and that also
21 # therefore means that it is reserved for developers and experienced
22 # professionals having in-depth computer knowledge. Users are therefore
23 # encouraged to load and test the software's suitability as regards their
24 # requirements in conditions enabling the security of their systems and/or
25 # data to be ensured and, more generally, to use and operate it in the
26 # same conditions as regards security.
27 #
28 # The fact that you are presently reading this means that you have had
29 # knowledge of the CeCILL license and that you accept its terms.
30
31 import sys
32
33 ## this class can parse a Ssr results output file. SSR.pl is developped by S.Cartinhour. (5/2000)
34 #
35 class SsrParser(object):
36
37
38 def __init__(self, BES_name='', BES_redundancy='', SSR_nbNucleotides='', SSR_Motif='', SSR_Motif_number='', SSR_start='', SSR_end='', BES_size=''):
39 self._BesName = BES_name
40 self._BesRedundancy = BES_redundancy
41 self._SsrNbNucleotides = SSR_nbNucleotides
42 self._SsrMotif = SSR_Motif
43 self._SsrMotifNumber = SSR_Motif_number
44 self._SsrStart = SSR_start
45 self._SsrEnd = SSR_end
46 self._BesSize = BES_size
47
48 def __eq__(self, o):
49 return self._BesName == o._BesName and self._BesRedundancy == o._BesRedundancy and self._SsrNbNucleotides == o._SsrNbNucleotides and self._SsrMotif == o._SsrMotif and self._SsrMotifNumber == o._SsrMotifNumber and self._SsrStart == o._SsrStart and self._SsrEnd == o._SsrEnd and self._BesSize == o._BesSize
50
51 def setBesName(self, BES_Name):
52 self._BesName = BES_Name
53
54 def setBesRedundancy(self, BES_redundancy):
55 self._BesRedundancy = BES_redundancy
56
57 def setSsrNbNucleotides(self, SSR_nbNucleotides):
58 self._SsrNbNucleotides = SSR_nbNucleotides
59
60 def setSsrMotif(self, SSR_Motif):
61 self._SsrMotif = SSR_Motif
62
63 def setSsrMotifNumber(self, SSR_Motif_number):
64 self._SsrMotifNumber = SSR_Motif_number
65
66 def setSsrStart(self, SSR_start):
67 self._SsrStart = SSR_start
68
69 def setSsrEnd(self, SSR_end):
70 self._SsrEnd = SSR_end
71
72 def setBesSize(self, BES_size):
73 self._BesSize = BES_size
74
75 def getBesName(self):
76 return self._BesName
77
78 def getBesRedundancy(self):
79 return self._BesRedundancy
80
81 def getSsrNbNucleotides(self):
82 return self._SsrNbNucleotides
83
84 def getSsrMotif(self):
85 return self._SsrMotif
86
87 def getSsrMotifNumber(self):
88 return self._SsrMotifNumber
89
90 def getSsrStart(self):
91 return self._SsrStart
92
93 def getSsrEnd(self):
94 return self._SsrEnd
95
96 def getBesSize(self):
97 return self._BesSize
98
99 def setAttributes(self, lResults, iCurrentLineNumber):
100 error = False
101
102 if lResults[0] != '':
103 self.setBesName(lResults[0])
104 else:
105 sys.stderr.write("WARNING: The field BES Name is empty in SSR results file in line %s\n" % iCurrentLineNumber)
106 error = True
107
108 if lResults[1] != '':
109 self.setBesRedundancy(lResults[1])
110 else:
111 sys.stderr.write("WARNING: The field BES Redundancy is empty in SSR results file in line %s\n" % iCurrentLineNumber)
112 error = True
113
114 if lResults[2] != '':
115 self.setSsrNbNucleotides(lResults[2])
116 else:
117 sys.stderr.write("WARNING: The field SSR Number Nucleotides is empty in SSR results file in line %s\n" % iCurrentLineNumber)
118 error = True
119
120 if lResults[3] != '':
121 self.setSsrMotif(lResults[3])
122 else:
123 sys.stderr.write("WARNING: The field SSR Motif is empty in SSR results file in line %s\n" % iCurrentLineNumber)
124 error = True
125
126 if lResults[4] != '':
127 self.setSsrMotifNumber(lResults[4])
128 else:
129 sys.stderr.write("WARNING: The field SSR Motif Number is empty in SSR results file in line %s\n" % iCurrentLineNumber)
130 error = True
131
132 if lResults[5] != '':
133 self.setSsrStart(lResults[5])
134 else:
135 sys.stderr.write("WARNING: The field SSR Start is empty in SSR results file in line %s\n" % iCurrentLineNumber)
136 error = True
137
138 if lResults[6] != '':
139 self.setSsrEnd(lResults[6])
140 else:
141 sys.stderr.write("WARNING: The field SSR End is empty in SSR results file in line %s\n" % iCurrentLineNumber)
142 error = True
143
144 if lResults[7] != '':
145 self.setBesSize(lResults[7])
146 else:
147 sys.stderr.write("WARNING: The field BES Size is empty in SSR results file in line %s\n" % iCurrentLineNumber)
148 error = True
149
150 if error == True:
151 self._setAllToNull()
152
153 def setAttributesFromString(self, ssrLine, iCurrentLineNumber ="", fieldSeparator ="\t"):
154 ssrLine = ssrLine.rstrip()
155 lSsrLineItem = ssrLine.split(fieldSeparator)
156 if len(lSsrLineItem) < 8:
157 sys.stderr.write("WARNING: The line %s is not a valid SSR Result line\n" % iCurrentLineNumber)
158 else:
159 self.setAttributes(lSsrLineItem, iCurrentLineNumber)
160
161 def _setAllToNull(self):
162 self._BesName = ''
163 self._BesRedundancy = ''
164 self._SsrNbNucleotides = ''
165 self._SsrMotif = ''
166 self._SsrMotifNumber = ''
167 self._SsrStart = ''
168 self._SsrEnd = ''
169 self._BesSize = ''
170