Skip to content

Commit 9602681

Browse files
authored
Merge pull request #65 from banhbio/dev
Dev
2 parents 3a89067 + d8a08a9 commit 9602681

2 files changed

Lines changed: 59 additions & 3 deletions

File tree

src/lineage.jl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,26 @@ This function is useful for converting `Lineage` to `DataFrame`, for example.
281281
# Arguments
282282
283283
* `fill_by_missing::Bool = false` - If `true`, fills missing instead of `UnclassifiedTaxon`.
284+
285+
# Examples
286+
287+
```jldoctest
288+
julia> ranks = [:domain, :phylum, :class, :order, :family, :genus, :species];
289+
290+
julia> lineage = reformat(Lineage(Taxon(9606)), ranks);
291+
292+
julia> nt = namedtuple(lineage);
293+
294+
julia> nt.species
295+
9606 [species] Homo sapiens
296+
297+
julia> incomplete = reformat(Lineage(Taxon(9443)), ranks);
298+
299+
julia> nt = namedtuple(incomplete; fill_by_missing=true);
300+
301+
julia> ismissing(nt.species)
302+
true
303+
```
284304
"""
285305
function namedtuple(l::Lineage; fill_by_missing::Bool=false)
286306
ranks = l.ranks
@@ -304,6 +324,23 @@ Print a formatted representation of the lineage to the given `IO` object.
304324
* `delim::AbstractString = ";"` - The delimiter between taxon fields.
305325
* `fill::Bool = false` - If `true`, prints `UnclassifiedTaxon`. only availavle when skip is false.
306326
* `skip::Bool = false` - If `true`, skip printing `UnclassifiedTaxon` and delimiter.
327+
328+
# Examples
329+
330+
```jldoctest
331+
julia> ranks = [:domain, :phylum, :class, :order, :family, :genus, :species];
332+
333+
julia> lineage = reformat(Lineage(Taxon(9443)), ranks);
334+
335+
julia> sprint(io -> print_lineage(io, lineage))
336+
"Eukaryota;Chordata;Mammalia;Primates;;;"
337+
338+
julia> sprint(io -> print_lineage(io, lineage; skip=true))
339+
"Eukaryota;Chordata;Mammalia;Primates"
340+
341+
julia> sprint(io -> print_lineage(io, lineage; fill=true))
342+
"Eukaryota;Chordata;Mammalia;Primates;unclassified Primates family;unclassified Primates genus;unclassified Primates species"
343+
```
307344
"""
308345
function print_lineage(io::IO, lineage::Lineage; delim::AbstractString=";", fill::Bool=false, skip::Bool=false)
309346
taxa = collect(lineage)

src/rank.jl

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ Return `CanonicalRank(sym)` if sym is in `CanonicalRanks`. Return `UnCanonicalRa
3636
`CanonicalRank(sym)` can be used for `isless` comparison.
3737
`:domain`, `:superkingdom`, and `:realm` are treated as the same top-rank
3838
level.
39+
40+
# Examples
41+
42+
```jldoctest
43+
julia> Rank(:species) isa Taxonomy.CanonicalRank
44+
true
45+
46+
julia> Rank(:clade) isa Taxonomy.UnCanonicalRank
47+
true
48+
```
3949
"""
4050
Rank
4151

@@ -71,6 +81,13 @@ Return `CanonicalRank` made from `rank(taxon)` if `rank(taxon)` is in `Canonical
7181
`CanonicalRank(taxon)` can be used for `isless` comparison.
7282
`:domain`, `:superkingdom`, and `:realm` can all be handled as canonical
7383
aliases for the same top-rank level.
84+
85+
# Examples
86+
87+
```jldoctest
88+
julia> Rank(Taxon(9606)) isa Taxonomy.CanonicalRank
89+
true
90+
```
7491
"""
7592
Rank(taxon::AbstractTaxon) = rank(taxon) |> Rank
7693

@@ -86,11 +103,13 @@ Base.show(io::IO, r::Rank) = print(io, String(rank(r)))
86103
"""
87104
isless(taxon::AbstractTaxon, rank::CanonicalRank)
88105
89-
Example
90-
```julia
91-
julia> Taxon(9606 , db) < Rank(:genus)
106+
# Examples
107+
108+
```jldoctest
109+
julia> Taxon(9606) < Rank(:genus)
92110
true
93111
```
112+
94113
Return `true` if the rank of the former `Taxon` is less than the later rank.
95114
"""
96115
Base.isless(x1::CanonicalRank, x2::CanonicalRank) = isless(Integer(x1), Integer(x2))

0 commit comments

Comments
 (0)