-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter_rotations.py
executable file
·57 lines (45 loc) · 1.5 KB
/
filter_rotations.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
#!/usr/bin/env python
import sys
import getopt
from ICDIndicator import get_compressed_diagram
from ICDIndicator import get_rotated_diagram
from ChordDiagram.Utility import load_diagrams_from_files
def usage(progname, msg=""):
usage_msg = '''
Print each input diagram to stdout if it is not rotationally equivalent to any
previous input diagrams.
Note: Not suitable for extremely large sets of input diagrams as each rotation
of each diagram is held in memory.
usage: {} [-h]
'''
print >>sys.stderr, usage_msg.format(progname)
if len(msg):
print >>sys.stderr, msg
sys.exit(1)
def main(argv):
"Process command line arguments and kick things off"
progname = argv[0].split('/')[-1]
# Parse command line options
try:
(opts, args) = getopt.getopt(argv[1:], "hk")
except getopt.GetoptError as err:
print >>sys.stderr, str(err)
usage(progname)
for opt, _ in opts:
if opt == '-h':
usage(progname)
diag_files = args
if len(diag_files) == 0:
diag_files.append(None) # Read from stdin
# Do the work
diags = set()
diag_gen = load_diagrams_from_files(diag_files)
for diagram in diag_gen:
comp_diag = get_compressed_diagram(diagram)
if str(comp_diag) not in diags:
print diagram
for rots in range(0, len(comp_diag)*2):
rot_diag = get_rotated_diagram(comp_diag, rots)
diags.add(str(rot_diag))
if __name__ == "__main__":
main(sys.argv)