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

Speed up match_quantiles function for ComBat_seq functon #48

Open
wants to merge 135 commits into
base: RELEASE_3_9
Choose a base branch
from

Conversation

lrf2019
Copy link

@lrf2019 lrf2019 commented Aug 2, 2021

match_quantiles <- function(counts_sub, old_mu, old_phi, new_mu, new_phi){
new_counts_sub <- matrix(NA, nrow=nrow(counts_sub), ncol=ncol(counts_sub))
for(a in 1:nrow(counts_sub)){
for(b in 1:ncol(counts_sub)){
if(counts_sub[a, b] <= 1){
new_counts_sub[a,b] <- counts_sub[a, b]
}else{
tmp_p <- pnbinom(counts_sub[a, b]-1, mu=old_mu[a, b], size=1/old_phi[a])
if(abs(tmp_p-1)<1e-4){
new_counts_sub[a,b] <- counts_sub[a, b]
# for outlier count, if p==1, will return Inf values -> use original count instead
}else{
new_counts_sub[a,b] <- 1+qnbinom(tmp_p, mu=new_mu[a, b], size=1/new_phi[a])
}
}
}
}
return(new_counts_sub)
}

new code for speed up this function

1. use which to transfer matrix boolean calculation to array boolean calculation to speed up

2. use matrix calculation to replace two for cycles to speed up the new matrix generation

match_quantiles_new <- function(counts_sub, old_mu, old_phi, new_mu, new_phi){
new_counts_sub <- counts_sub
condition1 <- which( counts_sub > 1) # array boolean calculation
colid <- floor(condition1/nrow(counts_sub)) + 1 # calculate the colid for rowid calculation
rowid <- condition1 - (colid - 1)*nrow(counts_sub) # calculate rowid for old_phi and new_phi value selection
tmp_p <- pnbinom(counts_sub[condition1] - 1, mu = old_mu[condition1], size = 1/old_phi[rowid])
tmp_q <- 1 + qnbinom(tmp_p[condition1], mu = new_mu[condition1], size = 1/new_phi[rowid])
condition2 <- which((abs(tmp_p-1) >= 1e-4))

new_counts_sub[ condition1[condition2] ] = tmp_q[condition2]
return(new_counts_sub)
}

m.carlson and others added 30 commits October 15, 2011 00:36
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/sva@59266 bc3139a8-67e5-0310-9ffc-ced21a209358
…) added man files for ComBat

git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/sva@59673 bc3139a8-67e5-0310-9ffc-ced21a209358
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/sva@59716 bc3139a8-67e5-0310-9ffc-ced21a209358
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/sva@59717 bc3139a8-67e5-0310-9ffc-ced21a209358
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/sva@59920 bc3139a8-67e5-0310-9ffc-ced21a209358
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/sva@59924 bc3139a8-67e5-0310-9ffc-ced21a209358
…n of setting num.sv method in sva. Fixed a bug in Combat so only an intercept term can be included

git-svn-id: https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/sva@60980 bc3139a8-67e5-0310-9ffc-ced21a209358
…n of setting num.sv method in sva. Fixed a bug in Combat so only an intercept term can be included

git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/sva@60980 bc3139a8-67e5-0310-9ffc-ced21a209358
…o use method leek

git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/sva@61130 bc3139a8-67e5-0310-9ffc-ced21a209358
…the list, updated fsva to include the new fast method as well as the original method

git-svn-id: https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/sva@63723 bc3139a8-67e5-0310-9ffc-ced21a209358
…the list, updated fsva to include the new fast method as well as the original method

git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/sva@63723 bc3139a8-67e5-0310-9ffc-ced21a209358
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/sva@64678 bc3139a8-67e5-0310-9ffc-ced21a209358
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/sva@64680 bc3139a8-67e5-0310-9ffc-ced21a209358
…rom being built. removed bug in fsva where svs where being normalized incorrectly for the exact case.

git-svn-id: https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/sva@65411 bc3139a8-67e5-0310-9ffc-ced21a209358
…rom being built. removed bug in fsva where svs where being normalized incorrectly for the exact case.

git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/sva@65411 bc3139a8-67e5-0310-9ffc-ced21a209358
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/sva@69763 bc3139a8-67e5-0310-9ffc-ced21a209358
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/sva@70050 bc3139a8-67e5-0310-9ffc-ced21a209358
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/sva@70052 bc3139a8-67e5-0310-9ffc-ced21a209358
lcolladotor and others added 30 commits June 13, 2017 13:09
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/sva@130304 bc3139a8-67e5-0310-9ffc-ced21a209358
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/sva@130416 bc3139a8-67e5-0310-9ffc-ced21a209358
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/sva@130528 bc3139a8-67e5-0310-9ffc-ced21a209358
Changed two occurences of `cat()` to `message()` in ComBat so they can be suppressed. All the other printing in ComBat already uses `message()`.
…hical parameters and reset to those after the 2x2 plot is made
…at matrix input for sva_network; input data is uncorrected normalized gene expression data; update example code accordingly
update documentation for sva_network
When plotting ComBat prior.plots, save the original state of the graphical parameters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants