annotate commons/core/parsing/SsrParser.py @ 32:3441fe98a2ba

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