Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions src/preprocess/scale.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"""
scale(p; kwargs...)
scale(X; kwargs...)

Scale each gene to zero mean and unit variance.

# Arguments

- `p::AnnotatedProfile`: The profile object to calculate on.
- `X::AbstractMatrix`: The count matrix to calculate on.

# Common Keyword arguments

- `max_value::Float64`: Clip to this value after scaling.

# Example

See also [`scale!`](@ref) for inplace operation.
"""
function scale end

"""
scale!(p; kwargs...)
scale!(X; kwargs...)

Scale each gene to zero mean and unit variance.

# Arguments

- `p::AnnotatedProfile`: The profile object to calculate on.
- `X::AbstractMatrix`: The count matrix to calculate on.

# Common Keyword arguments

- `max_value::Float64`: Clip to this value after scaling.

# Example

See also [`scale`](@ref) for non-inplace operation.
"""
function scale! end


scale(p::AnnotatedProfile; kwargs...) = scale!(copy(p); kwargs...)

function scale!(p::AnnotatedProfile; max_value=nothing)
@info "Scaling each gene:"
X = p.RNA.count
X = mapcols!(zscore, X)

if max_value !== nothing
@info "Clipping at max_value $(max_value)"
X[X.>=max_value] .= max_value

return p
end

function scale!(X::AbstractMatrix; max_value=nothing)
@info "Scaling each gene:"
X = mapcols!(zscore, X)

if max_value !== nothing
@info "Clipping at max_value $(max_value)"
X[X.>=max_value] .= max_value

return X
end

function scale(X::AbstractMatrix; max_value=nothing)
@info "Scaling each gene:"
X = mapcols(zscore, X)

if max_value !== nothing
@info "Clipping at max_value $(max_value)"
X[X.>=max_value] .= max_value

return X
end