comparison visualization.py @ 0:e41ec5af7472 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/heinz commit b0b2c64a46bdd9beebdfb7fc5312f75346483763
author iuc
date Thu, 02 Aug 2018 11:57:44 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e41ec5af7472
1 #!/usr/bin/env python
2 """Visualise the output of Heinz.
3
4 This script is used to visualize the output of Heinz, which is in the form of
5 DOT language:
6 1. Clear the output of Heinz, extract the DOT source code.
7 2. Visualize the DOT source code and save it into file.
8
9 The function of this script is rather simple, for more advanced visualization,
10 please adopt other solutions mentioned in the paper
11 doi: 10.1093/bioinformatics/btv526
12
13 This tool is only designed for visualizing the output of Heinz tool.
14 """
15
16 # Author: Cico Zhang
17 # Date: 2 Aug 2017
18 # Version: 0.2
19
20 import argparse
21 import sys
22
23 from graphviz import Source
24
25
26 def get_args():
27 """Collect the inputs."""
28 parser = argparse.ArgumentParser(
29 description='Visualise the output of Heinz')
30 parser.add_argument('-i', '--input', required=True, dest='heinz',
31 metavar='Heinz_output.txt', type=str,
32 help='Output file of Heinz as the input')
33 parser.add_argument('-o', '--output', required=True, dest='output',
34 metavar='graph.pdf', type=str,
35 help='The output file that saves the visualisation')
36 args = parser.parse_args()
37
38 if args.heinz is None:
39 sys.exit('Input file must be designated.')
40
41 return args
42
43
44 def main():
45 """Main function."""
46 args = get_args()
47 # Read the whole output file
48 with open(args.heinz) as r:
49 graph_dot = r.readlines()
50
51 # Remove the redundant lines
52 while not graph_dot[0].startswith('graph G {'):
53 graph_dot.pop(0)
54
55 src = Source(''.join(graph_dot))
56 data_pdf = src.pipe('pdf')
57 # Redirect the output (very important)
58 with open(args.output, 'wb') as w:
59 w.write(data_pdf)
60 print('The visualization is saved as PDF!')
61 sys.exit(0)
62
63
64 if __name__ == "__main__":
65 main()