-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetSimpleAS.py
executable file
·130 lines (104 loc) · 3.35 KB
/
getSimpleAS.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/broad/software/free/Linux/redhat_5_x86_64/pkgs/python_2.5.4/bin/python
# getSimpleAS.py
# Author: Angela Brooks
# Program Completion Date:
# Description:
# Modification Date(s):
# Copyright (c) 2011, Angela Brooks. [email protected]
# All rights reserved.
import sys
import optparse
import os
import pdb
#############
# CONSTANTS #
#############
SIMPLE_EVENTS = set(["cassette",
"alternative_donor",
"alternative_acceptor"])
#################
# END CONSTANTS #
#################
###########
# CLASSES #
###########
class OptionParser(optparse.OptionParser):
"""
Adding a method for required arguments.
Taken from:
http://www.python.org/doc/2.3/lib/optparse-extending-examples.html
"""
def check_required(self, opt):
option = self.get_option(opt)
# Assumes the option's 'default' is set to None!
if getattr(self.values, option.dest) is None:
print "%s option not supplied" % option
self.print_help()
sys.exit(1)
###############
# END CLASSES #
###############
########
# MAIN #
########
def main():
opt_parser = OptionParser()
# Add Options. Required options should have default=None
opt_parser.add_option("-i",
dest="juncBASE_table",
type="string",
help="JuncBASE table",
default=None)
opt_parser.add_option("-o",
dest="out_table",
type="string",
help="""juncBASE_table only containing simple cassette exon
events (no additional alternative splice site
usage) and alternative 5' and alternative 3'
splice sites with two choices""",
default=None)
(options, args) = opt_parser.parse_args()
# validate the command line arguments
opt_parser.check_required("-i")
opt_parser.check_required("-o")
in_table = open(options.juncBASE_table)
out_table = open(options.out_table, "w")
for line in in_table:
line = formatLine(line)
# Header line
if line.startswith("#"):
out_table.write(line + "\n")
continue
lineList = line.split("\t")
if lineList[1] not in SIMPLE_EVENTS:
continue
if lineList[1] == "cassette":
# Only keep events with one skipping junction
if ";" in lineList[5]:
continue
if lineList[1] == "alternative_donor" or lineList[1] == "alternative_acceptor":
if ";" in lineList[5]:
continue
if "," in lineList[5]:
continue
out_table.write(line + "\n")
sys.exit(0)
############
# END_MAIN #
############
#############
# FUNCTIONS #
#############
def formatDir(i_dir):
i_dir = os.path.realpath(i_dir)
if i_dir.endswith("/"):
i_dir = i_dir.rstrip("/")
return i_dir
def formatLine(line):
line = line.replace("\r","")
line = line.replace("\n","")
return line
#################
# END FUNCTIONS #
#################
if __name__ == "__main__": main()