Skip to content

Commit b3493d0

Browse files
committed
adding heatmap
1 parent 77053ca commit b3493d0

File tree

3 files changed

+158
-15
lines changed

3 files changed

+158
-15
lines changed

singularity/analysis/compare.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,38 @@
3939
import pandas
4040

4141

42+
def compare_lists(list1, list2):
43+
'''compare lists is the lowest level that drives compare_containers and
44+
compare_packages. It returns a comparison object (dict) with the unique,
45+
total, and intersecting things between two lists
46+
:param list1: the list for container1
47+
:param list2: the list for container2
48+
'''
49+
intersect = list(set(list1).intersection(list2))
50+
unique1 = list(set(list1).difference(list2))
51+
unique2 = list(set(list2).difference(list1))
52+
53+
# Return data structure
54+
comparison = {"shared": intersect,
55+
"removed": unique1,
56+
"added": unique2,
57+
"total1": len(list1),
58+
"total2": len(list2)}
59+
60+
return comparison
61+
62+
63+
64+
def compare_files(files1, files2):
65+
'''compare_files is a wrapper around compare_lists that will also calculate
66+
an information coefficient.
67+
'''
68+
comparison = compare_lists(files1, files2)
69+
70+
return information_coefficient(comparison['total1'],
71+
comparison['total2'],
72+
comparison['shared'])
73+
4274

4375
def compare_singularity_images(image_paths1,image_paths2=None):
4476
'''compare_singularity_images is a wrapper for compare_containers to compare
@@ -73,8 +105,8 @@ def compare_singularity_images(image_paths1,image_paths2=None):
73105
else:
74106
fileobj2,tar2 = get_image_tar(image2)
75107
members2 = [x.name for x in tar2]
76-
c = compare_lists(members1,members2)
77-
sim = information_coefficient(c['total1'],c['total2'],c['intersect'])
108+
c = compare_lists(members1, members2)
109+
sim = information_coefficient(c['total1'],c['total2'],c['shared'])
78110
delete_image_tar(fileobj2, tar2)
79111

80112
dfs.loc[image1,image2] = sim
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<head>
2+
<!-- Plotly.js -->
3+
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
4+
</head>
5+
6+
<body>
7+
8+
<div id="myDiv"></div>
9+
<script>
10+
11+
// var xValues = ['A', 'B', 'C', 'D', 'E'];
12+
var xValues = {{ X }};
13+
14+
// var yValues = ['W', 'X', 'Y', 'Z'];
15+
var yValues = {{ Y }};
16+
17+
// var zValues = [
18+
// [0.00, 0.00, 0.75, 0.75, 0.00],
19+
// [0.00, 0.00, 0.75, 0.75, 0.00],
20+
// [0.75, 0.75, 0.75, 0.75, 0.75],
21+
// [0.00, 0.00, 0.00, 0.75, 0.00]
22+
// ];
23+
24+
var zValues = [ {{ data }} ];
25+
26+
var colorscaleValue = [
27+
[0, '#3D9970'],
28+
[1, '#001f3f']
29+
];
30+
31+
var data = [{
32+
x: xValues,
33+
y: yValues,
34+
z: zValues,
35+
type: 'heatmap',
36+
colorscale: colorscaleValue,
37+
showscale: false
38+
}];
39+
40+
var layout = {
41+
title: '{{ title }}',
42+
annotations: [],
43+
xaxis: {
44+
ticks: '',
45+
side: 'top'
46+
},
47+
yaxis: {
48+
ticks: '',
49+
ticksuffix: ' ',
50+
width: 700,
51+
height: 900,
52+
autosize: false
53+
}
54+
};
55+
56+
for ( var i = 0; i < yValues.length; i++ ) {
57+
for ( var j = 0; j < xValues.length; j++ ) {
58+
var currentValue = zValues[i][j];
59+
if (currentValue != 0.0) {
60+
var textColor = 'white';
61+
}else{
62+
var textColor = 'black';
63+
}
64+
var result = {
65+
xref: 'x1',
66+
yref: 'y1',
67+
x: xValues[j],
68+
y: yValues[i],
69+
text: zValues[i][j],
70+
font: {
71+
family: 'Arial',
72+
size: 12,
73+
color: 'rgb(50, 171, 96)'
74+
},
75+
showarrow: false,
76+
font: {
77+
color: textColor
78+
}
79+
};
80+
layout.annotations.push(result);
81+
}
82+
}
83+
Plotly.newPlot('myDiv', data, layout);
84+
</script>
85+
</body>

singularity/views/trees.py

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,55 @@
4343

4444

4545

46-
def make_container_tree(folders,files,path_delim="/",parse_files=True):
47-
'''make_container_tree will convert a list of folders and files into a json structure that represents a graph.
48-
:param folders: a list of folders in the image
49-
:param files: a list of files in the folder
50-
:param parse_files: return 'files' lookup in result, to associate ID of node with files (default True)
51-
:param path_delim: the path delimiter, default is '/'
46+
def make_container_tree(files,
47+
folders=None,
48+
path_delim="/",
49+
parse_files=True,
50+
labels=None):
51+
52+
'''make_container_tree will convert a list of folders and files into a
53+
json structure that represents a graph.
54+
55+
Parameters
56+
==========
57+
folders: a list of folders in the image
58+
files: a list of files in the folder
59+
parse_files: return 'files' lookup in result, to associate ID of node with files (default True)
60+
path_delim: the path delimiter, default is '/'
61+
labels = dict() a lookup dictionary of labels to add to file nodes, if
62+
defined.
63+
5264
'''
65+
if folders == None:
66+
folders = files.copy()
67+
5368
nodes = {} # first we will make a list of nodes
5469
lookup = {}
5570
count = 1 # count will hold an id for nodes
5671
max_depth = 0
57-
for folder in folders:
58-
if folder != ".":
59-
folder = re.sub("^[.]/","",folder)
72+
73+
for folder_path in folders:
74+
if folder_path != ".":
75+
folder = re.sub("^[.]/","", folder_path)
6076
path_components = folder.split(path_delim)
77+
6178
for p in range(len(path_components)):
6279
path_component = path_components[p]
6380
fullpath = path_delim.join(path_components[0:p+1])
81+
6482
# Have we created the node yet?
6583
if fullpath not in lookup:
6684
lookup[fullpath] = count
67-
node = {"id":count,"name":path_component,"path":fullpath,"level":p,"children":[]}
85+
node = {"id": count,
86+
"name":path_component,
87+
"path":fullpath,
88+
"level":p,
89+
"children":[]}
6890
count +=1
91+
if labels is not None:
92+
if folder_path in labels:
93+
node['labels'] = labels[folder_path]
94+
6995
# Did we find a deeper level?
7096
if p > max_depth:
7197
max_depth = p
@@ -77,7 +103,7 @@ def make_container_tree(folders,files,path_delim="/",parse_files=True):
77103
parent_id = lookup[parent_path]
78104
node["parent"] = parent_id
79105
nodes[node['id']] = node
80-
106+
81107
# Now make the graph, we simply append children to their parents
82108
seen = []
83109
graph = []
@@ -104,8 +130,8 @@ def make_container_tree(folders,files,path_delim="/",parse_files=True):
104130
# Parse files to include in tree
105131
if parse_files == True:
106132
file_lookup = {}
107-
for filey in files:
108-
filey = re.sub("^[.]/","",filey)
133+
for file_name in files:
134+
filey = re.sub("^[.]/","",file_name)
109135
filepath,filename = os.path.split(filey)
110136
if filepath in lookup:
111137
folder_id = lookup[filepath]

0 commit comments

Comments
 (0)