Mercurial > repos > yufei-luo > s_mart
comparison commons/core/parsing/VarscanHit_v2_2_8.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 | |
32 from commons.core.checker.CheckerException import CheckerException | |
33 from commons.core.parsing.VarscanHit import VarscanHit | |
34 | |
35 class VarscanHit_v2_2_8(VarscanHit): | |
36 | |
37 def __init__(self, chrom = "", position = "", ref = "", cns = "", readsRef = "", readsVar = "", varFreq = "", strandsRef = "", strandsVar = "", qualRef = "", qualVar = "", pValue = "", mapQualRef = "", mapQualVar = "", readsRefPlus = "", readsRefMinus = "", readsVarPlus = "", readsVarMinus = "", var = ""): | |
38 self._cns = cns | |
39 self._mapQualRef = mapQualRef | |
40 self._mapQualVar = mapQualVar | |
41 self._readsRefPlus = readsRefPlus | |
42 self._readsRefMinus = readsRefMinus | |
43 self._readsVarPlus = readsVarPlus | |
44 self._readsVarMinus = readsVarMinus | |
45 VarscanHit.__init__(self, chrom, position, ref, var, readsRef, readsVar, varFreq, strandsRef, strandsVar, qualRef, qualVar, pValue) | |
46 | |
47 ## Equal operator | |
48 # | |
49 # @param o a VarscanFileAnalysis instance | |
50 # | |
51 def __eq__(self, o): | |
52 if self._cns == o._cns: | |
53 return VarscanHit.__eq__(self, o) | |
54 return False | |
55 | |
56 def setCns(self, consensus): | |
57 self._cns = consensus | |
58 | |
59 def setMapQualRef(self, mapQualRef): | |
60 self._mapQualRef = mapQualRef | |
61 | |
62 def setMapQualVar(self, mapQualVar): | |
63 self._mapQualVar = mapQualVar | |
64 | |
65 def setReadsRefPlus(self, readsRefPlus): | |
66 self._readsRefPlus = readsRefPlus | |
67 | |
68 def setReadsRefMinus(self, readsRefMinus): | |
69 self._readsRefMinus = readsRefMinus | |
70 | |
71 def setReadsVarPlus(self, readsVarPlus): | |
72 self._readsVarPlus = readsVarPlus | |
73 | |
74 def setReadsVarMinus(self, readsVarMinus): | |
75 self._readsVarMinus = readsVarMinus | |
76 | |
77 def getCns(self): | |
78 return self._cns | |
79 | |
80 def getMapQualRef(self): | |
81 return self._mapQualRef | |
82 | |
83 def getMapQualVar(self): | |
84 return self._mapQualVar | |
85 | |
86 def getReadsRefPlus(self): | |
87 return self._readsRefPlus | |
88 | |
89 def getReadsRefMinus(self): | |
90 return self._readsRefMinus | |
91 | |
92 def getReadsVarPlus(self): | |
93 return self._readsVarPlus | |
94 | |
95 def getReadsVarMinus(self): | |
96 return self._readsVarMinus | |
97 | |
98 def getHeader(self): | |
99 return "Chrom\tPosition\tRef\tCons\tReads1\tReads2\tVarFreq\tStrands1\tStrands2\tQual1\tQual2\tPvalue\tMapQual1\tMapQual2\tReads1Plus\tReads1Minus\tReads2Plus\tReads2Minus\tVarAllele\n" | |
100 | |
101 def getVarscanLine(self): | |
102 return "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%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.getCns(), self.getReadsRef(), self.getReadsVar(), self.getVarFreq(), self.getStrandsRef(), self.getStrandsVar(), self.getQualRef(), self.getQualVar(), self.getPValue(), self.getMapQualRef(), self.getMapQualVar(), self.getReadsRefPlus(), self.getReadsRefMinus(), self.getReadsVarPlus(), self.getReadsVarMinus(), self.getVar()) | |
103 | |
104 def setAttributes(self, lResults, iCurrentLineNumber): | |
105 if lResults[0] != '': | |
106 self.setChrom(lResults[0]) | |
107 else: | |
108 raise CheckerException ("The field Chrom is empty in varscan file in line %s" % iCurrentLineNumber) | |
109 if lResults[1] != '': | |
110 self.setPosition(lResults[1]) | |
111 else: | |
112 raise CheckerException ("The field Position is empty in varscan file in line %s" % iCurrentLineNumber) | |
113 if lResults[2] != '': | |
114 self.setRef(lResults[2]) | |
115 else: | |
116 raise CheckerException ("The field Ref is empty in varscan file in line %s" % iCurrentLineNumber) | |
117 if lResults[3] != '': | |
118 self.setCns(lResults[3]) | |
119 else: | |
120 raise CheckerException ("The field Cons is empty in varscan file in line %s" % iCurrentLineNumber) | |
121 if lResults[4] != '': | |
122 self.setReadsRef(lResults[4]) | |
123 if lResults[5] != '': | |
124 self.setReadsVar(lResults[5]) | |
125 if lResults[6] != '': | |
126 self.setVarFreq(lResults[6]) | |
127 if lResults[7] != '': | |
128 self.setStrandsRef(lResults[7]) | |
129 if lResults[8] != '': | |
130 self.setStrandsVar(lResults[8]) | |
131 if lResults[9] != '': | |
132 self.setQualRef(lResults[9]) | |
133 if lResults[10] != '': | |
134 self.setQualVar(lResults[10]) | |
135 if lResults[11] != '': | |
136 self.setPValue(lResults[11]) | |
137 if lResults[12] != '': | |
138 self.setMapQualRef(lResults[12]) | |
139 if lResults[13] != '': | |
140 self.setMapQualVar(lResults[13]) | |
141 if lResults[14] != '': | |
142 self.setReadsRefPlus(lResults[14]) | |
143 if lResults[15] != '': | |
144 self.setReadsRefMinus(lResults[15]) | |
145 if lResults[16] != '': | |
146 self.setReadsVarPlus(lResults[16]) | |
147 if lResults[17] != '': | |
148 self.setReadsVarMinus(lResults[17]) | |
149 if lResults[18] != '': | |
150 self.setVar(lResults[18]) | |
151 else: | |
152 raise CheckerException ("The field varAllele is empty in varscan file in line %s" % iCurrentLineNumber) | |
153 | |
154 def setAttributesFromString(self, varscanString, iCurrentLineNumber ="", fieldSeparator ="\t"): | |
155 varscanString = varscanString.rstrip() | |
156 lvarscanStringItem = varscanString.split(fieldSeparator) | |
157 if len(lvarscanStringItem) < 19: | |
158 raise CheckerException ("This varscan line (l.%s) is not complete" % iCurrentLineNumber) | |
159 self.setAttributes(lvarscanStringItem, iCurrentLineNumber) | |
160 | |
161 def convertVarscanHit_v2_2_8_To_VarscanHit(self): | |
162 iVarscanHit = VarscanHit() | |
163 iVarscanHit.setChrom(self.getChrom()) | |
164 iVarscanHit.setPosition(self.getPosition()) | |
165 iVarscanHit.setRef(self.getRef()) | |
166 iVarscanHit.setVar(self.getVar()) | |
167 iVarscanHit.setReadsRef(self.getReadsRef()) | |
168 iVarscanHit.setReadsVar(self.getReadsVar()) | |
169 iVarscanHit.setVarFreq(self.getVarFreq()) | |
170 iVarscanHit.setStrandsRef(self.getStrandsRef()) | |
171 iVarscanHit.setStrandsVar(self.getStrandsVar()) | |
172 iVarscanHit.setQualRef(self.getQualRef()) | |
173 iVarscanHit.setQualVar(self.getQualVar()) | |
174 iVarscanHit.setPValue(self.getPValue()) | |
175 return iVarscanHit | |
176 |