Skip to content

Commit 40dc2d1

Browse files
author
Khodadadi-Jamayran
committed
1.2.7
1 parent bce262f commit 40dc2d1

20 files changed

+142
-62
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: iCellR
22
Type: Package
33
Title: Analyzing High-Throughput Single Cell Sequencing Data
4-
Version: 1.2.5
4+
Version: 1.2.7
55
Author: Alireza Khodadadi-Jamayran,
66
Joseph Pucella,
77
Hua Zhou,
@@ -23,4 +23,4 @@ RoxygenNote: 6.1.1
2323
URL: https://github.com/rezakj/iCellR
2424
Suggests: phateR, Rmagic, Seurat
2525
NeedsCompilation: no
26-
Packaged: 2019-11-04 21:36:26 UTC; khodaa01
26+
Packaged: 2019-12-04 18:31:12 UTC; khodaa01

R/F008.norm.data.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#' This function takes an object of class iCellR and normalized the data based on "global.glsf", "ranked.glsf" or "spike.in" methods.
44
#' @param x An object of class iCellR.
55
#' @param norm.method Choose a normalization method, there are three option currently.
6-
#' Choose from "global.glsf", "ranked.glsf", "ranked.deseq", "deseq", "rpm","spike.in" or no.norm, default = "ranked.glsf".
6+
#' Choose from "global.glsf", "ranked.glsf","spike.in" or no.norm, default = "ranked.glsf".
77
#' @param top.rank If the method is set to "ranked.glsf", you need to set top number of genes sorted based on global base mean, default = 500.
88
#' @param spike.in.factors A numeric vector of spike-in values with the same cell id order as the main data.
99
#' @param rpm.factor If the norm.method is set to "rpm" the library sizes would be diveded by this number, default = 1000 (higher numbers recomanded for bulk RNA-Seq).

