6
|
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
|
|
32 from commons.core.checker.CheckerException import CheckerException
|
|
33
|
|
34 class VarscanHit(object):
|
|
35
|
|
36 def __init__(self, chrom = "", position = "", ref = "", var = "", readsRef = "", readsVar = "", varFreq = "", strandsRef = "", strandsVar = "", qualRef = "", qualVar = "", pValue = ""):
|
|
37 self._chrom = chrom
|
|
38 self._position = position
|
|
39 self._ref = ref
|
|
40 self._var = var
|
|
41 self._readsRef = readsRef
|
|
42 self._readsVar = readsVar
|
|
43 self._varFreq = varFreq
|
|
44 self._strandsRef = strandsRef
|
|
45 self._strandsVar = strandsVar
|
|
46 self._qualRef = qualRef
|
|
47 self._qualVar = qualVar
|
|
48 self._pValue = pValue
|
|
49
|
|
50 ## Equal operator
|
|
51 #
|
|
52 # @param o a VarscanFileAnalysis instance
|
|
53 #
|
|
54 def __eq__(self, o):
|
|
55 return self._chrom == o._chrom and self._position == o._position and self._ref == o._ref and self._var == o._var
|
|
56
|
|
57 def setChrom(self, chromosome):
|
|
58 self._chrom = chromosome
|
|
59
|
|
60 def setPosition(self, position):
|
|
61 self._position = position
|
|
62
|
|
63 def setRef(self, referenceAllele):
|
|
64 self._ref = referenceAllele
|
|
65
|
|
66 def setVar(self, variantAllele):
|
|
67 self._var = variantAllele
|
|
68
|
|
69 def setReadsRef(self, readsRef):
|
|
70 self._readsRef = readsRef
|
|
71
|
|
72 def setReadsVar(self, readsVar):
|
|
73 self._readsVar = readsVar
|
|
74
|
|
75 def setVarFreq(self, varFreq):
|
|
76 self._varFreq = varFreq
|
|
77
|
|
78 def setStrandsRef(self, strandsRef):
|
|
79 self._strandsRef = strandsRef
|
|
80
|
|
81 def setStrandsVar(self, strandsVar):
|
|
82 self._strandsVar = strandsVar
|
|
83
|
|
84 def setQualRef(self, qualRef):
|
|
85 self._qualRef = qualRef
|
|
86
|
|
87 def setQualVar(self, qualVar):
|
|
88 self._qualVar = qualVar
|
|
89
|
|
90 def setPValue(self, pValue):
|
|
91 self._pValue = pValue
|
|
92
|
|
93 def getChrom(self):
|
|
94 return self._chrom
|
|
95
|
|
96 def getPosition(self):
|
|
97 return self._position
|
|
98
|
|
99 def getRef(self):
|
|
100 return self._ref
|
|
101
|
|
102 def getVar(self):
|
|
103 return self._var
|
|
104
|
|
105 def getReadsRef(self):
|
|
106 return self._readsRef
|
|
107
|
|
108 def getReadsVar(self):
|
|
109 return self._readsVar
|
|
110
|
|
111 def getVarFreq(self):
|
|
112 return self._varFreq
|
|
113
|
|
114 def getStrandsRef(self):
|
|
115 return self._strandsRef
|
|
116
|
|
117 def getStrandsVar(self):
|
|
118 return self._strandsVar
|
|
119
|
|
120 def getQualRef(self):
|
|
121 return self._qualRef
|
|
122
|
|
123 def getQualVar(self):
|
|
124 return self._qualVar
|
|
125
|
|
126 def getPValue(self):
|
|
127 return self._pValue
|
|
128
|
|
129 def getHeader(self):
|
|
130 return "Chrom\tPosition\tRef\tVar\tReads1\tReads2\tVarFreq\tStrands1\tStrands2\tQual1\tQual2\tPvalue\n"
|
|
131
|
|
132 def getVarscanLine(self):
|
|
133 return "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n" % (self.getChrom(), self.getPosition(), self.getRef(), self.getVar(), self.getReadsRef(), self.getReadsVar(), self.getVarFreq(), self.getStrandsRef(), self.getStrandsVar(), self.getQualRef(), self.getQualVar(), self.getPValue())
|
|
134
|
|
135 def setAttributes(self, lResults, iCurrentLineNumber):
|
|
136 if lResults[0] != '':
|
|
137 self.setChrom(lResults[0])
|
|
138 else:
|
|
139 raise CheckerException ("The field Chrom is empty in varscan file in line %s" % iCurrentLineNumber)
|
|
140 if lResults[1] != '':
|
|
141 self.setPosition(lResults[1])
|
|
142 else:
|
|
143 raise CheckerException ("The field Position is empty in varscan file in line %s" % iCurrentLineNumber)
|
|
144 if lResults[2] != '':
|
|
145 self.setRef(lResults[2])
|
|
146 else:
|
|
147 raise CheckerException ("The field Ref is empty in varscan file in line %s" % iCurrentLineNumber)
|
|
148 if lResults[3] != '':
|
|
149 self.setVar(lResults[3])
|
|
150 else:
|
|
151 raise CheckerException ("The field Var is empty in varscan file in line %s" % iCurrentLineNumber)
|
|
152 if lResults[4] != '':
|
|
153 self.setReadsRef(lResults[4])
|
|
154 if lResults[5] != '':
|
|
155 self.setReadsVar(lResults[5])
|
|
156 if lResults[6] != '':
|
|
157 self.setVarFreq(lResults[6])
|
|
158 if lResults[7] != '':
|
|
159 self.setStrandsRef(lResults[7])
|
|
160 if lResults[8] != '':
|
|
161 self.setStrandsVar(lResults[8])
|
|
162 if lResults[9] != '':
|
|
163 self.setQualRef(lResults[9])
|
|
164 if lResults[10] != '':
|
|
165 self.setQualVar(lResults[10])
|
|
166 if lResults[11] != '':
|
|
167 self.setPValue(lResults[11])
|
|
168
|
|
169 def setAttributesFromString(self, varscanString, iCurrentLineNumber ="", fieldSeparator ="\t"):
|
|
170 varscanString = varscanString.rstrip()
|
|
171 lvarscanStringItem = varscanString.split(fieldSeparator)
|
|
172 if len(lvarscanStringItem)<12:
|
|
173 for i in range(len(lvarscanStringItem), 12):
|
|
174 lvarscanStringItem.append ("")
|
|
175 self.setAttributes(lvarscanStringItem, iCurrentLineNumber) |