R/make_node_data.R

Defines functions make_node_data

make_node_data <- function(phenoNet,
                           phenos,
                           phenos_column,
                           new_column=phenos_column) {

  if(!phenos_column %in% names(phenos)){
    messager(paste0("phenos_column=",shQuote(phenos_column)),
             "not found in phenos.")
    return(phenoNet)
  }
  messager("Adding",paste0("new_column=",shQuote(new_column)))
  # data.table::setkeyv(phenos,"hpo_id")
  # phenoNet[[new_column]] <- phenos[phenoNet$vertex.names, ][[phenos_column]]
  dat <- unique(phenos[,c("hpo_id",phenos_column), with=FALSE])
  data_dict <- stats::setNames(dat[[phenos_column]], dat$hpo_id)
  phenoNet[[new_column]] <- data_dict[phenoNet$name]
  return(phenoNet)
}
neurogenomics/HPOExplorer documentation built on Aug. 24, 2024, 1:39 a.m.