R/F012.run.pca.R

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#' @param data.type Choose from "main" and "imputed", default = "main"
88
#' @param plus.log.value A number to add to each value in the matrix before log transformasion to aviond Inf numbers, default = 0.1.
99
#' @param gene.list A charactor vector of genes to be used for PCA. If "clust.method" is set to "gene.model", default = "my_model_genes.txt".
10-
#' @param batch.norm If TRUE the data will be normalized based on the genes in gene.list or top ranked genes.
10+
#' @param scale.data If TRUE the data will be scaled (log2 + plus.log.value), default = TRUE.
1111
#' @return An object of class iCellR.
1212
#' @examples
1313
#' demo.obj <- run.pca(demo.obj, method = "gene.model", gene.list = demo.obj@gene.model)
@@ -20,7 +20,7 @@ run.pca <- function (x = NULL,
2020
method = "base.mean.rank",
2121
top.rank = 500,
2222
plus.log.value = 0.1,
23-
batch.norm = FALSE,
23+
scale.data = TRUE,
2424
gene.list = "character") {
2525
if ("iCellR" != class(x)[1]) {
2626
stop("x should be an object of class iCellR")
@@ -36,8 +36,10 @@ run.pca <- function (x = NULL,
3636
# model base mean rank
3737
if (method == "base.mean.rank") {
3838
raw.data.order <- DATA[ order(rowMeans(DATA), decreasing = TRUE), ]
39-
topGenes <- head(raw.data.order,top.rank)
40-
TopNormLogScale <- log(topGenes + plus.log.value)
39+
TopNormLogScale <- head(raw.data.order,top.rank)
40+
if(scale.data == TRUE) {
41+
TopNormLogScale <- log(TopNormLogScale + plus.log.value)
42+
}
4143
# TopNormLogScale <- scale(topGenes)
4244
# TopNormLogScale <- t(TopNormLogScale)
4345
# TopNormLogScale <- as.data.frame(t(scale(TopNormLogScale)))
@@ -49,24 +51,28 @@ run.pca <- function (x = NULL,
4951
} else {
5052
genesForClustering <- gene.list
5153
topGenes <- subset(DATA, rownames(DATA) %in% genesForClustering)
52-
if (batch.norm == FALSE){
5354
if (data.type == "main") {
54-
TopNormLogScale <- log2(topGenes + plus.log.value)
55-
}
55+
TopNormLogScale <- topGenes
56+
if(scale.data == TRUE) {
57+
TopNormLogScale <- log(TopNormLogScale + plus.log.value)
58+
}
5659
if (data.type == "imputed") {
57-
# TopNormLogScale <- topGenes
58-
TopNormLogScale <- t(scale(t(topGenes)))
60+
TopNormLogScale <- topGenes
61+
if(scale.data == TRUE) {
62+
TopNormLogScale <- t(scale(t(topGenes)))
63+
# TopNormLogScale <- log(TopNormLogScale + plus.log.value)
64+
}
5965
}
6066
}
61-
if (batch.norm == TRUE){
62-
## new method
63-
libSiz <- colSums(topGenes)
64-
norm.facts <- as.numeric(libSiz) / mean(as.numeric(libSiz))
65-
dataMat <- as.matrix(topGenes)
66-
normalized <- as.data.frame(sweep(dataMat, 2, norm.facts, `/`))
67+
# if (batch.norm == TRUE){
68+
# ## new method
69+
# libSiz <- colSums(topGenes)
70+
# norm.facts <- as.numeric(libSiz) / mean(as.numeric(libSiz))
71+
# dataMat <- as.matrix(topGenes)
72+
# normalized <- as.data.frame(sweep(dataMat, 2, norm.facts, `/`))
6773
# TopNormLogScale <- log2(normalized + plus.log.value)
68-
TopNormLogScale <- normalized
69-
}
74+
# TopNormLogScale <- normalized
75+
# }
7076
}
7177
}
7278
# Returns

R/F021.clust.avg.exp.R

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
#'
33
#' This function takes an object of class iCellR and creates an average gene expression for every cluster.
44
#' @param x An object of class iCellR.
5+
#' @param data.type Choose from "main" and "imputed", default = "main"
56
#' @return An object of class iCellR.
67
#' @examples
78
#' demo.obj <- clust.avg.exp(demo.obj)
89
#'
910
#' head(demo.obj@clust.avg)
1011
#' @export
11-
clust.avg.exp <- function (x = NULL) {
12+
clust.avg.exp <- function (x = NULL,
13+
data.type = "main") {
1214
if ("iCellR" != class(x)[1]) {
1315
stop("x should be an object of class iCellR")
1416
}
@@ -17,7 +19,14 @@ clust.avg.exp <- function (x = NULL) {
1719
sampleCondition <- DATA$clusters
1820
conditions <- sort(unique(sampleCondition))
1921
DATA1 <- DATA
20-
Table = x@main.data
22+
## get main data
23+
if (data.type == "main") {
24+
Table <- x@main.data
25+
}
26+
if (data.type == "imputed") {
27+
Table <- x@imputed.data
28+
}
29+
# Table = x@main.data
2130
for(i in conditions){
2231
IDs <- rownames(subset(DATA1, sampleCondition == i))
2332
DATA <- Table[ , which(names(Table) %in% IDs)]

R/F022.run.imput.R

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
#' This function takes an object of class iCellR and runs imputation on the main data.
44
#' @param x An object of class iCellR.
55
#' @param imp.method Choose between "iCellR.imp" and "magic", defualt = "iCellR.imp".
6-
#' @param cell.ratio Percent of cells to use to find neighboring cells, default = 2.
6+
#' @param nn Number of neighboring cells to find, default = 10.
77
#' @param dims PC dimentions to be used for the analysis, default = 10.
88
#' @param data.type Choose between "tsne", "pca", "umap", "diffusion", default = "pca".
99
#' @param genes character or integer vector, default: NULL vector of column names or column indices for which to return smoothed data If 'all_genes' or NULL, the entire smoothed matrix is returned
10-
#' @param k int, optional, default: 10 number of nearest neighbors on which to build kernel
11-
#' @param alpha int, optional, default: 15 sets decay rate of kernel tails. If NULL, alpha decaying kernel is not used
12-
#' @param t int, optional, default: 'auto' power to which the diffusion operator is powered sets the level of diffusion. If 'auto', t is selected according to the Procrustes disparity of the diffused data.'
10+
#' @param k if imp.method is magic; int, optional, default: 10 number of nearest neighbors on which to build kernel
11+
#' @param alpha if imp.method is magic; int, optional, default: 15 sets decay rate of kernel tails. If NULL, alpha decaying kernel is not used
12+
#' @param t if imp.method is magic; int, optional, default: 'auto' power to which the diffusion operator is powered sets the level of diffusion. If 'auto', t is selected according to the Procrustes disparity of the diffused data.'
1313
#' @param npca number of PCA components that should be used; default: 100.
1414
#' @param init magic object, optional object to use for initialization. Avoids recomputing intermediate steps if parameters are the same.
15-
#' @param t.max int, optional, default: 20 Maximum value of t to test for automatic t selection.
15+
#' @param t.max if imp.method is magic; int, optional, default: 20 Maximum value of t to test for automatic t selection.
1616
#' @param knn.dist.method string, optional, default: 'euclidean'. recommended values: 'euclidean', 'cosine' Any metric from 'scipy.spatial.distance' can be used distance metric for building kNN graph.
1717
#' @param verbose 'int' or 'boolean', optional (default : 1) If 'TRUE' or '> 0', message verbose updates.
1818
#' @param n.jobs 'int', optional (default: 1) The number of jobs to use for the computation. If -1 all CPUs are used. If 1 is given, no parallel computing code is used at all, which is useful for debugging. For n_jobs below -1, (n.cpus + 1 + n.jobs) are used. Thus for n_jobs = -2, all CPUs but one are used
1919
#' @param seed int or 'NULL', random state (default: 'NULL')
2020
#' @return An object of class iCellR.
2121
#' @export
2222
run.impute <- function (x = NULL,
23-
imp.method = "iCellR.imp", dims = 1:10,cell.ratio = 2,
23+
imp.method = "iCellR.imp", dims = 1:10, nn = 10,
2424
data.type = "pca",genes = "all_genes", k = 10, alpha = 15, t = "auto",
2525
npca = 100, init = NULL, t.max = 20,
2626
knn.dist.method = "euclidean", verbose = 1, n.jobs = 1,
@@ -55,10 +55,11 @@ run.impute <- function (x = NULL,
5555
message(paste(" Calculating distance ..."))
5656
My.distances = as.matrix(dist(t(my.data.my.pca), method = knn.dist.method))
5757
ncells = dim(my.data)[2]
58-
cell.num = ceiling(cell.ratio/100 * ncells)
59-
message(paste(" ",cell.ratio,"percent of ",ncells, "cells is", cell.num))
60-
message(" To change the number of neighboring cells cahnge cell.ratio option")
58+
# cell.num = ceiling(cell.ratio/100 * ncells)
59+
cell.num = nn
60+
# message(paste(" ",cell.ratio,"percent of ",ncells, "cells is", cell.num))
6161
message(paste(" Finding",cell.num, "neighboring cells per cell ..."))
62+
message(" To change the number of neighboring cells cahnge nn option")
6263
KNN1 = lapply(1:ncells, function(findKNN){
6364
order(My.distances[,findKNN])[1:cell.num]})
6465
############

R/F027.clust.stats.plot.R

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#'
33
#' This function takes an object of class iCellR and creates QC plot.
44
#' @param x An object of class iCellR.
5-
#' @param plot.type Choose from "box.umi", "box.mito", "box.gene", default = "box.mito".
5+
#' @param plot.type Choose from "bar.cc", "pie.cc" , box.umi", "box.mito", "box.gene", default = "box.mito".
66
#' @param cell.color Choose a color for points in the plot.
77
#' @param cell.size A number for the size of the points in the plot, default = 1.
88
#' @param box.color A color for the boxes in the "boxplot", default = "red".
@@ -41,7 +41,21 @@ clust.stats.plot <- function (x = NULL,
4141
MyClusts <- x@best.clust
4242
# merge
4343
DATA <- merge(DATA, MyClusts, by = "row.names", all.x=FALSE, all.y=TRUE)
44-
# plot
44+
###### # plot
45+
# cell cycle
46+
# bar
47+
COUNTS <- c(1:length(DATA$Phase))
48+
myBP <- ggplot(DATA,aes(y=COUNTS,
49+
x=clusters, fill = Phase)) +
50+
geom_bar(stat = "identity") + theme_bw() +
51+
theme(axis.text.x=element_text(angle=90)) +
52+
ylab("Cell number ratio")
53+
# pie
54+
myPIE <- ggplot(DATA,aes(y=clusters, x="", fill = Phase)) +
55+
geom_bar(stat = "identity", position = "fill") + theme_bw() + facet_wrap(~ clusters) +
56+
theme(axis.title.y=element_blank(),
57+
axis.text.y=element_blank(),
58+
axis.ticks.y=element_blank()) + coord_polar(theta="y")
4559
# mito
4660
mito.percent.plot <- ggplot(DATA,aes(y=mito.percent, x=as.factor(clusters))) +
4761
geom_jitter(color = cell.color, size = cell.size, alpha = cell.transparency) +
@@ -70,7 +84,7 @@ clust.stats.plot <- function (x = NULL,
7084
if (plot.type == "box.umi") {
7185
if (interactive == TRUE) {
7286
OUT.PUT <- paste(out.name, ".html", sep="")
73-
htmlwidgets::saveWidget(ggplotly(Mito.UMIs),OUT.PUT)
87+
htmlwidgets::saveWidget(ggplotly(UMIsplot),OUT.PUT)
7488
}
7589
else
7690
return(UMIsplot)
@@ -79,7 +93,7 @@ clust.stats.plot <- function (x = NULL,
7993
if (plot.type == "box.mito") {
8094
if (interactive == TRUE) {
8195
OUT.PUT <- paste(out.name, ".html", sep="")
82-
htmlwidgets::saveWidget(ggplotly(Mito.UMIs),OUT.PUT)
96+
htmlwidgets::saveWidget(ggplotly(mito.percent.plot),OUT.PUT)
8397
}
8498
else
8599
return(mito.percent.plot)
@@ -88,9 +102,27 @@ clust.stats.plot <- function (x = NULL,
88102
if (plot.type == "box.gene") {
89103
if (interactive == TRUE) {
90104
OUT.PUT <- paste(out.name, ".html", sep="")
91-
htmlwidgets::saveWidget(ggplotly(Mito.UMIs),OUT.PUT)
105+
htmlwidgets::saveWidget(ggplotly(nGenes.plot),OUT.PUT)
92106
}
93107
else
94108
return(nGenes.plot)
95109
}
110+
#
111+
if (plot.type == "pie.cc") {
112+
if (interactive == TRUE) {
113+
OUT.PUT <- paste(out.name, ".html", sep="")
114+
htmlwidgets::saveWidget(ggplotly(myPIE),OUT.PUT)
115+
}
116+
else
117+
return(myPIE)
118+
}
119+
#
120+
if (plot.type == "bar.cc") {
121+
if (interactive == TRUE) {
122+
OUT.PUT <- paste(out.name, ".html", sep="")
123+
htmlwidgets::saveWidget(ggplotly(myBP),OUT.PUT)
124+
}
125+
else
126+
return(myBP)
127+
}
96128
}

R/F028.findMarkers.R

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#'
33
#' This function takes an object of class iCellR and performs differential expression (DE) analysis to find marker genes for each cluster.
44
#' @param x An object of class iCellR.
5+
#' @param data.type Choose from "main" and "imputed", default = "main"
56
#' @param fold.change A number that designates the minimum fold change for out put, default = 2.
67
#' @param padjval Minimum adjusted p value for out put, default = 0.1.
78
#' @param Inf.FCs If set to FALSE the infinite fold changes would be filtered from out put, default = FALSE.
@@ -15,6 +16,7 @@
1516
#' head(marker.genes)
1617
#' @export
1718
findMarkers <- function (x = NULL,
19+
data.type = "main",
1820
fold.change = 2,
1921
padjval = 0.1,
2022
Inf.FCs = FALSE,
@@ -25,8 +27,17 @@ findMarkers <- function (x = NULL,
2527
}
2628
###########
2729
# x <- clust.avg.exp(x)
28-
dat <- x@main.data
30+
# dat <- x@main.data
31+
## get main data
32+
if (data.type == "main") {
33+
dat <- x@main.data
34+
}
35+
if (data.type == "imputed") {
36+
dat <- x@imputed.data
37+
}
2938
# get cluster data
39+
# get avrages
40+
x <- clust.avg.exp(x, data.type = data.type)
3041
DATA <- x@best.clust
3142
############## set wich clusters you want as condition 1 and 2
3243
MyClusts <- as.numeric(unique(DATA$clusters))
@@ -99,12 +110,14 @@ findMarkers <- function (x = NULL,
99110
mrgdall <- merge(Stats, Stats1, by="row.names")
100111
row.names(mrgdall) <- mrgdall$Row.names
101112
mrgdall <- mrgdall[,-1]
102-
# get avrage data
103-
AvData <- x@clust.avg
104-
row.names(AvData) <- AvData$gene
105-
mrgdall <- merge(mrgdall, AvData, by="row.names")
106-
row.names(mrgdall) <- mrgdall$Row.names
107-
mrgdall <- mrgdall[,-1]
113+
############################# get avrage data
114+
# if (add.avg == TRUE) {
115+
AvData <- x@clust.avg
116+
row.names(AvData) <- AvData$gene
117+
mrgdall <- merge(mrgdall, AvData, by="row.names")
118+
row.names(mrgdall) <- mrgdall$Row.names
119+
mrgdall <- mrgdall[,-1]
120+
# }
108121
# make it an object
109122
DatNmaes=paste("DATAcluster",i,sep="_")
110123
eval(call("<-", as.name(DatNmaes), mrgdall))

R/F030.heatmap.gg.plot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#' @export
3939
heatmap.gg.plot <- function (x = NULL,
4040
gene = "NULL",
41-
cell.sort = TRUE,
41+
cell.sort = FALSE,
4242
data.type = "main",
4343
cluster.by = "clusters",
4444
min.scale = -2.5,

R/F034.diff.exp.R

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#'
33
#' This function takes an object of class iCellR and performs differential expression (DE) analysis for clusters and conditions.
44
#' @param x An object of class iCellR.
5+
#' @param data.type Choose from "main" and "imputed", default = "main"
56
#' @param de.by Choose from "clusters", "conditions", "clustBase.condComp" or "condBase.clustComp".
67
#' @param cond.1 First condition to do DE analysis on.
78
#' @param cond.2 Second condition to do DE analysis on.
@@ -14,6 +15,7 @@
1415
#'
1516
#' @export
1617
run.diff.exp <- function (x = NULL,
18+
data.type = "main",
1719
de.by = "clusters",
1820
cond.1 = "array",
1921
cond.2 = "array",
@@ -22,7 +24,14 @@ run.diff.exp <- function (x = NULL,
2224
stop("x should be an object of class iCellR")
2325
}
2426
###########
25-
dat <- x@main.data
27+
# dat <- x@main.data
28+
## get main data
29+
if (data.type == "main") {
30+
dat <- x@main.data
31+
}
32+
if (data.type == "imputed") {
33+
dat <- x@imputed.data
34+
}
2635
# 2 dimentions
2736
DATA <- x@best.clust
2837
############## set wich clusters you want as condition 1 and 2

R/F045.cc.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
#' @return The data frame object
88
#' @importFrom Hmisc cut2
99
#' @export
10-
cc <- function (object = NULL, s.genes = s.phase, g2m.genes = g2m.phase) {
10+
cc <- function (object = NULL,
11+
s.genes = s.phase,
12+
g2m.genes = g2m.phase) {
1113
if ("iCellR" != class(object)[1]) {
1214
stop("object should be an object of class iCellR")
1315
}

0 commit comments

Comments
 (0)