Skip to content

Commit

Permalink
update PatternLine
Browse files Browse the repository at this point in the history
  • Loading branch information
JinNing329 committed Mar 6, 2024
1 parent 2436977 commit 5135ef7
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 38 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export(GetTDEseqAssayData)
export(IsMatrixEmpty)
export(NormDataTDEseq)
export(PatternHeatmap)
export(PatternLine)
export(SetAssayData)
export(TDEseq)
export(Version)
Expand Down
13 changes: 10 additions & 3 deletions R/TDEseq.R
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,14 @@ tdeseq.default <- function(object,
}
dfTDEseqResults$ChangePoint<-ChangePoint

fit.inc <- do.call(cbind,res.tdeseq[seq(2,length(res.tdeseq),9)])
fit.dec <- do.call(cbind,res.tdeseq[seq(3,length(res.tdeseq),9)])
fit.cov <- do.call(cbind,res.tdeseq[seq(4,length(res.tdeseq),9)])
fit.con <- do.call(cbind,res.tdeseq[seq(5,length(res.tdeseq),9)])


return(dfTDEseqResults)
ModelFits<-GetModelFits(dfTDEseqResults,list(fit.inc,fit.dec,fit.cov,fit.con),stage.id)
out<-list(dfTDEseqResults=dfTDEseqResults,ModelFits=ModelFits)
return(out)
}## end function


Expand Down Expand Up @@ -307,7 +312,9 @@ tdeseq.Assay <- function(object,


## store the scaled data in the slot
object <- SetAssayData(object = object, slot = 'tde', new.data = new.data)
object <- SetAssayData(object = object, slot = 'tde', new.data = new.data$dfTDEseqResults)
object <- SetAssayData(object = object, slot = 'fit', new.data = new.data$ModelFits)
return(object)
## store top number of features in tde slot
}## end func

Expand Down
15 changes: 9 additions & 6 deletions R/Visualization.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,24 +146,27 @@ return(p)

#' PatternLine: Line plot to show the pattern specific temporal genes. Please first install ggplot2.
#'
#' @param seuobj A seurat object with UMAP embeddings been calculated
#' @param features Genes to be shown in feature plot
#' @param tdeobj A tdeseq object
#' @param features Genes to be shown in line plot
#' @author Yue Fan, Shiquan Sun

#' @export
PatternLine<-function (obj, feature.show = NULL, cols = NULL)
{
if(is.null(cols))
{
cols=c('#E50C7D',"#E34627","#A22066","#A474A4","#2D8573","#E1DE15","#C16728","#2578BE","#738DC8","#C0C0C0", '#7d8d8e','#2a24d0','#a2292e','#274382','#838d36')
}
suppressPackageStartupMessages(library("ggplot2"))
feature.show=feature.show[feature.show%in%rownames(obj@ModelFits)]
dat <- GetTDEseqAssayData(obj,slot='fit')
feature.show=feature.show[feature.show%in%rownames(dat)]
if(length(feature.show)==0)
{
stop(paste0("Genes to be shown are not specified!!"))
}
dat = obj@ModelFits[feature.show, ]
time = sort(unique(obj@Metadata$Time_Origin))

dat = dat[feature.show, ]
time=as.numeric(colnames(dat))

N=length(feature.show)
if(N!=1)
{
Expand Down
9 changes: 6 additions & 3 deletions R/tdeseq.object.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ Assay <- setClass(
tde = "data.frame",
svg = "ANY",
de.truth = "ANY",
misc = "ANY"))
misc = "ANY",
fit = "matrix"))


###########################################
Expand Down Expand Up @@ -948,7 +949,8 @@ GetTDEseqAssayData.Assay <- function(object,
'tde',
'dr',
'svg',
'de.truth'), ...) {
'de.truth',
'fit'), ...) {
slot <- slot[1]
slot <- match.arg(arg = slot)
return(slot(object = object, name = slot))
Expand Down Expand Up @@ -1008,7 +1010,8 @@ SetAssayData.Assay <- function(object,
'dr',
'tde',
'svg',
'de.truth'), ...) {
'de.truth',
'fit'), ...) {

slot <- slot[1]
slot <- match.arg(arg = slot)
Expand Down
17 changes: 17 additions & 0 deletions R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,23 @@ combined_pvalue <- unlist(lapply(res, ComputeACAT))
return(combined_pvalue)
}

GetModelFits<-function(res_dat,res,stage)
{
sig_gene_idx=which(res_dat$SignificantDE=='Yes')
ModelFits=matrix(0,nrow=length(sig_gene_idx),ncol=length(unique(stage)))
rownames(ModelFits)=res_dat$gene[sig_gene_idx]
colnames(ModelFits)=sort(unique(stage))
pattern=c('Growth','Recession','Trough','Peak')
for(i in sig_gene_idx)
{
for(j in sort(unique(stage)))
{
ModelFits[res_dat$gene[i],j+1]=mean(res[[match(res_dat$pattern[i],pattern)]][which(stage==j),i])
}
}
return(ModelFits)
}


ComputeACAT <- function(Pvals, Weights=NULL){
#### check if there is NA
Expand Down
20 changes: 0 additions & 20 deletions man/AddMetaData.Rd

This file was deleted.

2 changes: 1 addition & 1 deletion man/NormDataTDEseq.Rd

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

4 changes: 2 additions & 2 deletions man/PatternLine.Rd

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

2 changes: 1 addition & 1 deletion man/TDEseq.Rd

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

2 changes: 1 addition & 1 deletion man/tdeseq.TDEseq.Rd

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

2 changes: 1 addition & 1 deletion man/tdeseq.default.Rd

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

0 comments on commit 5135ef7

Please sign in to comment.