-
Notifications
You must be signed in to change notification settings - Fork 0
/
meme2table.py
79 lines (53 loc) · 1.78 KB
/
meme2table.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
'''
meme2table - summarize infomation about a meme motif file
=========================================================
:Author:
:Tags: Python
Purpose
-------
.. Overall purpose and function of the script>
Usage
-----
.. Example use case
Example::
python cgat_script_template.py
Type::
python cgat_script_template.py --help
for command line help.
Command line options
--------------------
'''
import sys
import CGATCore.Experiment as E
import CGAT.MEME as MEME
import itertools
def main(argv=None):
"""script main.
parses command line options in sys.argv, unless *argv* is given.
"""
if argv is None:
argv = sys.argv
# setup command line parser
parser = E.OptionParser(version="%prog version: $Id$",
usage=globals()["__doc__"])
parser.add_option("-t", "--test", dest="test", type="string",
help="supply help")
# add common options (-h/--help, ...) and parse command line
(options, args) = E.start(parser, argv=argv)
motifs = MEME.MemeMotifFile(options.stdin)
headers = list(set(itertools.chain(*[motif.properties.keys()
for motif in motifs])))
outlines = []
for motif in motifs:
outline = [motif.primary_id, motif.secondary_id, motif.consensus()]
outline.extend([motif.properties.get(col, "") for col in headers])
outlines.append(outline)
headers = "\t".join(["primary_id", "secondary_id", "consensus"] + headers)
output = "\n".join(["\t".join(map(str, line))
for line in outlines])
output = headers + "\n" + output
options.stdout.write(output)
# write footer and output benchmark information.
E.stop()
if __name__ == "__main__":
sys.exit(main(sys.argv))