Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix print_lineage internal #27

Merged
merged 3 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions docs/src/man/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Load the package
julia> using Taxonomy

# Construct a Taxonomy.DB objext from the path to each file
# Construct a Taxonomy.DB object from the path to each file
julia> db = Taxonomy.DB("db/nodes.dmp","db/names.dmp")
Taxonomy.DB("db/nodes.dmp","db/names.dmp")

Expand Down Expand Up @@ -67,7 +67,7 @@ julia> collect(AbastractTrees.PreOrderDFS(human))
741158 [subspecies] Homo sapiens subsp. 'Denisova'
63221 [subspecies] Homo sapiens neanderthalensis

# print subtree
# Print subtree
julia> print_tree(Taxon(9604))
9604 [family] Hominidae
├─ 2922387 [no rank] unclassified Hominidae
Expand Down
2 changes: 1 addition & 1 deletion src/DataAPI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ struct Until{T <: Union{Int, Symbol}}
last::T
end

Until(x::AbstractString) = Until(Symbol(x))
Until(x::AbstractString) = Until(Symbol(x))
2 changes: 1 addition & 1 deletion src/Taxonomy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ include("rank.jl")
include("lineage.jl")
include("lca.jl")

end
end
2 changes: 1 addition & 1 deletion src/lca.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ end
function lca(taxa::Taxon...)
l = getindex(Taxon, taxa...)
return lca(l)
end
end
27 changes: 8 additions & 19 deletions src/lineage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ This function is useful for converting `Lineage` to `DataFrame`, for example.
function namedtuple(l::Lineage; fill_by_missing::Bool=false)
ranks = first.(collect(l.index))
values = getindex.(Ref(l), ranks)

if fill_by_missing
values = map(values) do val
val isa UnclassifiedTaxon ? missing : val
Expand All @@ -196,28 +195,18 @@ Print a formatted representation of the lineage to the given `IO` object.
* `skip::Bool = false` - If `true`, skip printing `UnclassifiedTaxon` and delimiter.
"""
function print_lineage(io::IO, lineage::Lineage; delim::AbstractString=";", fill::Bool=false, skip::Bool=false)
name_line = String[]
for taxon in lineage
if typeof(taxon) == UnclassifiedTaxon
if skip
continue
end
taxa = collect(lineage)
skip && filter!(taxon -> !(taxon isa UnclassifiedTaxon), taxa)

if fill
push!(name_line, name(taxon))
else
push!(name_line, "")
end
names = map(taxa) do taxon
if taxon isa UnclassifiedTaxon
fill ? name(taxon) : ""
else
push!(name_line, name(taxon))
name(taxon)
end
end

if isempty(name_line)
return nothing
end

l = foldl((x,y) -> x*delim*y, name_line)
l = join(names, delim)
print(io, l)
return nothing
end
Expand All @@ -240,4 +229,4 @@ AbstractTrees.isdescendant(descendant::Taxon, ancestor::Taxon) = ancestor in Lin

Return `true` if the former taxon is an ancestor of the latter taxon.
"""
isancestor(ancestor::Taxon, descendant::Taxon) = AbstractTrees.isdescendant(descendant, ancestor)
isancestor(ancestor::Taxon, descendant::Taxon) = AbstractTrees.isdescendant(descendant, ancestor)
2 changes: 1 addition & 1 deletion src/rank.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ function Base.isless(x1::AbstractTaxon, x2::CanonicalRank)
end
end

Base.:<=(x1::AbstractTaxon, x2::CanonicalRank) = Rank(x1) == x2 ? true : x1 < x2
Base.:<=(x1::AbstractTaxon, x2::CanonicalRank) = Rank(x1) == x2 ? true : x1 < x2
2 changes: 1 addition & 1 deletion src/taxon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,4 @@ Base.show(io::IO, taxon::UnclassifiedTaxon) = print(io, "Unclassified [$(rank(ta
rank(taxon::UnclassifiedTaxon) = taxon.rank
name(taxon::UnclassifiedTaxon) = taxon.name

source(taxon::UnclassifiedTaxon) = taxon.source
source(taxon::UnclassifiedTaxon) = taxon.source