Skip to content

Commit

Permalink
Metabolites (#125)
Browse files Browse the repository at this point in the history
* add metabolite feature

* remove qualifier

* add docs for Metabolite

* fix doctests for julia 1.7

* add doctests
  • Loading branch information
kescobo authored Dec 15, 2021
1 parent 515c392 commit d78153b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/src/profiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ with the value `missing` in any samples that do not have that field set.

```jldoctest profiles
julia> metadata(comm)
3-element Vector{NamedTuple{(:sample, :subject), T} where T<:Tuple}:
3-element Vector{NamedTuple{(:sample, :subject)}}:
(sample = "s1", subject = "kevin")
(sample = "s2", subject = "anika")
(sample = "s3", subject = missing)
Expand All @@ -310,7 +310,7 @@ julia> md2 = [(name="s1", other="Hello, World!"), (name="s2", other="Goodbye!")]
julia> insert!(comm, md2; namecol=:name)
julia> metadata(comm)
3-element Vector{NamedTuple{(:sample, :subject, :foo, :other), T} where T<:Tuple}:
3-element Vector{NamedTuple{(:sample, :subject, :foo, :other)}}:
(sample = "s1", subject = "kevin", foo = "bar", other = "Hello, World!")
(sample = "s2", subject = "anika", foo = missing, other = "Goodbye!")
(sample = "s3", subject = "annelle", foo = "baz", other = missing)
Expand Down
37 changes: 34 additions & 3 deletions docs/src/samples_features.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ MicrobiomeSample("sample3", {:age = 23, :gender = "nonbinary", :genotype = "XY",
## Feature Types

`AbstractFeature` types also have a `name`, but other fields are optional.
`Microbiome.jl` defines two concrete `AbstractFeature` types, [`Taxon`](@ref) and [`GeneFunction`](@ref).
`Microbiome.jl` defines three concrete `AbstractFeature` types,
[`Taxon`](@ref), [`GeneFunction`](@ref), and [`Metabolite`](@ref).


### Taxon
Expand Down Expand Up @@ -135,8 +136,6 @@ julia> String(ecoli) |> taxon
Taxon("Escherichia_coli", :species)
```



### GeneFunction

The [`GeneFunction`](@ref) type contains a name and (optionally) a [`Taxon`](@ref).
Expand Down Expand Up @@ -195,6 +194,31 @@ GeneFunction("gene2", Taxon("Species_name", :species))
```


### Metabolites

The [`Metabolite`](@ref) type has a `name` and optionally
a `commonname`, a mass / charge ratio (`mz`), and retention time (`rt`).


```jldoctest
julia> m = Metabolite("name", "common", 1., 2.)
Metabolite("name", "common", 1.0, 2.0)
julia> name(m)
"name"
julia> commonname(m)
"common"
julia> masscharge(m)
1.0
julia> retentiontime(m)
2.0
julia> m2 = Metabolite("other name")
Metabolite("other name", missing, missing, missing)
```

## Types and Methods

Expand All @@ -214,4 +238,11 @@ taxon
```@docs
GeneFunction
genefunction
```

```@docs
Metabolite
commonname
masscharge
retentiontime
```
31 changes: 31 additions & 0 deletions src/features.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ end

Base.string(f::AbstractFeature) = String(f)

"""
Metabolite(name::String, commonname::Union{Missing, String}, mz::Union{Missing, Float64}, rt::Union{Missing, Float64}) <: AbstractFeature
Metabolite(name::String)
Represents a small-molecule metabolite coming from an LCMS.
The fields are
- `name`: required, this should be a unique identifier
- `commonname`: might refer to a chemical name like "proprionate"
- `mz`: The mass/charge ratio
- `rt`: The retention time
"""
struct Metabolite <: AbstractFeature
name::String
commonname::Union{Missing, String}
Expand All @@ -192,8 +204,27 @@ end
Metabolite(n::AbstractString) = Metabolite(n, missing, missing, missing)

name(m::Metabolite) = m.name

"""
commonname(m::Metabolite)
Accessor function for the `commonname` field of a [`Metabolite`](@ref).
"""
commonname(m::Metabolite) = m.commonname


"""
masscharge(m::Metabolite)
Accessor function for the `mz` field of a [`Metabolite`](@ref).
"""
masscharge(m::Metabolite) = m.mz

"""
retentiontime(m::Metabolite)
Accessor function for the `rt` field of a [`Metabolite`](@ref).
"""
retentiontime(m::Metabolite) = m.rt

@testset "Metabolites" begin
Expand Down

0 comments on commit d78153b

Please sign in to comment.