block by syntagmatic 034f7124743e6d6ae6a666629dd664da

Thiocyanate Bioreactor Organisms

Full Screen

Organisms phylogeny from Bioreactor microbial ecosystems for thiocyanate and cyanide degradation unravelled with genome-resolved metagenomics by Kantor et al, downloaded from ggKbase Thiocyanate Bioreactor project.

Based on Tidy Tree using d3-hierarchy.

index.html

<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
  margin: 20px 0;
}

.node circle {
  fill: #555;
}

.node--leaf circle {
  fill: #bbb;
}

.node text {
  font: 12px sans-serif;
  text-shadow: 0 1px 0 #fff, 0 -1px 0 #fff, 1px 0 0 #fff, -1px 0 0 #fff;
}

.node--leaf text {
  display: none;
}

.link {
  fill: none;
  stroke: #bbb;
  stroke-opacity: 0.4;
  stroke-width: 1.5px;
}

</style>
<body>
<script src="//d3js.org/d3.v4.0.0-alpha.29.js"></script>
<script>

var width = 960,
    height = 920;

var burrow = function(table) {
  var obj = {};
  table.forEach(function(row) {
    var layer = obj;
    var tokenized = row.taxonomy.split(",").reverse().map(function(d) { return d.trim(); });
    tokenized.push(row.name);
    tokenized.forEach(function(key) {
      layer[key] = key in layer ? layer[key] : {};
      layer = layer[key];
    });
  });

  var descend = function(obj, depth) {
    var arr = [];
    var depth = depth || 0;
    for (var k in obj) {
      var child = {
        name: k,
        depth: depth,
        children: descend(obj[k], depth+1)
      };
      arr.push(child);
    }
    return arr;
  };

  return {
    name: "Bioreactor",
    children: descend(obj, 1),
    depth: 0
  }
};
    
var tree = d3.tree()
    .size([height, width - 180])

var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("height", height)
  .append("g")
    .attr("transform", "translate(76,0)");

d3.tsv("thiocyanate-organisms.tsv", function(error, data) {
  if (error) throw error;

  var root = d3.hierarchy(burrow(data));

  tree(root);

  var link = svg.selectAll(".link")
      .data(root.descendants().slice(1))
    .enter().append("path")
      .attr("class", "link")
      .attr("d", function(d) {
        return "M" + d.y + "," + d.x
            + "C" + (d.y + d.parent.y) / 2 + "," + d.x
            + " " + (d.y + d.parent.y) / 2 + "," + d.parent.x
            + " " + d.parent.y + "," + d.parent.x;
      });

  var node = svg.selectAll(".node")
      .data(root.descendants().reverse())     // reversing prevents children occluding parent text
    .enter().append("g")
      .attr("class", function(d) { return "node" + (d.children ? " node--internal" : " node--leaf"); })
      .attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; })

  node.append("circle")
      .attr("r", 2);

  node.append("text")
      .attr("dy", 3)
      .attr("x", function(d) { return d.depth > 0 ? 5 : -5; })
      .style("text-anchor", function(d) { return d.depth > 0 ? "start" : "end"; })
      .text(function(d) { return d.data.name; });
});

</script>