Skip to content

Commit

Permalink
Fixed issue #1
Browse files Browse the repository at this point in the history
  • Loading branch information
pverscha committed Mar 31, 2019
1 parent 5c95683 commit 4bd1113
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
20 changes: 20 additions & 0 deletions examples/data/breaks.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Family,Sample0,Sample1,Sample2,Sample3,Sample4,Sample5,Sample6,Sample7,Sample8,Sample9,Sample10,Sample11,Sample12,Sample13,Sample14,Sample15,Sample16,Sample17,Sample18,Sample19
Crenarchaeota,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Euryarchaeota,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Actinobacteria,44,285,2,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Aquificae,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Bacteroidetes,5,58,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Cyanobacteria,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Elusimicrobia,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Firmicutes,164,234,8,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Fusobacteria,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Proteobacteria,3,6,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0
Spirochaetes,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Tenericutes,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Dictyosteliales,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Entamoebidae,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Fungi,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Metazoa,0,0,55,0,51,40,47,5,8,10,48,8,59,8,64,8,8,8,55,38
Pyrenomonadales,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Viridiplantae,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Nidovirales,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
4 changes: 2 additions & 2 deletions examples/heatmap.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<div id="heatmap"></div>
<button id="cluster">Cluster!</button>

<script type="module">
<script>

d3.csv('data/dendrogram.csv')
d3.csv('data/breaks.csv')
.then(function(data) {

let grid = [];
Expand Down
5 changes: 3 additions & 2 deletions src/heatmap/heatmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {HeatmapData, HeatmapElement, HeatmapValue} from "./input";
import Reorderer from "../reorder/reorderer";
import MoloReorderer from "../reorder/moloReorderer";

class Heatmap {
export class Heatmap {
private element: HTMLElement;
private settings: HeatmapSettings;

Expand Down Expand Up @@ -82,12 +82,13 @@ class Heatmap {

let molo: Reorderer = new MoloReorderer();

console.log("Reorder rows");
// Create a new ClusterElement for every row that exists. This ClusterElement keeps track of an array of numbers that correspond to a row's values.
let rowElements: ClusterElement[] = this.rows.map((el, idx) => new ClusterElement(this.values[idx].filter(val => val.rowId == el.id).map(x => x.value), el.id!));
// Now we perform a depth first search on the result in order to find the order of the values
let rowOrder: number[] = this.determineOrder(molo.reorder(clusterer.cluster(rowElements)), (id: string) => this.rowMap.get(id)!.idx!);


console.log("Reorder columns");
// Create a new ClusterElement for every column that exists.
let columnElements: ClusterElement[] = this.columns.map((el, idx) => new ClusterElement(this.values.map(col => col[idx].value), el.id!));
let columnOrder: number[] = this.determineOrder(clusterer.cluster(columnElements), (id: string) => this.columnMap.get(id)!.idx!);
Expand Down
2 changes: 1 addition & 1 deletion src/reorder/moloReorderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class MoloReorderer implements Reorderer {
let leftMin = this.nodeMinMap.get(leftSorted);
let rightMin = this.nodeMinMap.get(rightSorted);

if (!leftMin || !rightMin) {
if (leftMin === undefined || rightMin === undefined) {
throw "One of the recursive calls to sort a subtree did not yield a minimum value.";
}

Expand Down

0 comments on commit 4bd1113

Please sign in to comment.