-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpreprocess-diversity.R
More file actions
executable file
·43 lines (38 loc) · 1.04 KB
/
Copy pathpreprocess-diversity.R
File metadata and controls
executable file
·43 lines (38 loc) · 1.04 KB
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
#!/usr/bin/env Rscript
##
## "Parse" command-line arguments
##
library(argparser, quietly=TRUE)
p <- arg_parser("Pre-process PREDICTS diversity data")
p <- add_argument(p, "--input", help="diversity rds file to read")
p <- add_argument(p, "--output", help="diversity rds file to write")
argv <- parse_args(p)
if (is.na(argv$input) || is.na(argv$output)) {
cat("failing\n")
print(p)
stop()
}
##
## Read the diversity DB
##
diversity <- readRDS(argv$input)
##
## Correct sampling effort and merge sites
##
library(yarg, quietly = TRUE)
cat("***\nCorrecting sampling effort\n")
diversity <- CorrectSamplingEffort(diversity)
cat("***\nMerging sites\n")
if ('Sample_midpoint' %in% names(diversity)) {
merge.extra <- c('Sample_midpoint')
} else {
merge.extra <- c()
}
if ('Wilderness_area' %in% names(diversity)) {
match.extra <- c('Wilderness_area')
} else {
match.extra <- c()
}
diversity <- MergeSites(diversity, merge.extra = merge.extra,
match.extra = match.extra)
saveRDS(diversity, file = argv$output)