Mercurial > repos > bitlab > bitlab
comparison chromeister/bin/make-cluster.R @ 0:ee6b15b409e5 draft
Uploaded
author | bitlab |
---|---|
date | Thu, 13 Dec 2018 06:27:57 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ee6b15b409e5 |
---|---|
1 #!/usr/bin/env Rscript | |
2 library(ape) | |
3 | |
4 args = commandArgs(trailingOnly=TRUE) | |
5 | |
6 if(length(args) < 1){ | |
7 stop("USE: Rscript --vanilla make-cluster.R <csv>") | |
8 } | |
9 | |
10 | |
11 path = args[1] | |
12 | |
13 inputcsv <- read.csv(path, sep ="-", header=FALSE) | |
14 | |
15 # Make indexing table | |
16 | |
17 indexing_table <- table(inputcsv[,1]) | |
18 n_species <- length(indexing_table) | |
19 | |
20 for(i in 1:n_species){ | |
21 indexing_table[i] <- i | |
22 } | |
23 | |
24 | |
25 distmat <- matrix(NA, nrow=n_species, ncol=n_species) | |
26 rownames(distmat) <- rownames(indexing_table) | |
27 colnames(distmat) <- rownames(indexing_table) | |
28 | |
29 for(i in 1:n_species){ | |
30 distmat[i,i] <- 0 | |
31 } | |
32 | |
33 | |
34 for(i in 1:length(inputcsv[,1])){ | |
35 redirX <- (as.character(inputcsv[i,1])) | |
36 redirY <- (as.character(inputcsv[i,2])) | |
37 | |
38 distmat[indexing_table[redirX],indexing_table[redirY]] <- as.numeric(inputcsv[i,3]) | |
39 distmat[indexing_table[redirY],indexing_table[redirX]] <- as.numeric(inputcsv[i,3]) | |
40 } | |
41 | |
42 cluster <- hclust(dist(distmat), method = "average") | |
43 | |
44 # Rooted hierarchical cluster | |
45 #plot(cluster, main = "Clustering based on automatic scoring", xlab = "Organisms") | |
46 | |
47 # Unrooted | |
48 plot(as.phylo(cluster), type = "unrooted", cex = 0.6, main = "Unrooted clustering based on automatic") | |
49 | |
50 # Fan cluster | |
51 #plot(as.phylo(cluster), type = "fan") | |
52 | |
53 | |
54 |