Commits

Mark Howison  committed d129601

report: fixed bug in colormap for coloring by frequency

  • Participants
  • Parent commits 6cdd00f
  • Branches chloroplast, devel 3
    1. issue-6
    2. issue-7
    3. issue7a

Comments (0)

Files changed (3)

File gabi/compare.py

     kmers = graph.kmers()
     print "found kmer length", graph.k
 
+    palette = ("red", "blue", "forestgreen")
+
     # search for kmer seeds in each reference and color the nodes/edges
     # contained in the reference
     for i, reference in enumerate(args.REFERENCES):
         name = os.path.splitext(os.path.basename(reference))[0]
-        color = '"/set13/%d" style=bold' % (i % 3 + 1)
+        color = '%s penwidth=4.0' % palette[i % 3]
         colors, edges = color_nodes(kmers, graph, reference, color)
         open('compare%d.edges.txt' % i, 'w').write(','.join(map(str, edges)))
         graph.write_dot('compare%d.dot' % i, colors=colors)

File gabi/consensus.py

         if f > threshold:
             colors[e] = 'black'
         else:
-            colors[e] = 'grey90'
+            colors[e] = 'grey70'
     graph.write_dot(prefix+'-majority.dot', colors=colors)
     subprocess.check_call(
         ['dot', '-Tsvg', '-Kneato', prefix+'-majority.dot'],

File gabi/graph.py

 import ast
 import networkx as nx
 
-from collections import defaultdict
 from itertools import izip
 from random import randint
 
 dot_max_node_size = 1.0
 dot_min_node_size = 0.1
 dot_palette = (
-    (215,25,28),
+    (186,186,186),
     (253,174,97),
-    (186,186,186))
+    (215,25,28))
 
 def colormap(palette, x):
     l = len(palette) - 1
-    x = float(1.0-x) * l
-    i = int(x)
-    if i < l:
-        x -= i
-        assert x < 1.0
+    x = float(x) * l
+    lo = int(x)
+    if lo < l:
+        mid = x - lo
+        hi = lo + 1
         rgb = (
-            x * palette[i][0] + (1.0 - x) * palette[i+1][0],
-            x * palette[i][1] + (1.0 - x) * palette[i+1][1],
-            x * palette[i][2] + (1.0 - x) * palette[i+1][2])
+            int(palette[lo][0] + mid * (palette[hi][0] - palette[lo][0])),
+            int(palette[lo][1] + mid * (palette[hi][1] - palette[lo][1])),
+            int(palette[lo][2] + mid * (palette[hi][2] - palette[lo][2])))
     else:
-        rgb = palette[i]
+        rgb = palette[-1]
     return '#%02x%02x%02x' % rgb
 
 def choice(x):
                 if frequencies:
                     color = 'color="%s"' % colormap(dot_palette, frequencies.get(id, 0.0))
                 elif colors:
-                    color = "color=%s" % colors.get(id, "grey40")
+                    color = "color=%s" % colors.get(id, "grey70")
                 elif active:
                     if self.A.has_node(n):
                         color = "color=red"
                     else:
-                        color = "color=grey90"
+                        color = "color=grey70"
                 else:
-                    color = "color=grey"
+                    color = "color=grey70"
                 print >>f, '"%d" [id="%s" label="" shape=circle penwidth=4.0 %s width=%f];' % (n, id, color, width)
             for n1, n2 in self.G.edges_iter():
                 id = "edge%d" % self.G.edge[n1][n2]['id']
                 if frequencies:
                     color = 'color="%s"' % colormap(dot_palette, frequencies.get(id, 0.0))
                 elif colors:
-                    color = "color=%s" % colors.get(id, "grey40")
+                    color = "color=%s" % colors.get(id, "grey70")
                 elif active:
                     if self.A.has_edge(n1, n2):
                         color = "color=red"
                     else:
-                        color = "color=grey90"
+                        color = "color=grey70"
                 else:
-                    color = "color=grey"
+                    color = "color=grey70"
                 print >>f, '"%d" -- "%d" [id="%s" %s penwidth=2.0];' % (n1, n2, id, color)
             print >>f, '}'