Skip to content

Commit

Permalink
get identifier for taxa
Browse files Browse the repository at this point in the history
  • Loading branch information
xu-hong committed Oct 28, 2015
1 parent bd13fb4 commit fe7d29e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
14 changes: 8 additions & 6 deletions R/pk_ontotrace.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,23 @@ pk_ontotrace <- function(taxon, entity, relation = "part of", get_metadata = FAL

nex <- nexml_read(out)


m <- get_characters(nex) # returned data.frame with taxon names as row index
m[] <- lapply(m, function(x) as.numeric(as.character(x)))
ont_row_names <- row.names(m)
ont_row_names <- rownames(m)
rownames(m) <- NULL
m <- dplyr::mutate(m, taxon = ont_row_names)
m_re <- m[, c(ncol(m), 1:ncol(m)-1)]
m_re <- dplyr::as_data_frame(m[, c(ncol(m), 1:ncol(m)-1)])

# TODO: add ordered taxonID and entityID to the list
if (get_metadata == TRUE) {
id_taxa <- get_metadata(nex, level = "otu")
id_entity <- get_metadata(nex, level = "char")
id_taxa <- get_taxa(nex)
#id_entity <- get_metadata(nex, level = "char")

m_re <- list(matrix = m_re,
id_taxa = id_taxa[which(names(id_taxa) == meta_attr_taxon)],
id_entity = id_entity[which(names(id_entity) == meta_attr_entitiy)]
id_taxa = id_taxa
#id_taxa = id_taxa[which(names(id_taxa) == meta_attr_taxon)]
#id_entity = id_entity[which(names(id_entity) == meta_attr_entitiy)]
)
}
return(m_re)
Expand Down
2 changes: 1 addition & 1 deletion man/pk_ontotrace.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
\alias{pk_ontotrace}
\title{Returns a NeXML-format evolutionary character matrix.}
\usage{
pk_ontotrace(taxon, entity, relation = "part of", get_metadata = TRUE,
pk_ontotrace(taxon, entity, relation = "part of", get_metadata = FALSE,
variable_only = TRUE)
}
\arguments{
Expand Down
11 changes: 8 additions & 3 deletions tests/testthat/test-pk.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,19 @@ test_that("Test OnToTrace", {
rel <- pk_ontotrace(taxon = c("Ictalurus", "Ameiurus"),
entity = c("fin", "spine"),
relation = "develops from")

single1 <- pk_ontotrace(taxon = "Ictalurus", entity = "fin", get_metadata = TRUE)

err1 <- function() pk_ontotrace(taxon = "Ictalurus TT", entity = "fin", relation = "other relation")
err2 <- function() pk_ontotrace(taxon = c("Ictalurus", "Ameiurus XXX"), entity = c("fin", "spine"))
err3 <- function() pk_ontotrace("Ictalurus TT", "fin")


expect_output(str(single), "data.frame")
expect_output(str(multi), "data.frame")
expect_output(str(rel), "data.frame")
expect_output(str(single), "Classes ‘tbl_df’, ‘tbl’ and 'data.frame'")
expect_output(str(multi), "Classes ‘tbl_df’, ‘tbl’ and 'data.frame'")
expect_output(str(rel), "Classes ‘tbl_df’, ‘tbl’ and 'data.frame'")

expect_output(str(single1), "List of 2")

expect_equal(all(apply(single[,-1], 2, is.numeric)), TRUE)
expect_equal(all(apply(multi[,-1], 2, is.numeric)), TRUE)
Expand Down

0 comments on commit fe7d29e

Please sign in to comment.