-
Notifications
You must be signed in to change notification settings - Fork 1
/
rinchi_stats.py
executable file
·70 lines (56 loc) · 2.72 KB
/
rinchi_stats.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
#!/usr/bin/env python3
"""
RInChI Statictics Script
------------------------
Calculates summary statistics for a flat file of RInChIs.
Modifications:
- D.F. Hampshire 2017
"""
import argparse
from rinchi_tools import tools, utils
def add_stats(subparser):
"""
Adds the arguments for the stats operation to the ``ArgumentParser`` object.
Args:
subparser: An ``ArgumentParser`` object
"""
assert isinstance(subparser, argparse.ArgumentParser)
# Add main search arguments
subparser.add_argument("input", help="The flat file of rinchis to generate statistics from")
subparser.add_argument('-all', action="store_true", help='return all information')
subparser.add_argument("-r", "--reactants", action="store_true", help="Include information about the reactants")
subparser.add_argument('-p', '--products', action="store_true", help='Include Information about the products')
subparser.add_argument("-a", '--agents', action='store_true', help='Include information about the agents')
subparser.add_argument("-d", '--directions', action='store_true', help='Include information about the directions')
subparser.add_argument('-u', '--unknownstructs', action='store_true',
help='Include information about unknown structures')
subparser.add_argument("-m", '--mostcommon', nargs='?', const=5, default=None,
help='Only include information about the most commonly occuring items')
def stats_ops(args):
"""
Executes the statitics operations.
Args:
args: The output of the ``parser.parse_args()``. The command line arguments.
"""
data = tools.rinchi_to_dict_list(open(args.input), )
rinchis = (item['rinchi'] for item in data)
data = tools.process_stats(rinchis, int(args.mostcommon))
p_string = 'STATS\n-----\n'
p_string += utils.counter_to_print_string(data['pops'], 'Populations')
if args.reactants or args.all:
p_string += '\n' + utils.counter_to_print_string(data['reactants'], 'Reactants')
if args.products or args.all:
p_string += '\n' + utils.counter_to_print_string(data['products'], 'Products')
if args.agents or args.all:
p_string += '\n' + utils.counter_to_print_string(data['agents'], 'Agents')
if args.directions or args.all:
p_string += '\n' + utils.counter_to_print_string(data['directions'], 'Directions')
if args.unknownstructs or args.all:
p_string += '\n' + utils.counter_to_print_string(data['unknownstructs'], 'Unknown Structures')
print(p_string)
if __name__ == "__main__":
role = "RInChI Statistical analysis"
parser = argparse.ArgumentParser(description=role)
add_stats(parser)
args = parser.parse_args()
stats_ops(args)