Skip to content

Commit 39b6be2

Browse files
committed
removed ImageMorphopolgy requirement
1 parent 496d695 commit 39b6be2

File tree

5 files changed

+42
-20
lines changed

5 files changed

+42
-20
lines changed

Project.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
name = "ClusterDepth"
22
uuid = "c8d8bbfa-f476-4995-adff-2987f04015d1"
33
authors = ["Benedikt V. Ehinger", "Maanik Marathe"]
4-
version = "0.2.0"
4+
version = "0.2.1"
55

66
[deps]
7-
ImageMorphology = "787d08f9-d448-5407-9aad-5290dd7ab264"
87
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
98
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
109
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
1110

1211
[compat]
13-
ImageMorphology = "0.4"
1412
Random = "1"
1513
SparseArrays = "1"
1614
StatsBase = "0.33, 0.34"

src/ClusterDepth.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module ClusterDepth
22

33
using Random
4-
using ImageMorphology
4+
#using ImageMorphology
55
using SparseArrays
66
#using ExtendableSparse
77
using StatsBase

src/cluster.jl

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""
22
3+
using Base: Stateful
34
clusterdepth(rng,data::AbstractArray;τ=2.3, statfun=x->abs.(studentt(x)),permfun=sign_permute!,nperm=5000,pval_type=:troendle)
45
56
calculate clusterdepth of given datamatrix.
@@ -186,7 +187,7 @@ function calc_clusterdepth(d0, τ)
186187
end
187188

188189
maxL = 1 + maximum(len) # go up only to max-depth
189-
190+
# @debug maxL
190191
valCol_head = Vector{Float64}(undef, maxL)
191192
valCol_tail = Vector{Float64}(undef, maxL)
192193

@@ -217,25 +218,38 @@ if the first and last cluster start on the first/last sample, we dont know their
217218
218219
Input is assumed to be a thresholded Array with only 0/1
219220
"""
220-
function cluster(data)
221-
label = label_components(Matrix(data))
222-
K = maximum(label)
223-
start = fill(0, K)
224-
stop = fill(0, K)
225-
for k = 1:K
226-
#length[k] = sum(label.==k)
227-
start[k] = findfirst(==(k), label)
228-
stop[k] = findlast(==(k), label)
221+
function cluster(data::BitVector)
222+
229223

224+
start = []
225+
stop = []
226+
227+
state = false
228+
for i in eachindex(data)
229+
if data[i] == 1
230+
if !state
231+
append!(start, i)
232+
state = true
233+
end
234+
else
235+
if state
236+
append!(stop, i - 1)
237+
state = false
238+
end
239+
end
230240

231241
end
232-
len = stop .- start
242+
243+
244+
245+
233246

234247
# if the first and last cluster start on the first/last sample, we dont know their real depth
235-
if length(start) > 0 && start[end] + len[end] == length(data)
248+
if length(start) == length(stop) + 1
236249
start = start[1:end-1]
237-
len = len[1:end-1]
238250
end
251+
len = stop .- start
252+
239253
if length(start) > 0 && start[1] == 1
240254
start = start[2:end]
241255
len = len[2:end]

test/cluster.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
@testset "cluster" begin
22
s, l = ClusterDepth.cluster(
3-
[4.0 0.0 10.0 0.0 3.0 4.0 0 4.0 4.0 0.0 0.0 5.0] .> 0.9,
3+
[4.0, 0.0, 10.0, 0.0, 3.0, 4.0, 0, 4.0, 4.0, 0.0, 0.0, 5.0] .> 0.9,
44
)
5+
56
@test s == [3, 5, 8]
67
@test l == [0, 1, 1]
78

8-
s, l = ClusterDepth.cluster([0.0 0.0 0.0 0.0] .> 0.9)
9+
s, l = ClusterDepth.cluster([0.0, 0.0, 0.0, 0.0] .> 0.9)
910
@test s == []
1011
@test l == []
12+
13+
14+
s, l = ClusterDepth.cluster(
15+
[4.0, 0.0, 10.0, 0.0, 3.0, 4.0, 0, 4.0, 4.0] .> 0.9,
16+
)
17+
@test s == [3, 5]
18+
@test l == [0, 1]
1119
end
1220

1321
@testset "Tests for 2D data" begin

test/pvals.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
[0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 1.0, 0.0, 0.0],
2323
cdm,
2424
0.1,
25-
type = :naive,
25+
type=:naive,
2626
)
2727
@test p[7] 1 / 1001
2828

@@ -55,6 +55,8 @@
5555
p = ClusterDepth.pvals([0.0, 1.0, 2.0, 3.0, 4.0, 5.1, 2.0, 0], (cdm, cdm), 0.9)
5656
@test all((p .> 0.05) .== [1, 1, 1, 0, 0, 0, 1, 1])
5757

58+
start, len = ClusterDepth.cluster([0.0, 1.0, 2.0, 3.0, 4.0, 5.1, 2.0, 0] .> 0.9) # get observed clusters
59+
5860

5961
p = ClusterDepth.pvals([0.0, 1.0, 2.0, 3.0, 4.0, 2.0, 1.0, 0.0, 6], (cdm, cdm), 0.9)
6062
@test all((p .> 0.05) .== [1, 1, 1, 0, 0, 1, 1, 1, 1])

0 commit comments

Comments
 (0)