Skip to content

Commit

Permalink
package contents
Browse files Browse the repository at this point in the history
  • Loading branch information
CarolineWheeler committed Sep 29, 2023
1 parent 2c97210 commit 6c0eff1
Show file tree
Hide file tree
Showing 11 changed files with 228 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
27 changes: 27 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Package: microsig
Type: Package
Title: Calculates Microbe Signature Score
Version: 0.0.0.9000
Authors@R:
c(person(given = "Caroline",
family = "Wheeler",
role = c("aut"),
comment = c(ORCID = "0000-0002-3374-4909")),
person(given = "Rebecca",
family = "Hoyd",
role = c("aut"),
comment = c(ORCID = "0000-0003-1210-4491")),
person(given = "Daniel",
family = "Spakowicz",
role = c("aut", "cre"),
email = "daniel.spakowicz@osumc.edu",
comment = c(ORCID = "0000-0003-2314-6435"))
Maintainer: Daniel Spakowicz <daniel.spakowicz@osumc.edu>
Description: This package contains functions to calculate microbe signatures, particularly from bugsigdb inputs.
License: MIT
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Imports:
dplyr,
tidyr
7 changes: 7 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(calcMicroSigScore)
export(getSigList)
export(microbeEntries)
import(dplyr)
import(tidyr)
58 changes: 58 additions & 0 deletions R/calcMicroSigScore.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#' Function to calculate microbe signature scores given a set of up and down
#' regulated microbes and the relative abundances of microbe per sample
#'
#' @param taxa a data frame where columns are microbes and rows are samples, first
#' column named 'sample'
#' @param sig.up a character vector listing microbes in given signature that are
#' up-regulated, empty if none
#' @param sig.down a character vector listing microbes in given signature that are
#' down-regulated, empty if none
#'
#' @return a data frame with samples and corresponding microbe signature scores
#'
#' @import dplyr
#' @import tidyr
#'
#' @export
calcMicroSigScore <- function(taxa, sig.up, sig.down){
df <- taxa %>%
tidyr::gather(microbe, exo.ra, -sample) %>%
dplyr::group_by(sample) %>%
dplyr::mutate(z_score = scale(exo.ra))

upMics <- df %>%
dplyr::filter(microbe %in% sig.up)

upTotal <- length(unique(upMics$microbe))

upMics <- upMics %>%
dplyr::group_by(sample) %>%
dplyr::summarize(tempUp = sum(exo.ra))

downMics <- df %>%
dplyr::filter(microbe %in% sig.down)

downTotal <- length(unique(downMics$microbe))

downMics <- downMics %>%
dplyr::group_by(sample) %>%
dplyr::summarize(tempDown = sum(exo.ra))

if(upTotal == 0 && downTotal == 0){
df <- data.frame(matrix(ncol = 0, nrow = 0))
}else if(upTotal == 0){
df <- downMics %>%
dplyr::mutate(score = tempDown*(1/downTotal)) %>%
dplyr::select(sample,score)
}else if(downTotal == 0){
df <- upMics %>%
dplyr::mutate(score = tempUp*(1/upTotal)) %>%
dplyr::select(sample, score)
}else{
df <- merge(upMics, downMics, by = "sample") %>%
dplyr::mutate(score = (tempUp - tempDown)*(1/(upTotal + downTotal))) %>%
dplyr::select(sample, score)
}

return(df)
}
14 changes: 14 additions & 0 deletions R/getSigList.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#' Given a single cell value from bigsigDB output in the column 'MetaPhlAn.taxon.names',
#' returns a list of the microbes
#'
#' @param sig character string from bugsigDB output containing comma separated
#' Metaphlan taxonomic names
#'
#' @return sig.list , a character list of containing the string after the last
#' "|" in each comma separated Metaphlan taxonomic name
#'
#' @export
getSigList <- function(sig){
sig.list <- sub("^.+\\|", "", unlist(strsplit(sig ,",")))
return(sig.list)
}
32 changes: 32 additions & 0 deletions R/microbeEntries.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#' Microbe Entries
#' A function that can be used to call of specific microbe signatures.
#' @param query Name of the signature group. If query is passed "all" function will return all the signature groups
#'
#' @return The microbes within a desired signature group in the format "x__microbe name" with x indicating taxonomic level
#' @export
#'
#' @examples microbeEntries("paa_up")
microbeEntries <- function(query){

paa_up <- c("s__Clostridium sp. UNK-MGS-6", "s__Firmicutes bacterium CAG 41",
"s__Coprobacillus cateniformis", "s__Clostridia bacterium UC5-1-2G4",
"s__Streptococcus dysgalactiae", "s__Acidaminococcus sp. HPA0509",
"s__Roseburia sp.CAG-303", "s__Butyrivibrio_sp. AE2032",
"s__Coprobacillus sp. 29-1", "s__Coprobacillus sp. D6")
paa_down <- c("s__Alistipes sp. CAG-435", "s__Fusobacterium hwasookii",
"s__Leuconostoc sp. DORA-2", "s__Paenibacillus lentimorbus",
"s__Fusobacterium sp. oral taxon 370", "s__Alcanivorax hongdengensis",
"s__Arthrobacter sp. LS16", "s__Bacillus sp. 5B6", "s__Bacillus velezensis",
"s__Fusobacterium sp. OBRC1")

mic_list <- list(paa_up, paa_down)

names(mic_list) <- c("paa_up", "paa_down")

if(query == "all"){
return(mic_list)
}

mics_queried <- mic_list[[query]]
return(mics_queried)
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# microsig
This package contains functions to calculate microbe signatures, particularly from bugsigdb inputs.
This package contains functions to calculate microbe signature scores, particularly from bugsigdb inputs.
26 changes: 26 additions & 0 deletions man/calcMicroSigScore.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions man/getSigList.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions man/microbeEntries.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions microsig.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes

0 comments on commit 6c0eff1

Please sign in to comment.