Skip to content

Commit

Permalink
Fix metadata slot problem.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gene233 committed Mar 26, 2024
1 parent 470b22f commit 34bf266
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ Suggests:
URL: https://davislaboratory.github.io/smartid
BugReports: https://github.com/DavisLaboratory/smartid/issues
VignetteBuilder: knitr
Language: en-US
Config/testthat/edition: 3
LazyData: false
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@ importClassesFrom(Matrix,dgCMatrix)
importFrom(SummarizedExperiment,SummarizedExperiment)
importFrom(SummarizedExperiment,assay)
importFrom(SummarizedExperiment,colData)
importFrom(SummarizedExperiment,metadata)
importFrom(utils,globalVariables)
importFrom(utils,stack)
6 changes: 3 additions & 3 deletions R/score-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ setMethod(
)

SummarizedExperiment::assay(data, i = new.slot) <- res$score
metadata(data)$tf <- res$tf
metadata(data)$idf <- res$idf
metadata(data)$iae <- res$iae
slot(data, "metadata")$tf <- res$tf
slot(data, "metadata")$idf <- res$idf
slot(data, "metadata")$iae <- res$iae

return(data)
}
Expand Down
2 changes: 1 addition & 1 deletion R/smartid-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#' @import methods
#' @import stats
#' @import graphics
#' @importFrom SummarizedExperiment SummarizedExperiment assay colData metadata
#' @importFrom SummarizedExperiment SummarizedExperiment assay colData
#' @importFrom utils globalVariables stack
#' @importClassesFrom Matrix dgCMatrix
NULL
Expand Down
22 changes: 11 additions & 11 deletions vignettes/smartid_Demo.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,23 @@ idf_iae_methods()
```

The basic version of TF, IDF and IAE can be termed as:
$$\mathbf{TF_{i,j}}=\frac{N_{i,j}}{\sum_j{N_{i,j}}}$$
$$\mathbf{IDF_i} = log(1+\frac{n}{n_i+1})$$
$$\mathbf{IAE_i} = log(1+\frac{n}{\hat N_{i,j}+1})$$
$\mathbf{TF_{i,j}}=\frac{N_{i,j}}{\sum_j{N_{i,j}}}$
$\mathbf{IDF_i} = log(1+\frac{n}{n_i+1})$
$\mathbf{IAE_i} = log(1+\frac{n}{\hat N_{i,j}+1})$

$$where\ N_{i,j}\ is\ the\ counts\ of\ feature\ i\ in\ cell\ j;\ \hat N_{i,j}\ is\ max(0,\ N_{i,j} - threshold);$$
$$\ n\ is\ total\ counts\ of\ documents(cells);\ n_i\ is\ \sum_{j = 1}^{n} sign(N_{i,j} > threshold)$$
$where\ N_{i,j}\ is\ the\ counts\ of\ feature\ i\ in\ cell\ j;\ \hat N_{i,j}\ is\ max(0,\ N_{i,j} - threshold);$
$\ n\ is\ total\ counts\ of\ documents(cells);\ n_i\ is\ \sum_{j = 1}^{n} sign(N_{i,j} > threshold)$

Here for labeled data, we can choose logTF * IDF_prob * IAE_prob for marker identification.

$\mathbf{score}=logTF*IDF_{prob}*IAE_{prob}$

The probability version of IDF can be termed as:
$$\mathbf{IDF_{i,j}} = log(1+\frac{\frac{n_{i,j\in D}}{n_{j\in D}}}{max(\frac{n_{i,j\in \hat D}}{n_{j\in \hat D}})+ e^{-8}}\frac{n_{i,j\in D}}{n_{j\in D}})$$
$\mathbf{IDF_{i,j}} = log(1+\frac{\frac{n_{i,j\in D}}{n_{j\in D}}}{max(\frac{n_{i,j\in \hat D}}{n_{j\in \hat D}})+ e^{-8}}\frac{n_{i,j\in D}}{n_{j\in D}})$

And the probability version of IAE can be termed as:
$$\mathbf{IAE_{i,j}} = log(1+\frac{mean(N_{i,j\in D})}{max(mean(N_{i,j\in \hat D}))+ e^{-8}}*mean(N_{i,j\in D}))$$
$$where\ D\ is\ the\ category\ of\ cell\ j;\ \hat D\ is\ the\ category\ other\ than\ D.$$
$\mathbf{IAE_{i,j}} = log(1+\frac{mean(N_{i,j\in D})}{max(mean(N_{i,j\in \hat D}))+ e^{-8}}*mean(N_{i,j\in D}))$
$where\ D\ is\ the\ category\ of\ cell\ j;\ \hat D\ is\ the\ category\ other\ than\ D.$

TF here stands for gene frequency, which is similar to CPM, while IDF represents the inverse cell/sample frequency for scRNA-seq data, and IAE is the inverse average expression of each gene across all cells or cells in each labeled group.

Expand Down Expand Up @@ -179,7 +179,7 @@ score_barplot(
)
```

As we can see, there is a UP DEG 'Gene76' not popping up in Group 2, we can check this gene's relative expression using violin plot. It is clear that this gene is not significantly highly expressed in Group 2 and the average expression is quite low across all cells.
As we can see, there is an UP DEG 'Gene76' not popping up in Group 2, we can check the relative expression of this gene using violin plot. It is clear that this gene is not significantly highly expressed in Group 2 and the average expression is quite low across all cells.

This can also be confirmed in data simulation information, where the scale factor is higher in Group2, but the GeneMean is too small to be confident. Thus this gene won't be selected by `smartid`.

Expand Down Expand Up @@ -258,8 +258,8 @@ Here we choose logTF * IDF_sd * IAE_sd for for gene-set scoring as a use case.

$\mathbf{score}=logTF*IDF_{sd}*IAE_{sd}$

$$where\ \mathbf{IDF} = log(1+sd(N_{i})*\frac{n}{n_i+1})$$
$$\mathbf{IAE} = log(1+sd(N_{i})*\frac{n}{\sum_{j=1}^{n}N_{i,j}+1})$$
$where\ \mathbf{IDF} = log(1+sd(N_{i})*\frac{n}{n_i+1})$
$\mathbf{IAE} = log(1+sd(N_{i})*\frac{n}{\sum_{j=1}^{n}N_{i,j}+1})$

## Score Samples

Expand Down

0 comments on commit 34bf266

Please sign in to comment.