Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
sirplus
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BioCellGen-public
sirplus
Commits
e0b2901c
Commit
e0b2901c
authored
8 years ago
by
Luke Zappia
Browse files
Options
Downloads
Patches
Plain Diff
Add simulateGeneMeans function
parent
7d31532f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
DESCRIPTION
+1
-1
1 addition, 1 deletion
DESCRIPTION
NAMESPACE
+2
-2
2 additions, 2 deletions
NAMESPACE
R/simulate.R
+57
-1
57 additions, 1 deletion
R/simulate.R
man/getLNormFactors.Rd
+30
-0
30 additions, 0 deletions
man/getLNormFactors.Rd
with
90 additions
and
4 deletions
DESCRIPTION
+
1
−
1
View file @
e0b2901c
Package: splatter
Package: splatter
Type: Package
Type: Package
Title: Simple Simulation of Single-cell RNA Sequencing Data
Title: Simple Simulation of Single-cell RNA Sequencing Data
Version: 0.3.
2
Version: 0.3.
3
Date: 2016-10-09
Date: 2016-10-09
Author: Luke Zappia
Author: Luke Zappia
Authors@R: as.person(c(
Authors@R: as.person(c(
...
...
This diff is collapsed.
Click to expand it.
NAMESPACE
+
2
−
2
View file @
e0b2901c
...
@@ -10,8 +10,8 @@ export(getParams)
...
@@ -10,8 +10,8 @@ export(getParams)
export(mergeParams)
export(mergeParams)
export(setParams)
export(setParams)
export(splatParams)
export(splatParams)
importFrom(Bio
B
ase,fData)
importFrom(Bio
b
ase,fData)
importFrom(Bio
B
ase,pData)
importFrom(Bio
b
ase,pData)
importFrom(scater,counts)
importFrom(scater,counts)
importFrom(scater,newSCESet)
importFrom(scater,newSCESet)
importFrom(stats,dnbinom)
importFrom(stats,dnbinom)
...
...
This diff is collapsed.
Click to expand it.
R/simulate.R
+
57
−
1
View file @
e0b2901c
...
@@ -30,7 +30,7 @@
...
@@ -30,7 +30,7 @@
#' @return RETURN DESCRIPTION
#' @return RETURN DESCRIPTION
#' @examples
#' @examples
#' # ADD EXAMPLES HERE
#' # ADD EXAMPLES HERE
#' @importFrom Bio
B
ase pData fData
#' @importFrom Bio
b
ase pData fData
#' @importFrom scater newSCESet counts
#' @importFrom scater newSCESet counts
splat
<-
function
(
params
=
defaultParams
(),
method
=
c
(
"groups"
,
"paths"
),
splat
<-
function
(
params
=
defaultParams
(),
method
=
c
(
"groups"
,
"paths"
),
add.assay
=
TRUE
,
verbose
=
TRUE
,
...
)
{
add.assay
=
TRUE
,
verbose
=
TRUE
,
...
)
{
...
@@ -69,10 +69,66 @@ splat <- function(params = defaultParams(), method = c("groups", "paths"),
...
@@ -69,10 +69,66 @@ splat <- function(params = defaultParams(), method = c("groups", "paths"),
groups
<-
unlist
(
groups
)
groups
<-
unlist
(
groups
)
pData
(
sim
)
$
Group
<-
group.names
[
groups
]
pData
(
sim
)
$
Group
<-
group.names
[
groups
]
sim
<-
simulateGeneMeans
(
sim
,
params
)
# Create new SCESet to make sure values are calculated correctly
# Create new SCESet to make sure values are calculated correctly
sce
<-
newSCESet
(
countData
=
counts
(
sim
),
sce
<-
newSCESet
(
countData
=
counts
(
sim
),
phenoData
=
new
(
"AnnotatedDataFrame"
,
data
=
pData
(
sim
)),
phenoData
=
new
(
"AnnotatedDataFrame"
,
data
=
pData
(
sim
)),
featureData
=
new
(
"AnnotatedDataFrame"
,
data
=
fData
(
sim
)))
featureData
=
new
(
"AnnotatedDataFrame"
,
data
=
fData
(
sim
)))
return
(
sce
)
return
(
sce
)
}
simulateGeneMeans
<-
function
(
sim
,
params
)
{
n.genes
<-
getParams
(
params
,
"nGenes"
)
mean.shape
<-
getParams
(
params
,
"mean.shape"
)
mean.rate
<-
getParams
(
params
,
"mean.rate"
)
out.prob
<-
getParams
(
params
,
"out.prob"
)
out.loProb
<-
getParams
(
params
,
"out.loProb"
)
out.facLoc
<-
getParams
(
params
,
"out.facLoc"
)
out.facScale
<-
getParams
(
params
,
"out.facScale"
)
# Simulate base gene means
base.means.gene
<-
rgamma
(
n.genes
,
shape
=
mean.shape
,
rate
=
mean.rate
)
# Add expression outliers
outlier.facs
<-
getLNormFactors
(
n.genes
,
out.prob
,
out.loProb
,
out.facLoc
,
out.facScale
)
means.gene
<-
base.means.gene
*
outlier.facs
fData
(
sim
)
$
BaseGeneMean
<-
base.means.gene
fData
(
sim
)
$
OutlierFactor
<-
outlier.facs
fData
(
sim
)
$
GeneMean
<-
means.gene
return
(
sim
)
}
#' Get log-normal factors
#'
#' Randomly generate multiplication factors from a log-normal distribution.
#'
#' @param n.facs Number of factors to generate.
#' @param sel.prob Probability that a factor will be selected to be different
#' from 1.
#' @param neg.prob Probability that a selected factor is less than one.
#' @param fac.loc Location parameter for the log-normal distribution.
#' @param fac.scale Scale factor for the log-normal distribution.
#'
#' @return Vector containing generated factors.
#' @examples
#' factors <- getLNormFactors(100, 0.5, 0.5, 4, 1)
getLNormFactors
<-
function
(
n.facs
,
sel.prob
,
neg.prob
,
fac.loc
,
fac.scale
)
{
is.selected
<-
as.logical
(
rbinom
(
n.facs
,
1
,
sel.prob
))
n.selected
<-
sum
(
is.selected
)
dir.selected
<-
(
-1
)
^
rbinom
(
n.selected
,
1
,
neg.prob
)
facs.selected
<-
rlnorm
(
n.selected
,
fac.loc
,
fac.scale
)
# Reverse directions for factors that are less than one
dir.selected
[
facs.selected
<
1
&
dir.selected
==
-1
]
<-
1
dir.selected
[
facs.selected
<
1
&
dir.selected
==
1
]
<-
-1
factors
<-
rep
(
1
,
n.facs
)
factors
[
is.selected
]
<-
facs.selected
^
dir.selected
return
(
factors
)
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
man/getLNormFactors.Rd
0 → 100644
+
30
−
0
View file @
e0b2901c
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/simulate.R
\name{getLNormFactors}
\alias{getLNormFactors}
\title{Get log-normal factors}
\usage{
getLNormFactors(n.facs, sel.prob, neg.prob, fac.loc, fac.scale)
}
\arguments{
\item{n.facs}{Number of factors to generate.}
\item{sel.prob}{Probability that a factor will be selected to be different
from 1.}
\item{neg.prob}{Probability that a selected factor is less than one.}
\item{fac.loc}{Location parameter for the log-normal distribution.}
\item{fac.scale}{Scale factor for the log-normal distribution.}
}
\value{
Vector containing generated factors.
}
\description{
Randomly generate multiplication factors from a log-normal distribution.
}
\examples{
factors <- getLNormFactors(100, 0.5, 0.5, 4, 1)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment