changeset 64:79dd7b62e4a8 draft

planemo upload for repository https://github.com/WGS-TB/MentaLiST/tree/master/galaxy commit c63eb1ab4395ff69f603f681fbde1134c69b3bcd-dirty
author dfornika
date Wed, 13 Jun 2018 19:25:46 -0400
parents c9d05c980d2a
children 2c58708d764c
files tools/mentalist_tree/mentalist_tree
diffstat 1 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tools/mentalist_tree/mentalist_tree	Wed Jun 13 19:02:38 2018 -0400
+++ b/tools/mentalist_tree/mentalist_tree	Wed Jun 13 19:25:46 2018 -0400
@@ -21,8 +21,22 @@
     distance_matrix = []
     for input_matrix_row in input_matrix:
         distance_matrix.append([int(i) for i in input_matrix_row])
+    """ np.tril() converts a matrix like this: [[0 1 2]
+                                                [1 0 1]
+                                                [2 1 0]]
+        ...into this: [[0 0 0]
+                       [1 0 0]
+                       [2 1 0]]
+        ...but what we need to pass to DistanceMatrix() is this: [[0]
+                                                                  [1 0]
+                                                                  [2 1 0]]
+        ...so that's what the (somewhat cryptic) code below does.
+    """
     distance_matrix = np.tril(np.array(distance_matrix))
     num_rows = distance_matrix.shape[0]
+    """ masking the distance matrix with tril_indices gives a linearized
+        distance matrix [0 1 0 2 1 0] that we need to re-construct into [[0], [1, 0], [2, 1, 0]]
+    """
     lower_triangular_idx_mask = np.tril_indices(num_rows)
     linear_distance_matrix = distance_matrix[lower_triangular_idx_mask]
     distance_matrix = []