1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,89 +0,0 @@ |
1 |
-#' @title Plotting function of runMusic.R |
|
2 |
-#' @description A wrapper that plots heatmap and cluster plots for results from runMusic.R |
|
3 |
-#' @param inSCE A \link[SingleCellExperiment]{SingleCellExperiment} object. |
|
4 |
-#' @param analysisType Character. Specify which function to run |
|
5 |
-#' Available options are "EstCellProp","PreGroupedClustProp","SingleCellClust" |
|
6 |
-#' @param heatmapTitle Character. Title for heatmap; Default is NULL |
|
7 |
-#' @param analysisName Character. User-defined analysis name. |
|
8 |
-#' This will be used as the slot name and results can be stored and retrived from SCE object using this name |
|
9 |
-#' @return SingleCellExperiment object containing the outputs of the |
|
10 |
-#' specified algorithms in the \link{colData} |
|
11 |
-#' of \code{inSCE}. |
|
12 |
- |
|
13 |
-library(singleCellTK) |
|
14 |
- |
|
15 |
- |
|
16 |
-plotMusicResults<- function(inSCE, |
|
17 |
- analysisType = c("EstCellProp","PreGroupedClustProp","SingleCellClust"), |
|
18 |
- heatmapTitle = NULL, |
|
19 |
- analysisName = NULL, |
|
20 |
- useAssay = NULL){ |
|
21 |
- |
|
22 |
- |
|
23 |
- # Plot clusters |
|
24 |
- |
|
25 |
- .musicPlotclusters<- function(inSCE,analysisName){ |
|
26 |
- basisObject = metadata(inSCE)[["sctk"]][["music"]][[analysisName]][["Disgn.mtx"]] |
|
27 |
- calc_dmat_dist = dist(t(log(basisObject + 1e-6)), method = "euclidean") |
|
28 |
- hc1<- hclust(calc_dmat_dist, method = "complete") |
|
29 |
- basisObject2 = metadata(inSCE)[["sctk"]][["music"]][[analysisName]][["M.theta"]] |
|
30 |
- calc_RA_dist = dist(t(log(basisObject2 + 1e-8)), method = "euclidean") |
|
31 |
- hc2<- hclust(calc_RA_dist,method = "complete") |
|
32 |
- p1<-plot(hc1,cex =0.6,hang = -1, main = 'Cluster log(Design Matrix)') |
|
33 |
- p2<-plot(hc2,cex =0.6,hang = -1, main = 'Cluster log(Mean of RA)') |
|
34 |
- return(list(hc1,hc2)) |
|
35 |
- |
|
36 |
- } |
|
37 |
- |
|
38 |
- |
|
39 |
- # plot heatmap # use the ones from lab inSCEheatmap? (uses complexheatmap) |
|
40 |
- |
|
41 |
- .plotHeatmap<- function(inSCE, # |
|
42 |
- analysisName, |
|
43 |
- heatmapTitle = NULL, |
|
44 |
- useAssay = useAssay){ |
|
45 |
- |
|
46 |
- |
|
47 |
- |
|
48 |
- |
|
49 |
- testBulk<-metadata(inSCE)[["sctk"]][["music"]][[analysisName]][[useAssay]] |
|
50 |
- bulkinSCE<-SingleCellExperiment(assays = list(EstProps = testBulk)) |
|
51 |
- names(assays(bulkinSCE))<-useAssay |
|
52 |
- heatmap<-plotSCEHeatmap(bulkinSCE, # Check version |
|
53 |
- useAssay = useAssay, |
|
54 |
- rowLabel = T, |
|
55 |
- colLabel = T, |
|
56 |
- rowTitle = "Subjects", |
|
57 |
- colTitle = "CellType", |
|
58 |
- title = heatmapTitle) |
|
59 |
- return(heatmap) |
|
60 |
- } |
|
61 |
- |
|
62 |
- # sce -> extract bulk -> new_sce -> plotsce |
|
63 |
- |
|
64 |
- |
|
65 |
- |
|
66 |
- if(analysisType == "SingleCellClust"){ |
|
67 |
- plots<-.musicPlotclusters(inSCE,analysisName = analysisName) |
|
68 |
- # metadata(inSCE)$sctk$music[[analysisName]][["Clusters"]]<- temp_results |
|
69 |
- } |
|
70 |
- else if(analysisType == "EstCellProp"){ |
|
71 |
- |
|
72 |
- plots<-.plotHeatmap(inSCE,heatmapTitle = heatmapTitle,useAssay = "Est.prop.weighted" ,analysisName = analysisName ) |
|
73 |
- # Do if else for pulling the assay data and have one single call for the sce heatmap |
|
74 |
- |
|
75 |
- #metadata(inSCE)$sctk$music[[analysisName]][["Heatmap"]]<- temp_results |
|
76 |
- |
|
77 |
- } |
|
78 |
- |
|
79 |
- else if(analysisType == "PreGroupedClustProp"){ |
|
80 |
- |
|
81 |
- plots<- .plotHeatmap(inSCE,heatmapTitle = heatmapTitle,useAssay = "Est.prop.weighted.cluster",analysisName = analysisName ) |
|
82 |
- #metadata(inSCE)$sctk$music[[analysisName]][["Heatmap"]]<- temp_results |
|
83 |
- |
|
84 |
- } |
|
85 |
- |
|
86 |
- |
|
87 |
- return(plots) |
|
88 |
-} |
|
89 |
- |