-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphynames.R
47 lines (34 loc) · 1.17 KB
/
phynames.R
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
42
43
44
45
46
47
#!/usr/bin/env Rscript
# Setup -------------------------------------------------------------------
rm(list = ls())
options(stringsAsFactors = F)
# Load libraries ----------------------------------------------------------
suppressMessages(require(getopt))
suppressMessages(require(ape))
# Set up options ----------------------------------------------------------
# col1: long flag name
# col2: short flag name
# col3: 0 = no argument, 1 = required, 2 = optional
# col3: logical, integer, double, complex, character
# col5: optional, brief description
spec <- matrix(c(
'help' , 'h', 0, "logical",
'phy' , 'p', 1, "character",
'nodes' , 'n', 2, "boolean"
), byrow = T, ncol = 4)
# Read options and do help -----------------------------------------------
opt <- getopt(spec)
if ( !is.null(opt$help) ){
cat(getopt(spec, usage = T))
q(status = 1)
}
# Set defaults -----------------------------------------------------------
if ( is.null( opt$nodes ) ) { opt$nodes = F }
# Load in data -----------------------------------------------------------
phy <- read.tree(opt$phy)
if( opt$nodes ){
out <- phy$node.label
} else {
out <- phy$tip.label
}
writeLines(out)