annotate Contra/scripts/convert_targeted_regions.py @ 0:7564f3b1e675

Uploaded
author fcaramia
date Thu, 13 Sep 2012 02:31:43 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
1 # ----------------------------------------------------------------------#
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
2 # Copyright (c) 2011, Richard Lupat & Jason Li.
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
3 #
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
4 # > Source License <
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
5 # This file is part of CONTRA.
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
6 #
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
7 # CONTRA is free software: you can redistribute it and/or modify
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
8 # it under the terms of the GNU General Public License as published by
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
10 # (at your option) any later version.
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
11 #
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
12 # CONTRA is distributed in the hope that it will be useful,
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
15 # GNU General Public License for more details.
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
16 #
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
17 # You should have received a copy of the GNU General Public License
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
18 # along with CONTRA. If not, see <http://www.gnu.org/licenses/>.
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
19 #
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
20 #
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
21 #-----------------------------------------------------------------------#
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
22 # Last Updated : 28 Mar 2011 11:00AM
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
23
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
24 class Target:
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
25 """
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
26 Class for target regions
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
27 """
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
28
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
29 population = 0
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
30
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
31 def __init__(self):
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
32 self.id = 0
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
33 self.gene = "unknown"
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
34 self.chr = "chr1"
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
35 self.start = 0
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
36 self.end = 0
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
37 self.numberExon = 0
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
38 self.oriStart = 0
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
39 self.oriEnd = 0
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
40
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
41 def convertTarget(target):
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
42 targets = open(target)
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
43
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
44 targetList = []
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
45
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
46 count = 0
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
47 for region in targets:
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
48 region = region.split()
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
49 chr = "chr" + region[0].strip("chr")
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
50 start = region[1]
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
51 end = region[2]
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
52 try:
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
53 gene = region[3]
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
54 except:
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
55 gene = "unknown"
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
56 count += 1
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
57
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
58 aTarget = Target()
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
59 aTarget.id = count
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
60 aTarget.gene = gene
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
61 aTarget.chr = chr
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
62 aTarget.start = start
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
63 aTarget.end = end
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
64 aTarget.numberExon = 1
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
65 aTarget.oriStart = start
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
66 aTarget.oriEnd = end
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
67
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
68 targetList.append(aTarget)
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
69
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
70
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
71 return targetList