annotate TEisotools-1.1.a/TEiso/ClosestToStartSite.py @ 13:feef9a0db09d draft

Uploaded
author urgi-team
date Wed, 20 Jul 2016 09:04:42 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
1 #!/usr/bin/env python
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
2
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
3 # Copyright INRA (Institut National de la Recherche Agronomique)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
4 # http://www.inra.fr
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
5 # http://urgi.versailles.inra.fr
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
6 #
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
7 # This software is governed by the CeCILL license under French law and
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
8 # abiding by the rules of distribution of free software. You can use,
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
9 # modify and/ or redistribute the software under the terms of the CeCILL
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
10 # license as circulated by CEA, CNRS and INRIA at the following URL
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
11 # "http://www.cecill.info".
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
12 #
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
13 # As a counterpart to the access to the source code and rights to copy,
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
14 # modify and redistribute granted by the license, users are provided only
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
15 # with a limited warranty and the software's author, the holder of the
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
16 # economic rights, and the successive licensors have only limited
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
17 # liability.
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
18 #
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
19 # In this respect, the user's attention is drawn to the risks associated
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
20 # with loading, using, modifying and/or developing or reproducing the
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
21 # software by the user in light of its specific status of free software,
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
22 # that may mean that it is complicated to manipulate, and that also
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
23 # therefore means that it is reserved for developers and experienced
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
24 # professionals having in-depth computer knowledge. Users are therefore
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
25 # encouraged to load and test the software's suitability as regards their
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
26 # requirements in conditions enabling the security of their systems and/or
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
27 # data to be ensured and, more generally, to use and operate it in the
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
28 # same conditions as regards security.
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
29 #
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
30 # The fact that you are presently reading this means that you have had
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
31 # knowledge of the CeCILL license and that you accept its terms.
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
32
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
33 from commons.core.LoggerFactory import LoggerFactory
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
34 from commons.core.utils.RepetOptionParser import RepetOptionParser
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
35 from commons.core.checker.RepetException import RepetException
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
36 from commons.core.utils.FileUtils import FileUtils
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
37 import re,os
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
38 LOG_NAME = "TEiso"
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
39
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
40 class ClosestToStartSite(object):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
41
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
42 def __init__(self, inputFile = "", cuffcom_tmap = "", outputFile = "", verbosity = 3):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
43 self._inputFile = inputFile
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
44 self._cuffcom_tmap = cuffcom_tmap
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
45 self._outputFile = outputFile
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
46 self._verbosity = verbosity
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
47 self._log = LoggerFactory.createLogger("%s.%s" % (LOG_NAME, self.__class__.__name__), self._verbosity)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
48
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
49 def setAttributesFromCmdLine(self):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
50 self._toolVersion = "1.1.a"
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
51 description = "ClosestToStartSite version %s" % self._toolVersion
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
52 epilog = "\nParser a bed file and create a bed file to create a report about positions of features A to features B. \n"
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
53 epilog +="it can also add the class code of features A.\n"
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
54 epilog += "example: ClosestToStartSite.py -i <inputFile> -c <cuff_in.tmap> -o <outputFile>\n"
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
55 parser = RepetOptionParser(description = description, epilog = epilog, version = self._toolVersion)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
56 parser.add_option("-i", "--inputFile", dest = "inputFile", action = "store", type = "string", help = "input bed file name.", default = "")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
57 parser.add_option("-c", "--cuffcom_tmap", dest = "cuffcom_tmap", action = "store", type = "string", help = "input gtf file of cuffcompare (<cuff_in>.tmap)", default = "")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
58 parser.add_option("-o", "--outputFile", dest = "outputFile", action = "store", type = "string", help = "output file name", default = "")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
59 parser.add_option("-v", "--verbosity", dest = "verbosity", action = "store", type = "int", help = "verbosity [optional] [default: 3]",default = 3)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
60 options = parser.parse_args()[0]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
61 self._setAttributesFromOptions(options)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
62
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
63 def _setAttributesFromOptions(self, options):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
64 self._inputFile = options.inputFile
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
65 self._cuffcom_tmap = options.cuffcom_tmap
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
66 self._outputFile = options.outputFile
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
67 self._verbosity = options.verbosity
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
68
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
69 def _logAndRaise(self, errorMsg):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
70 self._log.error(errorMsg)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
71 raise RepetException(errorMsg)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
72
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
73 def checkoption(self):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
74 if self._inputFile == "":
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
75 self._log.info("Missing input file")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
76 else:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
77 if not FileUtils.isRessourceExists(self._inputFile):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
78 self._log.info("'%s' doesn't exist!" % self._inputFile)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
79
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
80 if self._cuffcom_tmap != "":
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
81 if not FileUtils.isRessourceExists(self._cuffcom_tmap):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
82 self._log.info("'%s' doesn't exist!" % self._cuffcom_tmap)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
83 if self._outputFile == "":
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
84 self._outputFile = "%s_Close2TSS_with_classcode.bed" % os.path.splitext(self._inputFile)[0]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
85 else:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
86 if FileUtils.isRessourceExists(self._outputFile):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
87 self._log.info("Output file '%s' already exists!" % self._outputFile)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
88 else:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
89 if self._outputFile == "":
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
90 self._outputFile = "%s_Close2TSS.bed" % os.path.splitext(self._inputFile)[0]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
91 else:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
92 if FileUtils.isRessourceExists(self._outputFile):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
93 self._log.info("Output file '%s' already exists!" % self._outputFile)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
94
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
95
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
96 def getClassCodeCuffcompare(self, tmap_file, listPossitions):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
97 class_code_dic = {}
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
98 lcode_ref = []
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
99 tmp = []
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
100 linetowrite =[]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
101 with open(tmap_file) as tmap:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
102 tmapline = tmap.readlines()
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
103 for i in range(1,len(tmapline)):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
104 cuff_id = tmapline[i].split("\t")[4].strip()
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
105 class_code = tmapline[i].split("\t")[2].strip()
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
106 ref_id = tmapline[i].split("\t")[1].strip()
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
107 lcode_ref.append(class_code)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
108 lcode_ref.append(ref_id)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
109 class_code_dic[cuff_id] = lcode_ref
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
110 lcode_ref = []
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
111
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
112
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
113 for i in xrange(0,len(listPossitions)):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
114 tmp.extend(listPossitions[i])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
115 transcript_bedtools = listPossitions[i][3]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
116
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
117 if transcript_bedtools in class_code_dic.keys():
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
118 tmp.append(class_code_dic[transcript_bedtools][0])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
119 tmp.append(class_code_dic[transcript_bedtools][1])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
120 else:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
121 tmp.append("NA")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
122 tmp.append("NA")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
123 linetowrite.append(tmp)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
124 tmp=[]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
125 return linetowrite
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
126
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
127
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
128
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
129 def getClosestToStartSite(self, inputFile):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
130 linelist = []
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
131 tmplist = []
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
132 with open(inputFile, "r") as bedFile:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
133 for line in bedFile.readlines():
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
134 m = re.search(r"^\s*(\S+)\t+(\d+)\t+(\d+)\t+([^\t]+)\t+([^\t]+)\t+([+-])\t+(\d+\.\d+)\t+([^\t]+)+\t+(\d+)\t+(\d+)\t+([^\t]+)+\t+([^\t]+)\t+([+-])\t+([^\t]+)",line)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
135 if(m != None):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
136 start_TR = int(m.group(2))##F[1]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
137 end_TR = int(m.group(3))##F[2]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
138 strand_TR= m.group(6) ##[5]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
139 start_TE = int(m.group(9))##[8]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
140 end_TE = int(m.group(10))##[9]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
141 dist = int(m.group(14))##[13]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
142 if (start_TE < start_TR) and (end_TE < start_TR) and (strand_TR =="+") and (end_TR > end_TE) and (end_TR > start_TE) and (dist != 0):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
143 for i in range(0,len(line.split("\t"))-1):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
144 tmplist.append(line.split("\t")[i])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
145 tmplist.append(line.split("\t")[13].strip())
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
146 tmplist.append("TE_closest_TSS")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
147 linelist.append(tmplist)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
148 tmplist = []
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
149 # F[1] gene F[2]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
150 # =========================>
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
151 # ------------
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
152 # F[8] F[9]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
153
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
154 if (start_TE > end_TR) and (end_TE > end_TR) and (strand_TR =="-") and (start_TR < start_TE) and (start_TR < end_TE) and (dist != 0):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
155 for i in range(0,len(line.split("\t"))-1):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
156 tmplist.append(line.split("\t")[i])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
157 tmplist.append(line.split("\t")[13].strip())
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
158 tmplist.append("TE_closest_TSS")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
159 linelist.append(tmplist)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
160 tmplist = []
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
161
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
162 # F[1] F[2]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
163 # <======================
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
164 # ---------------
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
165
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
166 if (start_TE <= start_TR) and (start_TR < end_TE) and (strand_TR =="+") and (end_TR > end_TE) and (end_TR > start_TE):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
167 for i in range(0,len(line.split("\t"))-1):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
168 tmplist.append(line.split("\t")[i])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
169 overlap = (end_TE-start_TR)+1
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
170 tmplist.append(overlap)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
171 tmplist.append("TE_overlap_TSS")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
172 linelist.append(tmplist)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
173 tmplist = []
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
174
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
175 # F[1] gene F[2]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
176 # =========================>
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
177 # -------------
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
178 # F[8] F[9]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
179
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
180 # gene
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
181 # F[1]=========================>F[2]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
182
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
183 # F[8]---------------F[9]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
184
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
185
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
186 if (start_TE < start_TR) and (start_TR == end_TE) and (strand_TR =="+") and (end_TR > end_TE) and (end_TR > start_TE):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
187 for i in range(0,len(line.split("\t"))-1):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
188 tmplist.append(line.split("\t")[i])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
189 tmplist.append(0)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
190 tmplist.append("TE_overlap_TSS")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
191 linelist.append(tmplist)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
192 tmplist = []
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
193
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
194 ## F[1]=============================>F[2]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
195 ## F[8]---------------F[9]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
196
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
197
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
198 if (start_TE < end_TR) and (end_TR <= end_TE) and (strand_TR =="-") and (start_TR < start_TE) and (start_TR < end_TE):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
199 for i in range(0,len(line.split("\t"))-1):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
200 tmplist.append(line.split("\t")[i])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
201 overlap = (end_TR-start_TE)+1
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
202 tmplist.append(overlap)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
203 tmplist.append("TE_overlap_TSS")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
204 linelist.append(tmplist)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
205 tmplist = []
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
206
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
207
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
208 # F[1]<======================F[2]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
209 # ---------------
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
210 # F[8] F[9]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
211 #
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
212 #
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
213 # F[1]<=============================F[2]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
214 # F[8]---------------F[9]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
215
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
216 if (start_TE == end_TR) and (end_TR < end_TE) and (strand_TR =="-") and (start_TR < start_TE) and (start_TR < end_TE):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
217 for i in range(0,len(line.split("\t"))-1):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
218 tmplist.append(line.split("\t")[i])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
219 tmplist.append(0)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
220 tmplist.append("TE_overlap_TSS")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
221 linelist.append(tmplist)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
222 tmplist = []
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
223
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
224 # F[1]<=============================F[2]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
225 # F[8]---------------F[9]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
226
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
227 if (start_TR < start_TE) and (start_TR < end_TE) and (start_TE < end_TR) and (end_TE < end_TR) and (dist == 0):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
228 for i in range(0,len(line.split("\t"))-1):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
229 tmplist.append(line.split("\t")[i])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
230 tmplist.append(0)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
231 #tmplist.append(line.strip())
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
232 tmplist.append("TE_in_gene")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
233 linelist.append(tmplist)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
234 tmplist = []
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
235
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
236
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
237 # F[1] gene F[2]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
238 # ==============================
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
239 # -----------
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
240 # F[8] F[9]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
241
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
242
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
243 if (start_TE < start_TR) and (start_TR < end_TE) and (start_TE < end_TR) and (end_TR < end_TE):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
244 for i in range(0,len(line.split("\t"))-1):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
245 tmplist.append(line.split("\t")[i])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
246 #lenTE = (end_TE-start_TE)+1
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
247 tmplist.append(0)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
248 tmplist.append("gene_in_TE")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
249 linelist.append(tmplist)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
250 tmplist = []
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
251
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
252 # F[1]======================F[2]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
253 # F[8]----------------------------------------------------F[9]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
254
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
255
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
256 if (strand_TR =="+") and (start_TR > start_TE) and (start_TR < end_TE) and (start_TE < end_TR) and (end_TE == end_TR):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
257 for i in range(0,len(line.split("\t"))-1):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
258 tmplist.append(line.split("\t")[i])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
259 tmplist.append(0)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
260 #tmplist.append(line.strip())
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
261 tmplist.append("gene_in_TE")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
262 linelist.append(tmplist)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
263 tmplist = []
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
264
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
265 # F[1]==================================>F[2]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
266 # F[8]----------------------------------------------------------F[9]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
267
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
268 if (strand_TR =="-") and (start_TR > start_TE) and (start_TR < end_TE) and (start_TE < end_TR) and (end_TE == end_TR):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
269 for i in range(0,len(line.split("\t"))-1):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
270 tmplist.append(line.split("\t")[i])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
271 tmplist.append(0)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
272 #tmplist.append(line.strip())
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
273 tmplist.append("gene_in_TE")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
274 linelist.append(tmplist)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
275 tmplist = []
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
276
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
277 # F[1]<==================================F[2]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
278 # F[8]----------------------------------------------------------F[9]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
279
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
280 if (strand_TR =="+") and (start_TR == start_TE) and (start_TR < end_TE) and (start_TE < end_TR) and (end_TE > end_TR):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
281 for i in range(0,len(line.split("\t"))-1):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
282 tmplist.append(line.split("\t")[i])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
283 tmplist.append(0)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
284 #tmplist.append(line.strip())
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
285 tmplist.append("gene_in_TE")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
286 linelist.append(tmplist)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
287 tmplist = []
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
288
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
289 # F[1]==================================>F[2]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
290 # F[8]----------------------------------------------------------F[9]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
291
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
292 if (strand_TR =="-") and (start_TR == start_TE) and (start_TR < end_TE) and (start_TE < end_TR) and (end_TE > end_TR):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
293 for i in range(0,len(line.split("\t"))-1):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
294 tmplist.append(line.split("\t")[i])
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
295 tmplist.append(0)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
296 #tmplist.append(line.strip())
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
297 tmplist.append("gene_in_TE")
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
298 linelist.append(tmplist)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
299 tmplist = []
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
300
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
301 # F[1]<==================================F[2]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
302 # F[8]----------------------------------------------------------F[9]
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
303
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
304 return linelist
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
305
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
306
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
307 def writeOutputFromList(self, listPossitions , outputFile):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
308 w = open(outputFile,'w')
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
309 for s in listPossitions:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
310 line= "\t".join(str(item) for item in s)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
311 w.write("%s\n" % line)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
312 w.close()
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
313
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
314
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
315 def run(self):
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
316 self.checkoption()
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
317 listPossitions = self.getClosestToStartSite(self._inputFile)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
318 if self._cuffcom_tmap == "":
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
319 self.writeOutputFromList(listPossitions, self._outputFile )
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
320 else:
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
321 listclasscode = self.getClassCodeCuffcompare(self._cuffcom_tmap, listPossitions)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
322 self.writeOutputFromList(listclasscode, self._outputFile)
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
323
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
324 if __name__== "__main__":
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
325 iClosestToStartSite = ClosestToStartSite()
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
326 iClosestToStartSite.setAttributesFromCmdLine()
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
327 iClosestToStartSite.run()
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
328
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
329
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
330
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
331
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
332
feef9a0db09d Uploaded
urgi-team
parents:
diff changeset
333