File: tree-plot-3D.R

package info (click to toggle)
bali-phy 4.0~beta16%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 15,192 kB
  • sloc: cpp: 119,288; xml: 13,482; haskell: 9,722; python: 2,930; yacc: 1,329; perl: 1,169; lex: 904; sh: 343; makefile: 26
file content (41 lines) | stat: -rw-r--r-- 738 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
args = commandArgs(trailingOnly=T)
infile = args[1]
P = length(args) - 1
args = tail(args,P)

total = 0
Start = c()
End = c()
N = c()
for(i in 1:P)
{
    N[i] = as.numeric(args[i])

    Start[i] = total+1
    total    = total + N[i]
    End[i]   = total
}

# Read distance matrix
M = as.matrix(read.table(infile))
L = dim(M)[1]

if (dim(M)[2] != L) { stop("Matrix not square") }
if (total != L) { stop("Wrong number of points.") }

# Actually do the MDS
library(stats)
points = cmdscale(M,k=3)

#library(MASS)
#mds = isoMDS(M)
#points = mds$points

group = 1
for(group in 1:P)
{
    for (i in Start[group]:End[group])
    {
        cat(sprintf("%f\t%f\t%f\t%i\t%i\n",points[i,1], points[i,2], points[i,3], group, i-Start[group]))
    }
}