R/001_read.mothur.shared.R

Defines functions read.mothur.shared

Documented in read.mothur.shared

#' Read mothur formatted .shared file
#'
#' This function allows to read and reformat mothur .shared file such that columns are features (OTUs) and rows are samples
#' @param shared.file this is an output that you get from mothur.
#' @keywords mothur, shared
#' @export
#' @examples
#' otu_data <- read.mothur.shared(Sys.glob("data/*.shared"))

read.mothur.shared <- function(shared.file){
  otu_data <-read.table(shared.file, header=T)  %>%
    t(.) %>%
    .[2:nrow(.),] %>%
    .[-c(2),] %>%
    data.frame(.)
  colnames(otu_data) <- as.character(unlist(otu_data[1,]))
  otu_data <- otu_data[-1, ]
  write.csv(otu_data, file="otu_data.csv")
  otu_data <-read.csv("otu_data.csv", header=T, row.names = 1)
  otu_data <- data.frame(t(otu_data))
  return(otu_data)
}
ravinpoudel/myFunctions documentation built on May 9, 2020, 7:39 a.m.