Title: | Reconstructing Ordered Ontogenic Trajectories |
---|---|
Description: | A set of tools to reconstruct ordered ontogenic trajectories from single cell RNAseq data. |
Authors: | Wajid Jawaid [aut, cre] |
Maintainer: | Wajid Jawaid <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0 |
Built: | 2024-12-07 06:49:14 UTC |
Source: | CRAN |
Animation plot
animPlot(data, ccm, delay = 0.1, darken = 1, lwd = 1, c.cex = 1, main = "", ...)
animPlot(data, ccm, delay = 0.1, darken = 1, lwd = 1, c.cex = 1, main = "", ...)
data |
Dimensionality reduction plot |
ccm |
Dataframe of indices and momentums |
delay |
Delay between frames in seconds |
darken |
Passed to colGrad() function |
lwd |
Line width |
c.cex |
Size of poiints. |
main |
Plot title |
... |
Passed to plot() function |
Animation plot Generates plot in base R that gradually updates giving the impression of an animation
Generates plot
Wajid Jawaid
## Not run: xx <- animPlot(x, ccm) ## End(Not run)
## Not run: xx <- animPlot(x, ccm) ## End(Not run)
Generates a GIF animation
animPlotGif(data, ccm, delay = 0.1, darken = 1, lwd = 1, c.cex = 1, main = "", gif = "animation", img.name = "tempPlot", plot.par = NULL, point.col = "#333333", arrowLength = 0.1, ...)
animPlotGif(data, ccm, delay = 0.1, darken = 1, lwd = 1, c.cex = 1, main = "", gif = "animation", img.name = "tempPlot", plot.par = NULL, point.col = "#333333", arrowLength = 0.1, ...)
data |
Reduced dimensionality map to be used for visualisation |
ccm |
Dataframe of indices and momentums |
delay |
Delay between frames in seconds |
darken |
Passed to colGrad() function |
lwd |
Line width |
c.cex |
Size of poiints. |
main |
Title |
gif |
Name of movie |
img.name |
Name of temporary image files generated |
plot.par |
Passed to R base par() function |
point.col |
Colour of background points |
arrowLength |
Modify length of arrow |
... |
Passed to plot() function |
Generates a GIF animation
Produces an animated GIF with given file name
Wajid Jawaid
## Not run: xx <- animPlotGif(x, ccm, gif = "animation") ## End(Not run)
## Not run: xx <- animPlotGif(x, ccm, gif = "animation") ## End(Not run)
Apply Gaussian Kernel using Laleh Haghverdi's variable sigma
applyGaussianKernelwithVariableSigma(d2, rsigmas, csigmas = NULL)
applyGaussianKernelwithVariableSigma(d2, rsigmas, csigmas = NULL)
d2 |
Squared distance metric |
rsigmas |
Sigmas for cells in the rows |
csigmas |
Sigmas for cells in the columns |
Apply Gaussian Kernel using Laleh Haghverdi's variable sigma
Returns matrix of same size as d2.
Wajid Jawaid
## Not run: d <- applyGaussianKernelwithVariableSigma(dist, sigmas) ## End(Not run)
## Not run: d <- applyGaussianKernelwithVariableSigma(dist, sigmas) ## End(Not run)
Normalise by background gene set
bgGeneNorm(x, threshold = 0.05)
bgGeneNorm(x, threshold = 0.05)
x |
Matrix to be normalised with cells in rows and genes in columns |
threshold |
Default 0.05. The threshold below which a gene is deemed background |
Normalise by background gene set. Find background genes that are expressed at a lower percentage of the total library size per cell than 'threshold' parameter. These genes are used to calculate a normalisation factor.
Returns a normalised matrix of same dimenions as 'x'
Wajid Jawaid
## Not run: normGenes <- bgGeneNorm(x) ## End(Not run)
## Not run: normGenes <- bgGeneNorm(x) ## End(Not run)
Calculates sigmas for a distance matrix
calculateVariableSigmas(d, knn)
calculateVariableSigmas(d, knn)
d |
Square distance matrix with 0 diagonal |
knn |
Number of nearest neighbours to use for calculation |
Calculates sigmas for a distance matrix Using Laleh Hagherverdi's method
Returns a vector of sigmas
wj241
## Not run: sigmas <- calculateVariableSigmas(dist, 5) ## End(Not run)
## Not run: sigmas <- calculateVariableSigmas(dist, 5) ## End(Not run)
Generates a smooth colour gradient
colGrad(x, darken = 1)
colGrad(x, darken = 1)
x |
Number of colours required |
darken |
Multiplication factor. Must be less than 1. Smaller the darker. |
Generates a smooth colour gradient Goes from red to red/green to green to green/blue to blue to blu/red
Returns vector of RGB colours
Wajid Jawaid
gradientColors <- colGrad(10)
gradientColors <- colGrad(10)
Generic diffusion function using automated individualised sigma calculation
diffuseMat(data, ndims = 20, nsig = 5, removeFirst = TRUE, useARPACK = TRUE, distfun = NULL, sigmas = NULL, sqdistmat = NULL)
diffuseMat(data, ndims = 20, nsig = 5, removeFirst = TRUE, useARPACK = TRUE, distfun = NULL, sigmas = NULL, sqdistmat = NULL)
data |
Matrix of data with genes in rows and cells in columns. |
ndims |
Number of dimensions to return |
nsig |
For automatic sigma calculation |
removeFirst |
Default TRUE. Removes the first eigenvector |
useARPACK |
Default TRUE. Uses Arnoldi algorithm for eignvector calculations |
distfun |
A different distance function that returns the squared distance |
sigmas |
Manually provide sigma |
sqdistmat |
Squared distance matrix. Give your own squared distance matrix. |
Generic diffusion function using automated individualised sigma calculation.
A Gaussian kernel is applied to the chosen distance metric producing
an square unnormalised symmetric transition matrix,
.
Let
be an
diagonal matrix with row(column) sums of
as entries. The density corrected transition matrix will now
be:
and can be normalised:
where is an
diagonal matrix with row sums of
the density corrected transition matrix as entries. The eigen decomposition of
this matrix can be simplified by solving the symmetric system:
where is a matrix of the right eigenvectors that solve
the system and
is the corresponding eigenvalue
diagonal matrix. Now the solution of:
in terms of and
is:
and
This without the first eigen vector is returned as the diffusion map.
List output containing:
values | Eigenvalues, excluding the first eigenvalue, which should always be 1. |
vectors | Matrix of eigen vectors in columns, first eigen vector removed. |
nconv | Number of eigen vectors/values that converged. |
niter | Iterations taken for Arnoldi algorithm to converge. |
nops | Number of operations. |
val0 | 1st eigen value - should be 1. If not be suspicious! |
vec0 | 1st eigen vector - should be ,
where n is the number of cells/samples. |
usedARPACK | Predicates use of ARPACK for spectral decomposition. |
distfun | Function used to calculate the squared distance. |
nn | Number of nearest neighbours used for calculating sigmas . |
d2 | Matrix of squared distances, returned from distfun . |
sigmas | Vector of sigmas. Same length as number of cells if individual |
sigmas were calculated, otherwise a scalar if was supplied. | |
gaussian | Unnormalised transition matrix after applying Gaussian. |
markov | Normalised gaussian matrix. |
densityCorrected | Matrix after applying density correction to
markov . |
Wajid Jawaid
Haghverdi, L., Buettner, F., Theis, F.J., 2015. Diffusion maps for high-dimensional single-cell analysis of differentiation data. Bioinformatics 31, 2989–2998.
Haghverdi, L., Büttner, M., Wolf, F.A., Buettner, F., Theis, F.J., 2016. Diffusion pseudotime robustly reconstructs lineage branching. Nat Meth 13, 845–848.
Angerer, P., Haghverdi, L., Büttner, M., Theis, F.J., Marr, C., Buettner, F., 2016. destiny: diffusion maps for large-scale single-cell data in R. Bioinformatics 32, 1241–1243.
## Not run: xx <- diffuseMat(x) ## End(Not run)
## Not run: xx <- diffuseMat(x) ## End(Not run)
Predicts diffusion map projection from new data points
diffuseProj(dm, x, data, distfun)
diffuseProj(dm, x, data, distfun)
dm |
Output from diffuseMat2 function |
x |
Matrix of new data points. Features in rows and cells in columns. |
data |
Original data used to generate diffusion map |
distfun |
A distance function that takes new data as first paramter and previous data as second variable returning a squared distance measure, with each sample in the rows and distance to previous data points in columns, e.g. function(x, y) (1 - cor(x, y))^2. |
Predicts diffusion map projection from new data points
Returns a matrix with projected diffusion components.
Wajid Jawaid
## Not run: y <- diffuseProj(xx, newData, oldData, function(z) (1-cor(z))^2) ## End(Not run)
## Not run: y <- diffuseProj(xx, newData, oldData, function(z) (1-cor(z))^2) ## End(Not run)
Fast vectorised Euclidean distance calculator
fastDist(x, squared = FALSE)
fastDist(x, squared = FALSE)
x |
Matrix with vectors in columns. |
squared |
Will not perform the square root, i.e. will return the squared ‘L2-norm’. |
Calculates Euclidean distances between vectors arranged as columns in a matrix.
Returns a matrix of pairwise distances
Wajid Jawaid
## Not run: dist <- fastDist(x) ## End(Not run)
## Not run: dist <- fastDist(x) ## End(Not run)
Filter genes
filterGenes(x, mu = 0.01, cv = 2, fano = FALSE)
filterGenes(x, mu = 0.01, cv = 2, fano = FALSE)
x |
Matrix to be normalised with cells in rows and genes in columns |
mu |
Meam threshold |
cv |
Coefficient of variation or Fano factor threshold. |
fano |
Default TRUE. Predicate treat CV as Fano factor or CV |
Filter genes Filter genes by mean and either coefficient of variation, cv or Fano factor.
Returns a filtered matrix with same number of cells but fewer genes than 'x'
Wajid Jawaid
## Not run: expressionGenesFiltered <- filterGenes(x) ## End(Not run)
## Not run: expressionGenesFiltered <- filterGenes(x) ## End(Not run)
Louvain clustering on transition matrix
findLouvain(mkv)
findLouvain(mkv)
mkv |
Transition matrix |
Louvain clustering on transition matrix
Returns a list with graph, dataframe and community object
Wajid Jawaid
## Not run: xx <- findLouvain(mkv) xx$cll ## End(Not run)
## Not run: xx <- findLouvain(mkv) xx$cll ## End(Not run)
Find next cell function
fnc(rdmap, tm, curInd, mom = NULL, momAdj = 0.5, w1 = exp(1), w2 = 1, varEst = 10)
fnc(rdmap, tm, curInd, mom = NULL, momAdj = 0.5, w1 = exp(1), w2 = 1, varEst = 10)
rdmap |
reduced dimensionality matrix with cells in rows and dims in columns |
tm |
Transition matrix |
curInd |
Current state on tm |
mom |
Current momentum vector |
momAdj |
Weighting to adjust momentum. From 0-1. Lower numbers make smaller adjustment to momentum vector. |
w1 |
Parameter - Base used for modifying of tm probs. |
w2 |
Parameter - Multiplifaction factor used for modifying tm probs. |
varEst |
Number of alternatives to sample for estimating variance. |
Find next cell function. Transitioin probabilities are modifed by calulating the cosine of the angle between the current momentum vector and the vector on the rdmap required for each transtion. The tranisiton probability is adjusted by multiplying by w1^(w2 * (cosine_angle)) and then normalising.
Returns index of new cell and new momentum vector
Wajid Jawaid
## Not run: nextCell <- fnc(rdmap, tm, curInd) ## End(Not run)
## Not run: nextCell <- fnc(rdmap, tm, curInd) ## End(Not run)
Return a plausible developmental journey
getTraj(rdmap, tm, sourceCellInds, terminalCellsInd = NULL, momAdj = 0.5, w1 = exp(1), w2 = 1, simLen = 50, sim.seed = NULL, varEst = 10)
getTraj(rdmap, tm, sourceCellInds, terminalCellsInd = NULL, momAdj = 0.5, w1 = exp(1), w2 = 1, simLen = 50, sim.seed = NULL, varEst = 10)
rdmap |
reduced dimensionality matrix with cells in rows and dims in columns |
tm |
Transition matrix |
sourceCellInds |
Starting sell indices |
terminalCellsInd |
Terminal cell indices |
momAdj |
Weighting to adjust momentum. From 0-1. Lower numbers make smaller adjustment to momentum vector. |
w1 |
Parameter - Base used for modifying of tm probs. |
w2 |
Parameter - Multiplifaction factor used for modifying tm probs. |
simLen |
Maximum number of allowable tranisitons |
sim.seed |
Random seed for reproducibility |
varEst |
Number of alternatives to sample for estimating variance. |
Return a plausible developmental journey
Returns a data.frame of ordered indices and momentums
Wajid Jawaid
## Not run: traj <- getTraj(rdmap, tm, startCells, terminalCells) ## End(Not run)
## Not run: traj <- getTraj(rdmap, tm, startCells, terminalCells) ## End(Not run)
View single cell dataset
goggles(x, pcaDims = 90, nsig = 5, dmat = NULL, mkv = NULL, plotDims = 2, kernSq = 2, ...)
goggles(x, pcaDims = 90, nsig = 5, dmat = NULL, mkv = NULL, plotDims = 2, kernSq = 2, ...)
x |
Matrix with cells in rows and gene in columns |
pcaDims |
Number of PCA dimensions to keep for distance measure |
nsig |
Number of significant neighbours to keep for Gaussian kernel |
dmat |
Optional. Give your own distance matrix |
mkv |
Optional. Give your own markov matrix. |
plotDims |
Default 2. Number of dimensions to plot |
kernSq |
Factor to tighten kernel - operates on sigmas. |
... |
Additonal parameters not currently in use |
View single cell dataset
A list of l, dimensionality reduced data.frame; clust, returned from louvainClust(); adj, Sparse, pruned adjacency matrix; dmat, distance matrix; pca, PCA reduced matrix. sparse, diagnostics on adj prior to applying sparseMarkov().
Wajid Jawaid
## Not run: xx <- goggles(x) plot(xx$l) ## End(Not run)
## Not run: xx <- goggles(x) plot(xx$l) ## End(Not run)
Make markov matrix sparse
sparseMarkov(mkv, knn)
sparseMarkov(mkv, knn)
mkv |
Markov matric |
knn |
Number of nearest neighbours. See above. |
Make markov matrix sparse Choose knn as the maximum number of similar cells are likely to exist in your dataset.
Markovian sparse matrix.
Wajid Jawaid