annotate commons/core/parsing/VarscanHit.py @ 9:1eb55963fe39

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