knitr::opts_chunk$set(echo = TRUE)
library(ewing)
library(tidyverse)
data("organism.features")
data("future.host")
data("future.parasite")
data("host.parasite")
data("substrate.host")
data("substrate.parasite")

Get names of data structures.

dlist <- c("future.host",
           "future.parasite",
           "host.parasite",
           "substrate.host",
           "substrate.parasite")
dlist <- as.list(dlist)
names(dlist) <- c(dlist)
nlist <- map(dlist, function(x) {
  names(get(x))
})

We can combine (rbind) the futures by adding a column for species.

future <- bind_rows(
  host = future.host,
  parasite = future.parasite,
  .id = "species")

We can combine the substrate in a similar way, but first have to change the rownames into a column.

ftemp <- function(x) {
  out <- data.frame(subname = rownames(x), x)
  rownames(out) <- NULL
  out
}
substrate <- bind_rows(
  host = ftemp(substrate.host),
  parasite = ftemp(substrate.parasite),
  .id = "species")

Then we have 4 types of files:

The organism.features would work better as a long table.

ftemp <- function(x, cc) {
  out <- sapply(x[cc,], as.character)
  names(out) <- NULL
  out
}
features <- bind_rows(
  host = data.frame(feature = colnames(organism.features),
                    value = ftemp(organism.features, 1)),
  parasite = data.frame(feature = colnames(organism.features),
                        value = ftemp(organism.features, 2)),
  .id = "species") %>%
  filter(!is.na(value))

The host.parasite could be appended to host with some adjustment.

Could do the following:

Translation

Need routines to translate between formats, or adjust routines to handle this automatically.



byandell/ewing documentation built on Jan. 3, 2024, 7:27 p.m.