Skip to content

Commit

Permalink
relax type signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasmueboe committed Jun 16, 2024
1 parent 13d50c6 commit 57d82a6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/GridCount.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ end
Caclulate the totalrna as sum of all genes for each pixel.
"""
function totalrna(counts::GridCounts)
function totalrna(counts)
n = length(counts)
x, y, v = Vector{Vector}(undef, n), Vector{Vector}(undef, n), Vector{Vector}(undef, n)

Expand Down
24 changes: 8 additions & 16 deletions src/KDE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ using SparseArrays: AbstractSparseArray, SparseMatrixCSC, nnz, nonzeros, nzrange
"""
gaussiankernel(σ::Real, r::Real)
Generate a gaussian kernel with bandwidth `σ` and radius `r*σ`
Generate a gaussian kernel with bandwidth `σ` and radius `r * σ`
"""
function gaussiankernel::Real, r::Real)
l = ceil(Int, 2r * σ + 1)
Expand Down Expand Up @@ -83,7 +83,7 @@ function chunk_slices(i, step, n, pad)
return slice, reslice
end

function chunk(counts, kernel::OffsetArray, sx=500, sy=500)
function chunk(counts, kernel, sx=500, sy=500)
m, n = size(first(counts))
pad_x = extrema(axes(kernel, 1))
pad_y = extrema(axes(kernel, 2))
Expand Down Expand Up @@ -111,11 +111,7 @@ function chunk(counts, kernel::OffsetArray, sx=500, sy=500)
end

function calculatecosinesim(
counts,
signatures::AbstractMatrix{T},
kernel::AbstractMatrix{T},
unpad::Tuple{AbstractRange,AbstractRange};
log=false,
counts, signatures::AbstractMatrix{T}, kernel::AbstractMatrix{T}, unpad; log=false
) where {T<:Real}
n_celltypes = size(signatures, 1)

Expand Down Expand Up @@ -169,9 +165,7 @@ function smallestuint(n)
end

"""
function assigncelltype(
counts::GridCounts, signatures::AbstractDataFrame, kernel; celltypes=nothing, log=false
)
assigncelltype(counts, signatures, kernel; celltypes=nothing, log=false)
Assign a celltype to each pixel.
Expand All @@ -186,9 +180,7 @@ The `eltype(kernel)` will be used for calculations and `signatures` will be cast
- `log::Bool`: whether to log-transform the KDE. Useful if `signatures` are calculated
from log-transformed gene expression.
"""
function assigncelltype(
counts::GridCounts, signatures::AbstractDataFrame, kernel; celltypes=nothing, log=false
)
function assigncelltype(counts, signatures, kernel; celltypes=nothing, log=false)
if !isnothing(celltypes) && length(celltypes) != nrow(signatures)
error("Length of 'celltypes' must match number of rows in 'signatures'")
end
Expand All @@ -201,17 +193,17 @@ function assigncelltype(
genes = genes[exist]
end

S = eltype(kernel)
T = eltype(kernel)
U = smallestuint(nrow(signatures))

signatures = signatures[!, exist]

signatures = Matrix{S}(signatures)
signatures = Matrix{T}(signatures)

chunked_counts, rowslices, colslices = chunk([counts[g] for g in genes], kernel)
rows, cols = length.(rowslices), length.(colslices)

cosine = BlockArray(undef_blocks, Matrix{S}, rows, cols)
cosine = BlockArray(undef_blocks, Matrix{T}, rows, cols)
celltypemap = BlockArray(undef_blocks, Matrix{U}, rows, cols)

@threads for (i, r) in collect(enumerate(rowslices))
Expand Down
2 changes: 1 addition & 1 deletion src/LocalMax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Load KDE with `kernel` for coordinates at `localmax`.
- `genes=nothing`: vector of genes for which to calculate KDE. If `nothing` all genes are
used.
"""
function getlocalmaxima(counts::GridCounts, localmax, kernel; genes=nothing)
function getlocalmaxima(counts, localmax, kernel; genes=nothing)
if isnothing(genes)
genes = Vector(keys(counts))
else
Expand Down

0 comments on commit 57d82a6

Please sign in to comment.