Skip to content

Commit

Permalink
fix bug with use of existing size factors
Browse files Browse the repository at this point in the history
  • Loading branch information
ATpoint committed Aug 5, 2024
1 parent 9fd1463 commit e5d7a6e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: SigGenes
Title: Automated differential analysis and signature generation for bulk and single-cell data
Description: Automated differential analysis between groups based on limma-voom and generation of per-group signatures via custom filtering.
Version: 1.0.2
Version: 1.0.3
Author: Alexander Bender [aut,cre]
Maintainer: Alexander Bender <[email protected]>
License: LGPL (>=2)
Expand Down
39 changes: 16 additions & 23 deletions R/de_testing.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,40 +123,33 @@ de_limma <- function(x, use_assay = "counts", aggregate_by=NULL, use_existing_sf
# Aggregate to pseudobulk
if(!is.null(aggregate_by)){

pb <- aggregateAcrossCells(x, id=colData(x)[,aggregate_by], use.assay.type="counts")
pb <- aggregateAcrossCells(x, id=colData(x)[,aggregate_by], use.assay.type=use_assay)
pb <- DGEList(counts = assay(pb), samples = data.frame(colData(pb), check.names = FALSE))
run_norm <- TRUE

} else {

w <- which(assayNames(x) == "counts")
run_norm <- FALSE # means no calcNormFactors
w <- which(assayNames(x) == use_assay)
pb <- DGEList(counts = assay(x, use_assay), samples = data.frame(colData(x), check.names = FALSE))
sf <- suppressWarnings(sizeFactors(x))
# scran::convertTo()
if (!is.null(sf)) {
nf <- log(sf/pb$samples$lib.size)
nf <- exp(nf - mean(nf))
pb$samples$norm.factors <- nf
}

if(use_existing_sf){

if(is.null(sizeFactors(x))){

sf <- librarySizeFactors(x)
sizeFactors(x) <- sf
run_norm <- FALSE

}

run_norm <- FALSE

} else {
# Normalization
sf <- suppressWarnings(sizeFactors(x))
sf_null <- is.null(sf)

run_norm <- TRUE
if(sf_null){
use_existing_sf <- FALSE
}

if(!use_existing_sf){
sf <- librarySizeFactors(x)
}

# Convert Size factors to normalization factors based on scran::convertTo()
nf <- log(sf/pb$samples$lib.size)
nf <- exp(nf - mean(nf))
pb$samples$norm.factors <- nf

}

pb$samples <- droplevels.data.frame(pb$samples)
Expand Down

0 comments on commit e5d7a6e

Please sign in to comment.