1
1
# ' Extract the last clade of a lineage
2
2
# '
3
3
# ' @inheritParams is_rank
4
- # ' @param same logical. Does the lineage have the same depth? Default to TRUE.
4
+ # ' @param same logical. Does the lineage have the same depth? Default to ` TRUE` .
5
5
# '
6
6
# ' @return A string. The last clades of the given lineages.
7
7
# ' @importFrom stringr str_remove
10
10
# ' @examples
11
11
# ' lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae"
12
12
# ' lineage2 <- "k__Bacteria|p__Firmicutes|c__Clostridia"
13
- # ' last_clade (c(lineage1, lineage2))
14
- last_clade <- function (lineage , same = TRUE ) {
13
+ # ' get_last_clade (c(lineage1, lineage2))
14
+ get_last_clade <- function (lineage , same = TRUE ) {
15
15
16
16
error_lineage(lineage )
17
17
@@ -20,10 +20,41 @@ last_clade <- function(lineage, same = TRUE) {
20
20
str_remove(lineage , " .*__" )
21
21
}
22
22
23
+ # ' Extract the clade of a desired rank in a lineage
24
+ # '
25
+ # ' @inheritParams get_last_clade
26
+ # ' @param rank The desired rank of the clade.
27
+ # '
28
+ # ' @return A string.
29
+ # '
30
+ # ' @importFrom stringr str_extract str_remove_all
31
+ # ' @export
32
+ # '
33
+ # ' @examples
34
+ # ' lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae"
35
+ # ' lineage2 <- "k__Bacteria|p__Firmicutes|c__Clostridia"
36
+ # ' get_clade(c(lineage1, lineage2), "phylum")
37
+ get_clade <- function (lineage , rank = yatah :: all_ranks , same = TRUE ) {
38
+
39
+ error_lineage(lineage )
40
+
41
+ if (same ) depth(lineage )
42
+
43
+ rank <- match.arg(rank )
44
+ letter <- names(which(.ranks == rank ))
45
+
46
+ sep <- getOption(" yatah_sep" , default = " \\ |" )
47
+
48
+ str_remove_all(
49
+ str_extract(lineage , paste0(" (?<=" , letter , " __).*" )),
50
+ paste0(sep , " .*" )
51
+ )
52
+ }
53
+
23
54
24
55
# ' Extract the last rank of a lineage
25
56
# '
26
- # ' @inheritParams last_clade
57
+ # ' @inheritParams get_last_clade
27
58
# '
28
59
# ' @return A string. The last rank of the given lineages.
29
60
# ' @importFrom stringr str_remove
@@ -32,8 +63,8 @@ last_clade <- function(lineage, same = TRUE) {
32
63
# ' @examples
33
64
# ' lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae"
34
65
# ' lineage2 <- "k__Bacteria|p__Firmicutes|c__Clostridia"
35
- # ' last_rank (c(lineage1, lineage2))
36
- last_rank <- function (lineage , same = TRUE ) {
66
+ # ' get_last_rank (c(lineage1, lineage2))
67
+ get_last_rank <- function (lineage , same = TRUE ) {
37
68
38
69
error_lineage(lineage )
39
70
@@ -54,7 +85,7 @@ last_rank <- function(lineage, same = TRUE) {
54
85
# ' clades with same name and same rank when \code{simplify} is set to
55
86
# ' \code{FALSE}.
56
87
# '
57
- # ' @inheritParams last_clade
88
+ # ' @inheritParams get_last_clade
58
89
# ' @param simplify logical. Should the output be a vector or a dataframe?
59
90
# '
60
91
# ' @return The clades present in the lineage. Vector of ordered strings
@@ -66,9 +97,9 @@ last_rank <- function(lineage, same = TRUE) {
66
97
# ' lineage1 <- "k__Bacteria|p__Verrucomicrobia|c__Verrucomicrobiae"
67
98
# ' lineage2 <- "k__Bacteria|p__Firmicutes|c__Clostridia"
68
99
# ' lineage3 <- "k__Bacteria|p__Actinobacteria|c__Actinobacteria"
69
- # ' all_clades (c(lineage1, lineage2, lineage3))
70
- # ' all_clades (c(lineage1, lineage2, lineage3), simplify = FALSE)
71
- all_clades <- function (lineage , simplify = TRUE ) {
100
+ # ' get_all_clades (c(lineage1, lineage2, lineage3))
101
+ # ' get_all_clades (c(lineage1, lineage2, lineage3), simplify = FALSE)
102
+ get_all_clades <- function (lineage , simplify = TRUE ) {
72
103
73
104
error_lineage(lineage )
74
105
0 commit comments