@sjcrh/proteinpaint-rust 2.11.1 → 2.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.toml +8 -0
- package/package.json +1 -1
- package/src/cluster.rs +102 -413
- package/src/test_examples.rs +642 -0
- package/src/wilcoxon.rs +427 -0
package/Cargo.toml
CHANGED
|
@@ -24,6 +24,10 @@ libmath = "^0.2.1"
|
|
|
24
24
|
json = "^0.12.4"
|
|
25
25
|
serde = {version = "^1.0.147", features = ["derive"]}
|
|
26
26
|
serde_json="^1.0.88"
|
|
27
|
+
num = "^0.4.1"
|
|
28
|
+
#r_stats = { git = "https://github.com/derekdreery/r_stats.git"}
|
|
29
|
+
#r_stats = { git = "https://github.com/robinpaul85/r_stats.git"}
|
|
30
|
+
|
|
27
31
|
|
|
28
32
|
[profile.release]
|
|
29
33
|
lto = "fat"
|
|
@@ -58,3 +62,7 @@ path="src/sv.rs"
|
|
|
58
62
|
[[bin]]
|
|
59
63
|
name="cluster"
|
|
60
64
|
path="src/cluster.rs"
|
|
65
|
+
|
|
66
|
+
#[[bin]]
|
|
67
|
+
#name="wilcoxon"
|
|
68
|
+
#path="src/wilcoxon.rs"
|
package/package.json
CHANGED
package/src/cluster.rs
CHANGED
|
@@ -55,35 +55,28 @@ use colorgrad;
|
|
|
55
55
|
use json;
|
|
56
56
|
use json::JsonValue;
|
|
57
57
|
use kodama::{linkage, Method};
|
|
58
|
-
use nalgebra::base::dimension::Const;
|
|
59
58
|
use nalgebra::base::dimension::Dyn;
|
|
60
59
|
use nalgebra::base::Matrix;
|
|
61
60
|
use nalgebra::base::VecStorage;
|
|
62
61
|
use nalgebra::DMatrix;
|
|
63
|
-
use serde::ser::{SerializeStruct, Serializer};
|
|
64
62
|
use serde::{Deserialize, Serialize};
|
|
65
63
|
use serde_json;
|
|
66
64
|
use std::env;
|
|
67
65
|
//use ndarray::Array1;
|
|
68
66
|
use ndarray::ArrayBase;
|
|
69
67
|
use ndarray::OwnedRepr;
|
|
70
|
-
use petgraph::algo::dijkstra;
|
|
71
|
-
//use petgraph::dot::Dot;
|
|
72
|
-
use petgraph::graph::NodeIndex;
|
|
73
|
-
use petgraph::prelude::Graph;
|
|
74
68
|
use plotters::prelude::*;
|
|
75
69
|
use rayon::prelude::*;
|
|
76
70
|
use std::any::type_name;
|
|
77
71
|
use std::io;
|
|
78
72
|
use std::time::Instant;
|
|
79
73
|
|
|
80
|
-
#[
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
height: f64, // Contains the weight of the dissimilarity of that particular step. For original nodes this will just be the height from the top most node
|
|
74
|
+
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
|
|
75
|
+
struct Steps {
|
|
76
|
+
cluster1: usize,
|
|
77
|
+
cluster2: usize,
|
|
78
|
+
dissimilarity: f64,
|
|
79
|
+
size: usize,
|
|
87
80
|
}
|
|
88
81
|
|
|
89
82
|
#[allow(dead_code)]
|
|
@@ -96,67 +89,6 @@ struct NodeCoordinate {
|
|
|
96
89
|
y: Option<f64>, // The y-position stores the relative distance from the last (top most) node in the dendrogram
|
|
97
90
|
}
|
|
98
91
|
|
|
99
|
-
impl Serialize for NodeCoordinate {
|
|
100
|
-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
101
|
-
where
|
|
102
|
-
S: Serializer,
|
|
103
|
-
{
|
|
104
|
-
let x = &self.x;
|
|
105
|
-
let y = &self.y;
|
|
106
|
-
|
|
107
|
-
let mut state;
|
|
108
|
-
if x.is_some() && y.is_some() {
|
|
109
|
-
state = serializer.serialize_struct("NodeCoordinate", 2)?;
|
|
110
|
-
state.serialize_field("x", &self.x)?;
|
|
111
|
-
state.serialize_field("y", &self.y)?;
|
|
112
|
-
} else {
|
|
113
|
-
state = serializer.serialize_struct("NodeCoordinate", 0)?;
|
|
114
|
-
}
|
|
115
|
-
state.end()
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
#[allow(dead_code)]
|
|
120
|
-
#[derive(Debug, Clone, Deserialize)]
|
|
121
|
-
struct NewNodeRelativeCoordinates {
|
|
122
|
-
node_id: usize, // Node ID of the current node.
|
|
123
|
-
node_coordinates: NodeCoordinate, // (X,Y) coordinates of the current node.
|
|
124
|
-
#[serde(skip_serializing_if = "Vec::is_empty")]
|
|
125
|
-
child_nodes: Vec<usize>, // ID's of the child node (if it exists). There will be no child node for the original (input) nodes in the dendrogram.
|
|
126
|
-
#[serde(skip_serializing_if = "Vec::is_empty")]
|
|
127
|
-
child_node_coordinates: Vec<NodeCoordinate>, // (X,Y) coordinates of each of the two child nodes (if they exist).
|
|
128
|
-
all_original_nodes: Vec<usize>, // Contains list of original descendant nodes. To be displayed in UI on clicking a derived node (or line).
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
impl Serialize for NewNodeRelativeCoordinates {
|
|
132
|
-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
133
|
-
where
|
|
134
|
-
S: Serializer,
|
|
135
|
-
{
|
|
136
|
-
let child_nodes = &self.child_nodes;
|
|
137
|
-
let node_id = &self.node_id;
|
|
138
|
-
let node_coordinates = &self.node_coordinates;
|
|
139
|
-
let child_node_coordinates = &self.child_node_coordinates;
|
|
140
|
-
let all_original_nodes = &self.all_original_nodes;
|
|
141
|
-
|
|
142
|
-
let mut state;
|
|
143
|
-
if child_nodes.len() == 0 && all_original_nodes.len() == 0 {
|
|
144
|
-
// This will be true in case of the original nodes
|
|
145
|
-
state = serializer.serialize_struct("NewNodeRelativeCoordinates", 2)?;
|
|
146
|
-
state.serialize_field("node_id", node_id)?;
|
|
147
|
-
state.serialize_field("node_coordinates", &self.node_coordinates)?;
|
|
148
|
-
} else {
|
|
149
|
-
state = serializer.serialize_struct("NewNodeRelativeCoordinates", 5)?;
|
|
150
|
-
state.serialize_field("node_id", node_id)?;
|
|
151
|
-
state.serialize_field("child_nodes", child_nodes)?;
|
|
152
|
-
state.serialize_field("node_coordinates", node_coordinates)?;
|
|
153
|
-
state.serialize_field("child_node_coordinates", child_node_coordinates)?;
|
|
154
|
-
state.serialize_field("all_original_nodes", all_original_nodes)?;
|
|
155
|
-
}
|
|
156
|
-
state.end()
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
92
|
#[allow(dead_code)]
|
|
161
93
|
fn type_of<T>(_: T) -> &'static str {
|
|
162
94
|
type_name::<T>()
|
|
@@ -281,12 +213,11 @@ fn euclidean_distance3(
|
|
|
281
213
|
fn sort_elements(
|
|
282
214
|
coordinates: &Matrix<f64, Dyn, Dyn, VecStorage<f64, Dyn, Dyn>>,
|
|
283
215
|
cluster_method: &String,
|
|
284
|
-
) ->
|
|
216
|
+
) -> Vec<Steps> {
|
|
285
217
|
//fn sort_elements(coordinates: &Vec<Vec<f64>>) -> Vec<usize> {
|
|
286
218
|
//fn sort_elements(coordinates: &Vec<Array1<f64>>) -> Vec<usize> {
|
|
287
219
|
let new_now = Instant::now();
|
|
288
|
-
let mut
|
|
289
|
-
let mut node_coordinates_list = Vec::<NewNodeRelativeCoordinates>::new();
|
|
220
|
+
let mut steps_vec = Vec::<Steps>::new();
|
|
290
221
|
if coordinates.len() > 0 {
|
|
291
222
|
//let mut condensed = vec![];
|
|
292
223
|
//for row in 0..coordinates.len() - 1 {
|
|
@@ -295,17 +226,6 @@ fn sort_elements(
|
|
|
295
226
|
// }
|
|
296
227
|
//}
|
|
297
228
|
let mut condensed = euclidean_distance4(coordinates);
|
|
298
|
-
let column_means = Matrix::column_mean(coordinates);
|
|
299
|
-
//println!("column_means:{:?}", column_means);
|
|
300
|
-
|
|
301
|
-
let mut min_mean_value = 100000000000.0;
|
|
302
|
-
let mut min_mean_value_index = 0;
|
|
303
|
-
for i in 0..column_means.len() {
|
|
304
|
-
if column_means[i] < min_mean_value {
|
|
305
|
-
min_mean_value = column_means[i];
|
|
306
|
-
min_mean_value_index = i;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
229
|
|
|
310
230
|
//println!("condensed:{:?}", condensed);
|
|
311
231
|
let new_now2 = Instant::now();
|
|
@@ -316,7 +236,9 @@ fn sort_elements(
|
|
|
316
236
|
//println!("coordinates.len():{:?}", coordinates.len());
|
|
317
237
|
|
|
318
238
|
let dend;
|
|
319
|
-
if cluster_method == &"
|
|
239
|
+
if cluster_method == &"Single" {
|
|
240
|
+
dend = linkage(&mut condensed, coordinates.nrows(), Method::Single);
|
|
241
|
+
} else if cluster_method == &"Complete" {
|
|
320
242
|
dend = linkage(&mut condensed, coordinates.nrows(), Method::Complete);
|
|
321
243
|
} else if cluster_method == &"Average" {
|
|
322
244
|
dend = linkage(&mut condensed, coordinates.nrows(), Method::Average);
|
|
@@ -338,270 +260,22 @@ fn sort_elements(
|
|
|
338
260
|
new_now3.duration_since(new_now2)
|
|
339
261
|
);
|
|
340
262
|
|
|
341
|
-
let mut deps = Graph::new_undirected();
|
|
342
|
-
|
|
343
|
-
// Adding nodes and edges to graph
|
|
344
|
-
println!("Number of original nodes:{}", coordinates.nrows());
|
|
345
|
-
for i in 0..coordinates.nrows() {
|
|
346
|
-
// Add original nodes to graph
|
|
347
|
-
deps.add_node(i);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
263
|
//println!("dend.steps().len(){:?}", dend.steps().len());
|
|
351
|
-
|
|
352
|
-
|
|
264
|
+
println!("Number of nodes:{}", coordinates.nrows());
|
|
265
|
+
//println!("max_length_node_distance:{}", max_length_node_distance);
|
|
353
266
|
for i in 0..dend.steps().len() {
|
|
354
267
|
let step = &dend.steps()[i];
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
//let node2 = deps.add_node(step.cluster2);
|
|
361
|
-
let node3 = deps.add_node(current_cluster_label);
|
|
362
|
-
//println!("node1:{:?}", node1);
|
|
363
|
-
|
|
364
|
-
let new_node = NewNodeInfo {
|
|
365
|
-
node_id: current_cluster_label,
|
|
366
|
-
child_nodes: vec![step.cluster1, step.cluster2],
|
|
367
|
-
height: step.dissimilarity,
|
|
368
|
-
};
|
|
369
|
-
new_nodes.push(new_node);
|
|
370
|
-
// Adding edges
|
|
371
|
-
deps.add_edge(
|
|
372
|
-
NodeIndex::from(step.cluster1 as u32),
|
|
373
|
-
node3,
|
|
374
|
-
step.dissimilarity,
|
|
375
|
-
);
|
|
376
|
-
deps.add_edge(
|
|
377
|
-
NodeIndex::from(step.cluster2 as u32),
|
|
378
|
-
node3,
|
|
379
|
-
step.dissimilarity,
|
|
380
|
-
);
|
|
381
|
-
|
|
382
|
-
if i == dend.steps().len() - 1 {
|
|
383
|
-
max_length_node_distance = step.dissimilarity
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
//println!("Graph:{}", Dot::new(&deps));
|
|
387
|
-
let new_now4 = Instant::now();
|
|
388
|
-
println!(
|
|
389
|
-
"Time taken to generate graph:{:?}",
|
|
390
|
-
new_now4.duration_since(new_now3)
|
|
391
|
-
);
|
|
392
|
-
|
|
393
|
-
let mut remaining_nodes: Vec<usize> = (0..coordinates.nrows()).collect();
|
|
394
|
-
//println!("remaining_nodes:{:?}", remaining_nodes);
|
|
395
|
-
|
|
396
|
-
// Initialize first node from cluster1 of first step, not sure if this is the best place from where to stop
|
|
397
|
-
//let mut current_node = dend.steps()[0].cluster1.clone();
|
|
398
|
-
let mut current_node = min_mean_value_index;
|
|
399
|
-
|
|
400
|
-
let mut num_iter = 0;
|
|
401
|
-
while remaining_nodes.len() > 0 {
|
|
402
|
-
let mut smallest_distance = 1000000000; // Initialized to very high value
|
|
403
|
-
|
|
404
|
-
//println!("current_node:{}", current_node);
|
|
405
|
-
let distances = dijkstra(
|
|
406
|
-
&deps,
|
|
407
|
-
NodeIndex::from(current_node as u32),
|
|
408
|
-
None,
|
|
409
|
-
//Some(NodeIndex::from(node as u32)),
|
|
410
|
-
|_| 1,
|
|
411
|
-
);
|
|
412
|
-
|
|
413
|
-
//println!("distances:{:?}", distances);
|
|
414
|
-
let mut next_node = current_node;
|
|
415
|
-
let mut degenerate_nodes = Vec::<usize>::new();
|
|
416
|
-
for item in distances {
|
|
417
|
-
if item.0.le(&NodeIndex::from(coordinates.nrows() as u32 - 1)) == true
|
|
418
|
-
&& item.0.ne(&NodeIndex::from(current_node as u32)) == true
|
|
419
|
-
&& sorted_nodes.contains(&item.0.index()) == false
|
|
420
|
-
{
|
|
421
|
-
//println!("item:{:?}", item);
|
|
422
|
-
if item.1 < smallest_distance {
|
|
423
|
-
smallest_distance = item.1;
|
|
424
|
-
next_node = item.0.index();
|
|
425
|
-
degenerate_nodes = vec![]; // Delete all previous degenerate nodes if another node with closer distance is found.
|
|
426
|
-
} else if item.1 == smallest_distance {
|
|
427
|
-
// If a node with the same distance is found as that in the variable smallest_distance then add both nodes to degenerate_nodes vector
|
|
428
|
-
if degenerate_nodes.len() == 0 {
|
|
429
|
-
// Add the first node only if the vector is empty
|
|
430
|
-
degenerate_nodes.push(next_node)
|
|
431
|
-
}
|
|
432
|
-
degenerate_nodes.push(item.0.index());
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
if item.0.eq(&NodeIndex::from(
|
|
436
|
-
new_nodes[new_nodes.len() - 1].node_id as u32,
|
|
437
|
-
)) == true
|
|
438
|
-
{
|
|
439
|
-
//node_y = item.1;
|
|
440
|
-
//println!("item:{:?}", item);
|
|
441
|
-
node_coordinates_list.push(NewNodeRelativeCoordinates {
|
|
442
|
-
node_id: current_node,
|
|
443
|
-
node_coordinates: NodeCoordinate {
|
|
444
|
-
x: Some(num_iter as f64),
|
|
445
|
-
y: Some(1.0),
|
|
446
|
-
},
|
|
447
|
-
child_nodes: vec![], // These are the original nodes, so they have no child nodes
|
|
448
|
-
child_node_coordinates: vec![
|
|
449
|
-
NodeCoordinate { x: None, y: None },
|
|
450
|
-
NodeCoordinate { x: None, y: None },
|
|
451
|
-
],
|
|
452
|
-
all_original_nodes: vec![],
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
if degenerate_nodes.len() > 0 {
|
|
458
|
-
next_node = closest_degenerate_nodes(current_node, degenerate_nodes, &column_means);
|
|
459
|
-
}
|
|
460
|
-
//println!("next_node:{}", next_node);
|
|
461
|
-
sorted_nodes.push(current_node);
|
|
462
|
-
remaining_nodes.remove(
|
|
463
|
-
remaining_nodes
|
|
464
|
-
.iter()
|
|
465
|
-
.position(|x| *x == current_node)
|
|
466
|
-
.expect(&(current_node.to_string() + " not found")),
|
|
467
|
-
);
|
|
468
|
-
current_node = next_node;
|
|
469
|
-
num_iter += 1;
|
|
470
|
-
//println!("remaining_nodes:{:?}", remaining_nodes);
|
|
471
|
-
}
|
|
472
|
-
//println!("sorted_nodes:{:?}", sorted_nodes);
|
|
473
|
-
for i in 0..new_nodes.len() {
|
|
474
|
-
let current_node = &new_nodes[i];
|
|
475
|
-
let mut all_original_nodes = Vec::<usize>::new();
|
|
476
|
-
//println!("current_node:{:?}", current_node);
|
|
477
|
-
let distances = dijkstra(
|
|
478
|
-
&deps,
|
|
479
|
-
NodeIndex::from(current_node.node_id as u32),
|
|
480
|
-
None,
|
|
481
|
-
//Some(NodeIndex::from(node as u32)),
|
|
482
|
-
|_| 1,
|
|
483
|
-
);
|
|
484
|
-
//println!("distances:{:?}", distances);
|
|
485
|
-
|
|
486
|
-
// Computing relative y-coordinate of new node
|
|
487
|
-
let mut node_y = 0.0;
|
|
488
|
-
for item in distances {
|
|
489
|
-
if item.0.eq(&NodeIndex::from(
|
|
490
|
-
new_nodes[new_nodes.len() - 1].node_id as u32,
|
|
491
|
-
)) == true
|
|
492
|
-
{
|
|
493
|
-
node_y =
|
|
494
|
-
(max_length_node_distance - current_node.height) / max_length_node_distance;
|
|
495
|
-
// Normalizing distance with distance of the farthest node
|
|
496
|
-
//println!("item:{:?}", item);
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
//if item.1 > max_length_node_distance {
|
|
500
|
-
// max_length_node_distance = item.1
|
|
501
|
-
//}
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
let (child_node1_x, child_node2_x): (Option<f64>, Option<f64>);
|
|
505
|
-
let (child_node1_y, child_node2_y): (Option<f64>, Option<f64>);
|
|
506
|
-
let child1_search_result = node_coordinates_list
|
|
507
|
-
.iter()
|
|
508
|
-
.find(|&i| i.node_id == current_node.child_nodes[0]);
|
|
509
|
-
match child1_search_result {
|
|
510
|
-
Some(item) => {
|
|
511
|
-
child_node1_x = item.node_coordinates.x;
|
|
512
|
-
child_node1_y = item.node_coordinates.y;
|
|
513
|
-
if item.node_id < coordinates.nrows() {
|
|
514
|
-
// Select only original nodes and put them in all_original_nodes
|
|
515
|
-
all_original_nodes.push(item.node_id)
|
|
516
|
-
}
|
|
517
|
-
for child_item in &item.all_original_nodes {
|
|
518
|
-
// Iterate through the child's all_original_nodes vector and add them to the current vectors all_original_nodes
|
|
519
|
-
all_original_nodes.push(*child_item)
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
None => {
|
|
523
|
-
// Should not happen
|
|
524
|
-
panic!(
|
|
525
|
-
"X-coordinate of child node not found:{}",
|
|
526
|
-
current_node.child_nodes[0]
|
|
527
|
-
);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
let child2_search_result = node_coordinates_list
|
|
532
|
-
.iter()
|
|
533
|
-
.find(|&i| i.node_id == current_node.child_nodes[1]);
|
|
534
|
-
match child2_search_result {
|
|
535
|
-
Some(item) => {
|
|
536
|
-
child_node2_x = item.node_coordinates.x;
|
|
537
|
-
child_node2_y = item.node_coordinates.y;
|
|
538
|
-
if item.node_id < coordinates.nrows() {
|
|
539
|
-
// Select only original nodes and put them in all_original_nodes
|
|
540
|
-
all_original_nodes.push(item.node_id)
|
|
541
|
-
}
|
|
542
|
-
for child_item in &item.all_original_nodes {
|
|
543
|
-
// Iterate through the child's all_original_nodes vector and add them to the current vectors all_original_nodes
|
|
544
|
-
all_original_nodes.push(*child_item)
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
None => {
|
|
548
|
-
// Should not happen
|
|
549
|
-
panic!(
|
|
550
|
-
"X-coordinate of child node not found:{}",
|
|
551
|
-
current_node.child_nodes[1]
|
|
552
|
-
);
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
node_coordinates_list.push(NewNodeRelativeCoordinates {
|
|
557
|
-
node_id: current_node.node_id,
|
|
558
|
-
node_coordinates: NodeCoordinate {
|
|
559
|
-
x: Some((child_node1_x.unwrap() + child_node2_x.unwrap()) / 2.0),
|
|
560
|
-
y: Some(node_y),
|
|
561
|
-
},
|
|
562
|
-
child_nodes: current_node.child_nodes.clone(),
|
|
563
|
-
child_node_coordinates: vec![
|
|
564
|
-
NodeCoordinate {
|
|
565
|
-
x: child_node1_x,
|
|
566
|
-
y: child_node1_y,
|
|
567
|
-
},
|
|
568
|
-
NodeCoordinate {
|
|
569
|
-
x: child_node2_x,
|
|
570
|
-
y: child_node2_y,
|
|
571
|
-
},
|
|
572
|
-
],
|
|
573
|
-
all_original_nodes: all_original_nodes,
|
|
268
|
+
steps_vec.push(Steps {
|
|
269
|
+
cluster1: step.cluster1,
|
|
270
|
+
cluster2: step.cluster2,
|
|
271
|
+
dissimilarity: step.dissimilarity,
|
|
272
|
+
size: step.size,
|
|
574
273
|
})
|
|
575
274
|
}
|
|
576
|
-
//println!("node_coordinates_final:{:?}", node_coordinates_final);
|
|
577
|
-
let new_now5 = Instant::now();
|
|
578
|
-
println!(
|
|
579
|
-
"Time for sorting nodes:{:?}",
|
|
580
|
-
new_now5.duration_since(new_now4)
|
|
581
|
-
);
|
|
582
275
|
} else {
|
|
583
276
|
panic!("The dissimilarity matrix length cannot be zero");
|
|
584
277
|
}
|
|
585
|
-
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
fn closest_degenerate_nodes(
|
|
589
|
-
current_node: usize,
|
|
590
|
-
degenerate_nodes: Vec<usize>,
|
|
591
|
-
//means: &Matrix<f64, Const<1>, Dyn, VecStorage<f64, Const<1>, Dyn>>,
|
|
592
|
-
means: &Matrix<f64, Dyn, Const<1>, VecStorage<f64, Dyn, Const<1>>>,
|
|
593
|
-
) -> usize {
|
|
594
|
-
let mean_current_node = means[current_node];
|
|
595
|
-
let mut closest_node = 0;
|
|
596
|
-
let mut min_diff = 100000000000000.0;
|
|
597
|
-
for item in degenerate_nodes {
|
|
598
|
-
let mean_degenerate_node = means[item];
|
|
599
|
-
if (mean_degenerate_node - mean_current_node).abs() < min_diff {
|
|
600
|
-
min_diff = (mean_degenerate_node - mean_current_node).abs();
|
|
601
|
-
closest_node = item;
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
closest_node
|
|
278
|
+
steps_vec
|
|
605
279
|
}
|
|
606
280
|
|
|
607
281
|
fn main() {
|
|
@@ -679,11 +353,11 @@ fn main() {
|
|
|
679
353
|
}
|
|
680
354
|
//println!("cluster_method:{}", cluster_method);
|
|
681
355
|
|
|
682
|
-
let
|
|
356
|
+
let _plot_image;
|
|
683
357
|
let plot_image_option = &json_string["plot_image"].as_bool();
|
|
684
358
|
match plot_image_option {
|
|
685
|
-
Some(plot_image_op) =>
|
|
686
|
-
None =>
|
|
359
|
+
Some(plot_image_op) => _plot_image = plot_image_op.to_owned(),
|
|
360
|
+
None => _plot_image = false,
|
|
687
361
|
}
|
|
688
362
|
//println!("plot_image:{}", plot_image);
|
|
689
363
|
|
|
@@ -732,75 +406,88 @@ fn main() {
|
|
|
732
406
|
|
|
733
407
|
// Build our condensed matrix by computinghe dissimilarity between all
|
|
734
408
|
// possible coordinate pairs.
|
|
735
|
-
let (
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
println!("sorted_row_elements:{:?}", sorted_row_elements);
|
|
742
|
-
let mut sorted_row_names = Vec::<String>::new();
|
|
743
|
-
let mut sorted_col_names = Vec::<String>::new();
|
|
744
|
-
|
|
745
|
-
match row_string_search.as_str() {
|
|
746
|
-
Some(_row_string_se) => {
|
|
747
|
-
sorted_row_names = sorted_row_elements
|
|
748
|
-
.clone()
|
|
749
|
-
.into_iter()
|
|
750
|
-
.map(|x| row_names[x].clone())
|
|
751
|
-
.collect::<Vec<String>>();
|
|
752
|
-
}
|
|
753
|
-
None => {}
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
match col_string_search.as_str() {
|
|
757
|
-
Some(_col_string_se) => {
|
|
758
|
-
sorted_col_names = sorted_col_elements
|
|
759
|
-
.clone()
|
|
760
|
-
.into_iter()
|
|
761
|
-
.map(|x| col_names[x].clone())
|
|
762
|
-
.collect::<Vec<String>>();
|
|
763
|
-
}
|
|
764
|
-
None => {}
|
|
765
|
-
}
|
|
766
|
-
//println!("sorted_row_names:{:?}", sorted_row_names);
|
|
767
|
-
//println!("sorted_col_names:{:?}", sorted_col_names);
|
|
768
|
-
|
|
769
|
-
let mut sorted_col_coordinates_string = "[".to_string();
|
|
770
|
-
for i in 0..sorted_col_coordinates.len() {
|
|
771
|
-
sorted_col_coordinates_string +=
|
|
772
|
-
&serde_json::to_string(&sorted_col_coordinates[i]).unwrap();
|
|
773
|
-
if i != sorted_col_coordinates.len() - 1 {
|
|
774
|
-
sorted_col_coordinates_string += &",".to_string();
|
|
409
|
+
let col_steps = sort_elements(&input_matrix, &cluster_method);
|
|
410
|
+
let mut col_output_string = "[".to_string();
|
|
411
|
+
for i in 0..col_steps.len() {
|
|
412
|
+
col_output_string += &serde_json::to_string(&col_steps[i]).unwrap();
|
|
413
|
+
if i != col_steps.len() - 1 {
|
|
414
|
+
col_output_string += &",".to_string();
|
|
775
415
|
}
|
|
776
416
|
}
|
|
777
|
-
|
|
778
|
-
println!("
|
|
779
|
-
|
|
780
|
-
let mut
|
|
781
|
-
for i in 0..
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
sorted_row_coordinates_string += &",".to_string();
|
|
417
|
+
col_output_string += &"]".to_string();
|
|
418
|
+
println!("colSteps:{:?}", col_output_string);
|
|
419
|
+
let row_steps = sort_elements(&input_matrix.transpose(), &cluster_method);
|
|
420
|
+
let mut row_output_string = "[".to_string();
|
|
421
|
+
for i in 0..row_steps.len() {
|
|
422
|
+
row_output_string += &serde_json::to_string(&row_steps[i]).unwrap();
|
|
423
|
+
if i != row_steps.len() - 1 {
|
|
424
|
+
row_output_string += &",".to_string();
|
|
786
425
|
}
|
|
787
426
|
}
|
|
788
|
-
|
|
789
|
-
println!("
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
427
|
+
row_output_string += &"]".to_string();
|
|
428
|
+
println!("rowSteps:{:?}", row_output_string);
|
|
429
|
+
//let mut sorted_row_names = Vec::<String>::new();
|
|
430
|
+
//let mut sorted_col_names = Vec::<String>::new();
|
|
431
|
+
//
|
|
432
|
+
//match row_string_search.as_str() {
|
|
433
|
+
// Some(_row_string_se) => {
|
|
434
|
+
// sorted_row_names = sorted_row_elements
|
|
435
|
+
// .clone()
|
|
436
|
+
// .into_iter()
|
|
437
|
+
// .map(|x| row_names[x].clone())
|
|
438
|
+
// .collect::<Vec<String>>();
|
|
439
|
+
// }
|
|
440
|
+
// None => {}
|
|
441
|
+
//}
|
|
442
|
+
//
|
|
443
|
+
//match col_string_search.as_str() {
|
|
444
|
+
// Some(_col_string_se) => {
|
|
445
|
+
// sorted_col_names = sorted_col_elements
|
|
446
|
+
// .clone()
|
|
447
|
+
// .into_iter()
|
|
448
|
+
// .map(|x| col_names[x].clone())
|
|
449
|
+
// .collect::<Vec<String>>();
|
|
450
|
+
// }
|
|
451
|
+
// None => {}
|
|
452
|
+
//}
|
|
453
|
+
////println!("sorted_row_names:{:?}", sorted_row_names);
|
|
454
|
+
////println!("sorted_col_names:{:?}", sorted_col_names);
|
|
455
|
+
//
|
|
456
|
+
//let mut sorted_col_coordinates_string = "[".to_string();
|
|
457
|
+
//for i in 0..sorted_col_coordinates.len() {
|
|
458
|
+
// sorted_col_coordinates_string +=
|
|
459
|
+
// &serde_json::to_string(&sorted_col_coordinates[i]).unwrap();
|
|
460
|
+
// if i != sorted_col_coordinates.len() - 1 {
|
|
461
|
+
// sorted_col_coordinates_string += &",".to_string();
|
|
462
|
+
// }
|
|
463
|
+
//}
|
|
464
|
+
//sorted_col_coordinates_string += &"]".to_string();
|
|
465
|
+
////println!("sorted_col_coordinates:{:?}", sorted_col_coordinates_string);
|
|
466
|
+
//
|
|
467
|
+
//let mut sorted_row_coordinates_string = "[".to_string();
|
|
468
|
+
//for i in 0..sorted_row_coordinates.len() {
|
|
469
|
+
// sorted_row_coordinates_string +=
|
|
470
|
+
// &serde_json::to_string(&sorted_row_coordinates[i]).unwrap();
|
|
471
|
+
// if i != sorted_row_coordinates.len() - 1 {
|
|
472
|
+
// sorted_row_coordinates_string += &",".to_string();
|
|
473
|
+
// }
|
|
474
|
+
//}
|
|
475
|
+
//sorted_row_coordinates_string += &"]".to_string();
|
|
476
|
+
////println!("sorted_row_coordinates:{:?}", sorted_row_coordinates_string);
|
|
477
|
+
//if plot_image == true {
|
|
478
|
+
// let sorted_matrix =
|
|
479
|
+
// sort_matrix(sorted_col_elements, sorted_row_elements, &input_matrix);
|
|
480
|
+
// let sorted_matrix_transpose = sorted_matrix.transpose();
|
|
481
|
+
// //println!(
|
|
482
|
+
// // "sorted_matrix:{:?}",
|
|
483
|
+
// // &serde_json::to_string(&sorted_matrix_transpose).unwrap()
|
|
484
|
+
// //);
|
|
485
|
+
// let _plot_result = plot_matrix(
|
|
486
|
+
// &sorted_matrix_transpose,
|
|
487
|
+
// sorted_row_names,
|
|
488
|
+
// sorted_col_names,
|
|
489
|
+
// );
|
|
490
|
+
//}
|
|
804
491
|
}
|
|
805
492
|
Err(error) => println!("Incorrect json: {}", error),
|
|
806
493
|
}
|
|
@@ -810,6 +497,7 @@ fn main() {
|
|
|
810
497
|
}
|
|
811
498
|
}
|
|
812
499
|
|
|
500
|
+
#[allow(dead_code)]
|
|
813
501
|
fn sort_matrix(
|
|
814
502
|
// Rearranging matrix so as to plot it
|
|
815
503
|
sorted_elements: Vec<usize>,
|
|
@@ -836,6 +524,7 @@ fn sort_matrix(
|
|
|
836
524
|
sorted_array
|
|
837
525
|
}
|
|
838
526
|
|
|
527
|
+
#[allow(dead_code)]
|
|
839
528
|
fn plot_matrix(
|
|
840
529
|
original_array: &Matrix<f64, Dyn, Dyn, VecStorage<f64, Dyn, Dyn>>,
|
|
841
530
|
sorted_row_names: Vec<String>,
|