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
c695d501
Commit
c695d501
authored
8 years ago
by
Luke Zappia
Browse files
Options
Downloads
Patches
Plain Diff
Add checkParams function
parent
504b1d0b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
NAMESPACE
+1
-0
1 addition, 0 deletions
NAMESPACE
R/params.R
+105
-2
105 additions, 2 deletions
R/params.R
man/checkParams.Rd
+35
-0
35 additions, 0 deletions
man/checkParams.Rd
with
141 additions
and
2 deletions
NAMESPACE
+
1
−
0
View file @
c695d501
# Generated by roxygen2: do not edit by hand
S3method(print,splatParams)
export(checkParams)
export(defaultParams)
export(mergeParams)
export(splatParams)
...
...
This diff is collapsed.
Click to expand it.
R/params.R
+
105
−
2
View file @
c695d501
...
...
@@ -157,6 +157,109 @@ print.splatParams <- function(x, ...) {
}
}
#' Check splatParams object
#'
#' Check that a splatParams object has valid parameter values.
#'
#' @param params splatParams object to check
#'
#' @details
#' The following checks are made:
#' \itemize{
#' \item{Input has "splatParams" class}
#' \item{Logical parameters are logical}
#' \item{Numeric parameters are numeric}
#' \item{Positive numeric parameters are positive}
#' \item{Integer parameters are integers}
#' \item{Probability parameters are in the range 0-1}
#' \item{Vector parameters are the correct length}
#' \item{Vector parameters do not contain NAs}
#' \item{Non-vector parameters are single values}
#' }
#'
#' @return Produces error if not valid otherwise nothing
#' @examples
#' checkParams(defaultParams())
#' @export
checkParams
<-
function
(
params
)
{
# Check class before anything else
if
(
!
(
"splatParams"
%in%
class
(
params
)))
{
stop
(
"params does not belong to the splatParams class"
)
}
# Define what values each parameter can take
# NUM = Numeric
# POS = Positive numeric
# INT = Positive integer
# PROB = Positive numeric in range 0-1
# LOG = Logical
types
<-
c
(
nGenes
=
"INT"
,
nCells
=
"INT"
,
groupCells
=
"INT"
,
mean.rate
=
"POS"
,
mean.shape
=
"POS"
,
lib.loc
=
"NUM"
,
lib.scale
=
"POS"
,
out.prob
=
"PROB"
,
out.loProb
=
"PROB"
,
out.facLoc
=
"NUM"
,
out.facScale
=
"POS"
,
de.prob
=
"PROB"
,
de.downProb
=
"PROB"
,
de.facLoc
=
"NUM"
,
de.facScale
=
"POS"
,
bcv.common
=
"POS"
,
bcv.DF
=
"POS"
,
dropout.present
=
"LOG"
,
dropout.mid
=
"NUM"
,
dropout.shape
=
"NUM"
,
path.from
=
"INT"
,
path.length
=
"INT"
,
path.skew
=
"PROB"
,
path.nonlinearProb
=
"PROB"
,
path.sigmaFac
=
"POS"
)
# Define which parameters are allowed to be vectors
vectors
<-
c
(
"groupCells"
,
"path.from"
,
"path.length"
,
"path.skew"
)
n.groups
<-
length
(
params
$
groupCells
)
for
(
idx
in
seq_along
(
types
))
{
name
<-
names
(
types
)[
idx
]
name.split
<-
strsplit
(
name
,
"."
,
fixed
=
TRUE
)[[
1
]]
type
<-
types
[
idx
]
if
(
length
(
name.split
)
==
1
)
{
value
<-
params
[[
name
]]
}
else
{
value
<-
params
[[
name.split
[
1
]]][[
name.split
[
2
]]]
}
# Check vector properties first so we can exclude vectors with an NA
# before the next section
if
(
length
(
value
)
>
1
)
{
if
(
name
%in%
vectors
)
{
if
(
any
(
is.na
(
value
)))
{
stop
(
name
,
" is a vector and contains NA values"
)
}
else
if
(
length
(
value
)
!=
n.groups
)
{
stop
(
"length of "
,
name
,
" must be 1 or the length of "
,
"the groupCells parameter"
)
}
}
else
{
stop
(
name
,
" should be a single value"
)
}
}
# Missing values are allowed so we skip anything that is not NA
if
(
!
all
(
is.na
(
value
)))
{
if
(
type
%in%
c
(
"NUM"
,
"INT"
,
"POS"
,
"PROB"
)
&&
!
(
is.numeric
(
value
)))
{
stop
(
name
,
" must be numeric"
)
}
if
(
type
%in%
c
(
"INT"
,
"POS"
,
"PROB"
)
&&
value
<
0
)
{
stop
(
name
,
" must be positive"
)
}
if
(
type
==
"INT"
&&
value
%%
1
!=
0
)
{
stop
(
name
,
" must be an integer"
)
}
if
(
type
==
"PROB"
&&
(
value
<
0
||
value
>
1
))
{
stop
(
paste
(
name
,
"must be in the range 0-1"
))
}
if
(
type
==
"LOG"
&&
!
(
is.logical
(
value
)))
{
stop
(
name
,
" must be logical (TRUE/FALSE)"
)
}
}
}
}
#' Update a splatParams object
#'
#' Update any of the parameters in a splatParams object to have a new value.
...
...
@@ -199,9 +302,9 @@ updateParams <- function(params, ...) {
update.name
<-
update.names
[[
idx
]]
value
<-
update
[[
idx
]]
if
(
length
(
update.name
)
==
1
)
{
params
[
update.name
]
<-
value
params
[
[
update.name
]
]
<-
value
}
else
{
params
[[
update.name
[
1
]]][
update.name
[
2
]]
<-
value
params
[[
update.name
[
1
]]][
[
update.name
[
2
]]
]
<-
value
}
}
...
...
This diff is collapsed.
Click to expand it.
man/checkParams.Rd
0 → 100644
+
35
−
0
View file @
c695d501
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/params.R
\name{checkParams}
\alias{checkParams}
\title{Check splatParams object}
\usage{
checkParams(params)
}
\arguments{
\item{params}{splatParams object to check}
}
\value{
Produces error if not valid otherwise nothing
}
\description{
Check that a splatParams object has valid parameter values.
}
\details{
The following checks are made:
\itemize{
\item{Input has "splatParams" class}
\item{Logical parameters are logical}
\item{Numeric parameters are numeric}
\item{Positive numeric parameters are positive}
\item{Integer parameters are integers}
\item{Probability parameters are in the range 0-1}
\item{Vector parameters are the correct length}
\item{Vector parameters do not contain NAs}
\item{Non-vector parameters are single values}
}
}
\examples{
checkParams(defaultParams())
}
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