Created
April 13, 2014 23:00
-
-
Save jnpaulson/10605744 to your computer and use it in GitHub Desktop.
Version of make_biom that allows a change in matrix_element_type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
make_biom2<-function (data, sample_metadata = NULL, observation_metadata = NULL, | |
id = NULL,matrix_element_type="int") | |
{ | |
if (!is.null(observation_metadata)) { | |
rows = mapply(list, SIMPLIFY = FALSE, id = as.list(rownames(data)), | |
metadata = alply(as.matrix(observation_metadata), | |
1, .expand = FALSE, .dims = TRUE)) | |
} | |
else { | |
rows = mapply(list, id = as.list(rownames(data)), metadata = NA, | |
SIMPLIFY = FALSE) | |
} | |
if (!is.null(sample_metadata)) { | |
columns = mapply(list, SIMPLIFY = FALSE, id = as.list(colnames(data)), | |
metadata = alply(as.matrix(sample_metadata), 1, .expand = FALSE, | |
.dims = TRUE)) | |
} | |
else { | |
columns = mapply(list, id = as.list(colnames(data)), | |
metadata = NA, SIMPLIFY = FALSE) | |
} | |
datalist = as.list(as.data.frame(as(t(data), "matrix"))) | |
names(datalist) <- NULL | |
format_url = "http://biom-format.org/documentation/format_versions/biom-1.0.html" | |
return(biom(list(id = id, format = "Biological Observation Matrix 1.0.0-dev", | |
format_url = format_url, type = "OTU table", generated_by = sprintf("biom %s", | |
packageVersion("biom")), date = as.character(Sys.time()), | |
matrix_type = "dense", matrix_element_type = matrix_element_type, shape = dim(data), | |
rows = rows, columns = columns, data = datalist))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment