Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev kadm #94

Merged
merged 18 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: kimma
Type: Package
Title: Kinship In Mixed Model Analysis of RNA-seq
Version: 1.6.1
Version: 1.6.3
Author: Kim Dill-McFarland
Maintainer: Kim Dill-McFarland <kadm@uw.edu>
Description: Linear mixed effects models with pairwise kinship for RNA-seq data.
Expand All @@ -16,7 +16,6 @@ Imports:
data.table,
doParallel,
dplyr,
edgeR,
emmeans,
forcats,
foreach,
Expand All @@ -30,9 +29,10 @@ Imports:
tibble,
tidyr,
tidyselect
RoxygenNote: 7.2.1
RoxygenNote: 7.3.1
Depends:
R (>= 4.2)
R (>= 4.4)
Suggests:
testthat (>= 3.0.0)
testthat (>= 3.0.0),
edgeR
Config/testthat/edition: 3
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ export(extract_lmFit)
export(kmFit)
export(kmFit_eQTL)
export(summarise_kmFit)
export(summarise_lmFit)
export(summarize_kmFit)
export(summarize_lmFit)
importFrom(foreach,"%dopar%")
importFrom(magrittr,"%>%")
importFrom(tidyselect,vars_select_helpers)
26 changes: 14 additions & 12 deletions R/kmFit.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ kmFit <- function(dat=NULL, kin=NULL, patientID="ptID", libraryID="libID",
if(!is.null(subset_var) & is.null(subset_lvl)){
stop("Sample subsetting has been selected. Please also provide subset_lvl")}
if(run_lmerel & !grepl("\\|", model)){
stop("Kinship models require a random effect in the model as in (1 | ptID)")}
stop("Kinship models require a random effect in the model as in (1 | patientID)")}
if(run_lme & !grepl("\\|", model)){
stop("LME models require a random effect in the model")}
if(is.null(kin) & run_lmerel){
stop("Kinship matrix is required to run lmerel")}
if(!run_lm & !run_lme & !run_lmerel & !run_contrast){
Expand Down Expand Up @@ -201,16 +203,16 @@ kmFit <- function(dat=NULL, kin=NULL, patientID="ptID", libraryID="libID",
#Make formulae. as.formula does not work
if(grepl("\\|", model)){
model.temp <- strsplit(gsub(" ", "", model), split = "\\+\\(1")[[1]][1]
model.lm <- paste("expression", model.temp, sep="")
model_lm <- paste("expression", model.temp, sep="")
} else {
model.lm <- paste("expression", model, sep="")
model.lm <- gsub(" ","",model.lm)
model_lm <- paste("expression", model, sep="")
model_lm <- gsub(" ","",model_lm)
}
model.lme <- paste("expression", gsub(" ", "", model), sep="")
model_lme <- paste("expression", gsub(" ", "", model), sep="")

#Model message
if(run_lm){ message(paste("lm model:",model.lm))}
if(run_lme | run_lmerel){ message(paste("lme/lmerel model:",model.lme))}
if(run_lm){ message(paste("lm model:",model_lm))}
if(run_lme | run_lmerel){ message(paste("lme/lmerel model:",model_lme))}

#If no contrast variable set, as all
if(run_contrast & is.null(contrast_var)){
Expand Down Expand Up @@ -257,7 +259,7 @@ kmFit <- function(dat=NULL, kin=NULL, patientID="ptID", libraryID="libID",
stop(paste("Contrast variable", v, "is numeric. Please specify only character/factor contrasts."))
}
} else {
v.class <- class(meta.temp[,v])
v.class <- class(unlist(meta.temp[,v]))
if(v.class %in% c("numeric","integer","double")){
stop(paste("Contrast variable", v, "is numeric. Please specify only character/factor contrasts."))
}
Expand All @@ -269,7 +271,7 @@ kmFit <- function(dat=NULL, kin=NULL, patientID="ptID", libraryID="libID",
to.model.ls <- kimma_cleaning(dat, kin, patientID, libraryID,
counts, meta, genes, weights,
subset_var, subset_lvl, subset_genes,
model.lm, genotype_name, run_lmerel)
model_lm, genotype_name, run_lmerel)

###### Run models ######
#create blank df to hold results
Expand Down Expand Up @@ -297,7 +299,7 @@ kmFit <- function(dat=NULL, kin=NULL, patientID="ptID", libraryID="libID",
if(run_lm){
#Wrap model run in error catch to allow loop to continue even if a single model fails
results.lm.ls <- tryCatch({
kimma_lm(model.lm, to.model.gene, gene, use_weights, metrics)
kimma_lm(model_lm, to.model.gene, gene, use_weights, metrics)
}, error=function(e){
results.lm.ls[["error"]] <- data.frame(model="lm",
gene=gene,
Expand All @@ -311,7 +313,7 @@ kmFit <- function(dat=NULL, kin=NULL, patientID="ptID", libraryID="libID",
if(run_lme){
#Wrap model run in error catch to allow loop to continue even if a single model fails
results.lme.ls <- tryCatch({
kimma_lme(model.lme, to.model.gene, gene, use_weights, metrics)
kimma_lme(model_lme, to.model.gene, gene, use_weights, metrics)
}, error=function(e){
results.lme.ls[["error"]] <- data.frame(model="lme",
gene=gene,
Expand All @@ -325,7 +327,7 @@ kmFit <- function(dat=NULL, kin=NULL, patientID="ptID", libraryID="libID",
if(run_lmerel){
#Wrap model run in error catch to allow loop to continue even if a single model fails
results.kin.ls <- tryCatch({
kimma_lmerel(model.lme, to.model.gene, gene, to.model.ls[["kin.subset"]],
kimma_lmerel(model_lme, to.model.gene, gene, to.model.ls[["kin.subset"]],
use_weights, patientID, metrics)
}, error=function(e){
results.kin.ls[["error"]] <- data.frame(model="lmerel",
Expand Down
4 changes: 4 additions & 0 deletions R/summarise_kmFit.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,9 @@ summarise_kmFit <- function(fdr, fdr_cutoff = c(0.05,0.1,0.2,0.3,0.4,0.5),
#' @rdname summarise_kmFit
#' @export
summarize_kmFit <- summarise_kmFit
#' @rdname summarise_kmFit
#' @export
summarise_lmFit <- summarise_kmFit
#' @rdname summarise_kmFit
#' @export
summarize_lmFit <- summarise_kmFit
22 changes: 22 additions & 0 deletions man/summarise_kmFit.Rd

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

Loading
Loading