Skip to content

Commit

Permalink
compute tail and head radius ratio, which could be an important metri…
Browse files Browse the repository at this point in the history
…c to identify spine
  • Loading branch information
jingpengw committed Nov 2, 2017
1 parent c493411 commit 8af50c0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/BranchNets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,20 @@ end
function load_swc( fileName::AbstractString )
swcString = readstring( fileName )
BranchNet( swcString )
end

function load_gzip_swc( fileName::AbstractString )
swc = SWCs.load_gzip_swc( fileName )
BranchNet( swc )
end

function save(self::BranchNet, fileName)
function save(self::BranchNet, fileName::AbstractString)
swc = SWC(self)
SWCs.save( swc, fileName )
end

function save_gzip_swc( self::BranchNet, fileName::AbstractString )
SWCs.save_gzip_swc( SWCs.SWC(self), fileName )
end

####################### properties ##############
Expand Down Expand Up @@ -435,6 +444,9 @@ end


############################### Base functions ###################################
function Base.getindex(self::BranchNet, index::Integer)
get_branch_list(self)[index]
end
"""
merge two nets at a specific branch location.
the root node of second net will be connected to the first net
Expand Down
19 changes: 19 additions & 0 deletions src/Branches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,28 @@ function get_path_length(self::Branch)
ret += norm( [map((x,y)-> x-y, self[i][1:3], self[i-1][1:3] )...] )
end
ret
end

function get_radius_list( self::Branch ) map(n->n[4], self) end

"""
get_tail_head_radius_ratio( self::Branch )
the spine is normally thick in tail, and thin in the head.
The head should point to dendrite. This is a very good feature to identify spine.
"""
function get_tail_head_radius_ratio( self::Branch )
radiusList = get_radius_list( self )
N = length(self)
headRadiusList = radiusList[1:cld(N,2)]
tailRadiusList = radiusList[cld(N,2):N]
maximum(tailRadiusList) / minimum(headRadiusList)
end

###################### Base functions ################
function Base.start( self::Branch ) 1 end
function Base.next( self::Branch, state::Integer ) get_node_list(self)[state], state+1 end
function Base.done( self::Branch, state::Integer ) state > length(self) end

function Base.endof(self::Branch) length(self) end
function Base.isempty(self::Branch) isempty(self.nodeList) end

Expand Down
15 changes: 15 additions & 0 deletions test/Branches.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using RealNeuralNetworks
using RealNeuralNetworks.BranchNets
using RealNeuralNetworks.BranchNets.Branches
using Base.Test


@testset "test Branches" begin
# construct a branch
branchNet = BranchNets.load_gzip_swc("../assert/76869.swc.gz")
# get a random branch
branch = branchNet[5]

println("get tail head radius ratio ...")
@time Branches.get_tail_head_radius_ratio( branch )
end

0 comments on commit 8af50c0

Please sign in to comment.