Repository navigation
Expand file tree
/
Copy pathcli.py
More file actions
200 lines (162 loc) · 5.54 KB
/
Copy pathcli.py
File metadata and controls
200 lines (162 loc) · 5.54 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#
# command line module
#
import argparse
from common import *
# system setting arguments
#
OPT_NAMESPACE = "ns"
OPT_NAMESPACE_SHORT = str("-" + OPT_NAMESPACE[:1])
OPT_NAMESPACE_EXT = str("--" + OPT_NAMESPACE)
OPT_EXE = "exe"
OPT_EXE_SHORT = str("-" + OPT_EXE[:1])
OPT_EXE_EXT = str("--" + OPT_EXE[:])
OPT_DB = "db"
OPT_DB_SHORT = str("-" + OPT_DB[:1])
OPT_DB_EXT = str("--" + OPT_DB)
# operation arguments
#
# read
OPT_READ = "read"
OPT_READ_SHORT = str("-" + OPT_READ[:1])
OPT_READ_EXT = str("--" + OPT_READ)
# filtrate
OPT_FILTRATE = "filtrate"
OPT_FILTRATE_SHORT = str("-" + OPT_FILTRATE[:1])
OPT_FILTRATE_EXT = str("--" + OPT_FILTRATE)
# annotate
OPT_ANNOTATE = "annotate"
OPT_ANNOTATE_SHORT = str("-" + OPT_ANNOTATE[:1])
OPT_ANNOTATE_EXT = str("--" + OPT_ANNOTATE)
# all operations
#
# NOTE: ADD NEW NAMESPACES-SPECIFIC-OPERATIONS IN THE FOLLOWING DICTIONARY
# The triplexer identifies 3 abstract operations:
# - read for reading an input file containing miRNA duplexes
# - filtrate for keeping only those miRNA duplexes that bind a common target
# gene in compliance with defined structural constraints
# - annotate to retrieve the target gene's transcript sequence from a remote
# database
# Since the identification of putative RNA triplexes is carried out by
# harvesting data from different sources (namespace, e.g. microrna.org,
# TargetScan, etc.), it is safe to assume that input datasets have a different
# organization, i.e. duplex information in a microrna.org file are not the same
# as those found in a TargetScan dataset. Hence, the implementation and
# combination of each operations is "namespace-specific".
# For example, to find putative RNA triplexes in a microrna.org dataset, one
# needs to run:
# - a namespace-specific implementation of the operation read
# - a namespace-agnostic implementation of the operation filtrate
# - a namespace-agnostic implementation of the operation annotate
# However, to find putative RNA triplexes from a different namespace, one might
# need to instead run:
# - a namespace-specific implementation of the operation read
# - the same namespace-agnostic implementation of the operation filtrate
# - no operation annotate
# For this reason, we collect the set of all namespace-specific-operations
# in the following dictionary
OPS = {
MICRORNA_ORG: [
OPT_READ,
OPT_FILTRATE,
OPT_ANNOTATE
]
}
# set the CLI parser
#
def triplexer_parser():
"""
Sets the command line (CLI) parser.
"""
# system setting arguments start
#
parser = argparse.ArgumentParser(
prog=TRIPLEXER,
description="Predict and simulate putative RNA triplexes.",
formatter_class=argparse.RawTextHelpFormatter)
# version
parser.add_argument(
"-v",
"--version",
action="version",
version=str("%(prog)s " + VERSION),
help="print the version and exit")
# configuration file
parser.add_argument(
"-c",
"--conf",
metavar="CONF",
default="conf.yaml",
type=argparse.FileType("r"),
help="set %(metavar)s as configuration file")
# multiprocessing
parser.add_argument(
OPT_EXE_SHORT,
OPT_EXE_EXT,
metavar="EXE",
default="2",
help="set %(metavar)s as number of parallely executing processes")
# cache
parser.add_argument(
OPT_DB_SHORT,
OPT_DB_EXT,
metavar="DB",
default="redis:6379",
help="set %(metavar)s as intermediate results database")
#
# system setting arguments end
# operation arguments start
#
parser_op = parser.add_argument_group("operations (require "
+ OPT_NAMESPACE_SHORT + ")")
parser_op.add_argument(
OPT_READ_SHORT,
OPT_READ_EXT,
action="store_true",
default=argparse.SUPPRESS,
help=str("read the provided dataset in memory"))
parser_op.add_argument(
OPT_FILTRATE_SHORT,
OPT_FILTRATE_EXT,
action="store_true",
default=argparse.SUPPRESS,
help=str("filter entries not forming putative triplexes"))
parser_op.add_argument(
OPT_ANNOTATE_SHORT,
OPT_ANNOTATE_EXT,
action="store_true",
default=argparse.SUPPRESS,
help=str("annotate transcripts with their sequences"))
#
# operation arguments end
# namespace arguments start
#
supported_namespaces = get_supported_namespaces() # supported namespaces
parser_ns = parser.add_argument_group("namespace")
parser_ns.add_argument(
OPT_NAMESPACE_SHORT,
OPT_NAMESPACE_EXT,
metavar="NS",
default="test",
help=str("set %(metavar)s as model organism namespace\n"
+ "supported %(metavar)s (default \"%(default)s\"):\n"
+ supported_namespaces))
#
# namespace arguments end
return parser
# print the supported namespaces
#
def get_supported_namespaces():
"""
Prints the supported namespaces.
"""
line_divider = "+-------+----------------------------------+\n"
supported_namespaces = line_divider
supported_namespaces += str("| {:<1}\t| {:<32} |\n".format(
"NS", "database:version:organism:genome"))
supported_namespaces += line_divider
for k, v in NAMESPACES.items():
label, source, origing, release, orgagnism, genome = v
supported_namespaces += "| {:<1}\t| {:<32} |\n".format(k, v[NS_LABEL])
supported_namespaces += line_divider
return supported_namespaces