comparison MotifFinderPlot.py @ 1:adf18db4c14a draft

planemo upload for repository https://github.com/eteriSokhoyan/galaxytools/tree/master/tools/GraphClust/Plotting commit 4dd7269185f6fb9bdc007028007d6540f4cf057d
author rnateam
date Sat, 25 Mar 2017 16:53:09 -0400
parents edcf58ab7552
children
comparison
equal deleted inserted replaced
0:edcf58ab7552 1:adf18db4c14a
7 from collections import defaultdict 7 from collections import defaultdict
8 import glob 8 import glob
9 import pandas as pd 9 import pandas as pd
10 import itertools 10 import itertools
11 import seaborn as sns 11 import seaborn as sns
12 12 import numpy as np
13 13
14 def plot_bar(ranges, colors, orig_names, cluster_nums): 14 def plot_bar(ranges, colors, orig_names, cluster_nums):
15 fig, ax = plt.subplots() 15 fig, ax = plt.subplots()
16 for i, k in enumerate(sorted(ranges.keys())): 16 for i, k in enumerate(sorted(ranges.keys())):
17 ax.broken_barh(ranges[k], (i-0.25, 0.5), facecolors=colors[k]) 17 ax.broken_barh(ranges[k], (i-0.25, 0.5), facecolors=colors[k])
18 18
19 ax.set_xlim(0) 19 ax.set_xlim(0)
20 ax.set_xlabel('position in sequence') 20 ax.set_xlabel('position in sequence')
21 ax.set_yticks(np.arange(-1, len(ranges)))
21 ax.set_yticklabels(['']+[k+'-'+orig_names[k] for k in sorted(ranges.keys())]) 22 ax.set_yticklabels(['']+[k+'-'+orig_names[k] for k in sorted(ranges.keys())])
22 ax.grid(True) 23 ax.grid(True)
23 fig.suptitle('Structure motif prediction\nRegions with same color are prediticted to have similar structures') 24 fig.suptitle('Structure motif prediction\nRegions with same color are prediticted to have similar structures')
24 # Add the legend 25 # Add the legend
25 patches = [mpatches.Patch(color=cluster_nums[lab], label=lab) for lab in sorted(cluster_nums)] 26 patches = [mpatches.Patch(color=cluster_nums[lab], label=lab) for lab in sorted(cluster_nums)]
26 ax.legend(handles=patches, loc='best') # , bbox_to_anchor=(1, 0.5), loc='center left') 27 ax.legend(handles=patches, loc='best', bbox_to_anchor=(1.2, 1.05))#, loc='center left')
27 plt.savefig("motif_plot.png", bbox_inches='tight') 28 plt.savefig("motif_plot.png", bbox_inches='tight')
28 29
29 30
30 def parse_clusters(): 31 def parse_clusters():
31 currentdir_files = sorted(list(glob.glob('*'))) 32 currentdir_files = sorted(list(glob.glob('*')))
32 print ("currentdir_files are: ", currentdir_files) 33 print ("currentdir_files are: ", currentdir_files)
33 print ("RESULTS_files are: ", sorted(list(glob.glob('RESULTS/*')))) 34 print ("RESULTS_files are: ", sorted(list(glob.glob('RESULTS/*'))))
34 35
35 cluster_files = sorted(list(glob.glob('RESULTS/*.cluster.all'))) 36 cluster_files = sorted(list(glob.glob('RESULTS/*.cluster.all')))
36 if len(cluster_files) == 0: 37 if len(cluster_files) == 0:
37 raise RuntimeError('Expected cluster.all search path is empty:{}'.format(cluster_files)) 38 raise RuntimeError('Expected cluster.all search path is empty:{}'.format(cluster_files))
38 palette = itertools.cycle(sns.color_palette("Set2", len(cluster_files))) 39 palette = itertools.cycle(sns.color_palette("Set2", len(cluster_files)))
39
40 40
41 ranges = defaultdict(list) 41 ranges = defaultdict(list)
42 colors = defaultdict(list) 42 colors = defaultdict(list)
43 orig_names = defaultdict(list) 43 orig_names = defaultdict(list)
44 cluster_nums = defaultdict(list) 44 cluster_nums = defaultdict(list)