10
10
11
11
12
12
def generate_motif_visualisations_by_cluster (input_file_motif_clusters = './results/motifs_by_cluster.pickle' , output_file = './results/clustering_output.pdf' ):
13
- """
14
- :param input_file_motif_clusters: string with a filepath to a pickled dictionary where the keys are cluster names and the values
15
- are dictionaries where the keys are motifs (nx subgraph) of length k and the values are how many times similar
16
- (isomorphic) motifs occur in the graph.
17
- :param output_file: string thats a path of a pdf file to output the graphs to
13
+ """ Visualize the motif clustering result and output the visualize result to pdf file.
14
+
15
+ Parameters
16
+ ----------
17
+ input_file_motif_clusters: string with a filepath to a pickled dictionary where the keys are cluster names and the values
18
+ are dictionaries where the keys are motifs (nx subgraph) of length k and the values are how
19
+ many times similar(isomorphic) motifs occur in the graph.
20
+ output_file: string thats a path of a pdf file to output the graphs to.
21
+
22
+ Returns
23
+ -------
24
+ Visulization result of motif clustering, by cluster, saved down to a pdf file.
18
25
"""
19
26
with open (input_file_motif_clusters , 'rb' ) as pickle_in :
20
27
motif_clusters = pickle .load (pickle_in )
@@ -30,15 +37,18 @@ def generate_motif_visualisations_by_cluster(input_file_motif_clusters='./result
30
37
31
38
32
39
def visualize_motif_samples_bar_graph (motifs , plot_title = 'Motif Frequency in Dataset' , motifs_to_show = 8 ):
33
- """
34
- Given a collection of motifs and their frequency in a graph, output a file with a bar chart showing the motifs and
35
- their associated frequencies.
36
-
37
- :param motifs: dictionary where the keys are motifs (nx subgraph) of length k and the values are how many times similar
38
- (isomorphic) motifs occur in the graph.
39
- :param plot_title: string thats the tile of your plot.
40
- :return: fig that is a bar chart of the most common motifs and how often they occurred
41
-
40
+ """ Given a collection of motifs and their frequency in a graph, output a file with a bar chart showing the motifs and
41
+ their associated frequencies.
42
+
43
+ Parameters
44
+ ----------
45
+ motifs: dictionary where the keys are motifs (nx subgraph) of length k and the values are how many times similar
46
+ (isomorphic) motifs occur in the graph.
47
+ plot_title: string thats the tile of your plot.
48
+
49
+ Returns
50
+ -------
51
+ A bar chart figure of the most common motifs and how often they occurred.
42
52
"""
43
53
motifs_sorted = sorted (motifs .items (), key = lambda kv : kv [1 ], reverse = True )
44
54
@@ -97,48 +107,5 @@ def visualize_motif_samples_bar_graph(motifs, plot_title='Motif Frequency in Dat
97
107
'{}% of Sampled Motifs are a Single Chain' .format (round (100 * single_chain_occurences / number_of_samples , 3 )))
98
108
return fig
99
109
100
- # plt.savefig(output_file, pad_inches=2)
101
- # plt.close()
102
-
103
-
104
- # def visualize_motif_samples(motifs, output_file):
105
- # """
106
- # Given a sample of motifs, output a file with their graphs and how often they occurred.
107
- #
108
- # :param motifs: a dictionary where the keys are motifs (nx subgraph) of length k and the keys are how many times similar
109
- # (isomorphic) motifs occur in the graph.
110
- # :param output_file: string thats apath of a pdf file to output the graphs to
111
- # :return: a pdf file with name output_file with the graphs and how often they occured
112
- # """
113
- # motif_count = sum(motifs.values())
114
- # motifs_sorted = sorted(motifs.items(), key=lambda kv: kv[1], reverse=True)
115
- # with PdfPages(output_file) as pdf:
116
- # for motif in motifs_sorted:
117
- # fig = plt.figure()
118
- # nx.draw_kamada_kawai(motif[0], node_size=25, arrowsize=5)
119
- # fig.suptitle('{} Occurrences ({}%)'.format(motif[1], round(100 * motif[1] / motif_count, 3)))
120
- # pdf.savefig(fig)
121
- # plt.close()
122
- #
123
-
124
110
if __name__ == '__main__' :
125
111
main ()
126
-
127
- # try:
128
- # makedirs('results/clustering_{}'.format(output_folder_suffix)) # make output folder
129
- # except FileExistsError:
130
- # print('About to overwrite existing output folder and files...')
131
- # #TODO: Have user have to type 'y' or something continue, then also delete all files in folder so theres not like one cluster left over from before.
132
-
133
-
134
-
135
-
136
- # cluster_visual = visualize_motif_samples_bar_graph(motifs, 'Cluster ' + str(cluster), number_of_samples)
137
- # pdf.savefig(cluster_visual,pad_inches=2)
138
- # #visualize_motif_samples(motifs, './results/clustering_{}/cluster_{}.pdf'.format(output_folder_suffix,cluster))
139
- #
140
-
141
-
142
- # # Sort keys in cluster dictionary so they are outputted
143
- # sorted_cluster_keys = list(clusters.keys())
144
- # sorted_cluster_keys.sort()
0 commit comments