taxonomy

package
v0.0.0-...-b9741f9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2023 License: BSD-2-Clause Imports: 11 Imported by: 1

Documentation

Overview

Package taxonomy implements a basic taxonomy to be used with GBIF occurrence data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Canon

func Canon(name string) string

Canon transforms a name into its canonical form.

Types

type ErrAmbiguous

type ErrAmbiguous struct {
	Name string

	// The found IDs
	IDs []int64

	Err error
}

An ErrAmbiguous is the error produced when searching for a name that has multiple possible resolutions in GBIF.

func (*ErrAmbiguous) Error

func (e *ErrAmbiguous) Error() string

func (*ErrAmbiguous) Unwrap

func (e *ErrAmbiguous) Unwrap() error

type Rank

type Rank uint

Rank is a linnean rank. Ranks are arranged in a way that an inclusive rank in the taxonomy is always smaller than more exclusive ranks. Then it is possible to use the form:

if rank < taxonomy.Genus {
	// do something
}
const (
	Unranked Rank = iota
	Kingdom
	Phylum
	Class
	Order
	Family
	Genus
	Species
)

Valid taxonomic ranks.

func GetRank

func GetRank(s string) Rank

GetRank returns a rank value from a string.

func (Rank) String

func (r Rank) String() string

String returns the rank string of a rank.

type Taxon

type Taxon struct {
	Name   string // taxon name
	Author string // author of the name
	ID     int64  // ID of the taxon
	Rank   Rank   // taxon rank
	Status string // taxon status
	Parent int64  // ID of the parent taxon
}

A Taxon stores the taxon information.

type Taxonomy

type Taxonomy struct {
	// contains filtered or unexported fields
}

A Taxonomy stores taxon IDs

func NewTaxonomy

func NewTaxonomy() *Taxonomy

NewTaxonomy creates a new empty taxonomy.

func Read

func Read(r io.Reader) (*Taxonomy, error)

Read reads a taxonomy from a TSV-encoded file.

func (*Taxonomy) Accepted

func (tx *Taxonomy) Accepted(id int64) Taxon

Accepted return the accepted taxon from a given ID.

func (*Taxonomy) AcceptedAndRanked

func (tx *Taxonomy) AcceptedAndRanked(id int64) Taxon

AcceptedAndRanked return the accepted and ranked taxon from a given ID.

func (*Taxonomy) AddFromGBIF

func (tx *Taxonomy) AddFromGBIF(id int64, maxRank Rank) error

AddFromGBIF add a taxon from a GBIF ID, as well as all the parents up to the given rank.

Taxa will be added in a temporal space. To formally add the taxa to the taxonomy use the Stage method.

It requires an internet connection.

func (*Taxonomy) AddNameFromGBIF

func (tx *Taxonomy) AddNameFromGBIF(name string, maxRank Rank) error

AddNameFromGBIF search for a taxon name in GBIF as well as all the parents up to the given rank.

If multiple taxons with the indicated name were found it will look for a single accepted name. If there are multiple accepted names, or all the names are synonyms, then it will return an ErrAmbiguous error.

Taxa will be added in a temporal space. To formally add the taxa to the taxonomy use the Stage method.

It requires an internet connection.

func (*Taxonomy) AddSpecies

func (tx *Taxonomy) AddSpecies(sp *gbif.Species)

AddSpecies add a GBIF Species type from an external source.

func (*Taxonomy) ByName

func (tx *Taxonomy) ByName(name string) []int64

ByName returns the IDs of all the taxons with a given name.

func (*Taxonomy) IDs

func (tx *Taxonomy) IDs() []int64

IDs return the ID of all taxons in the taxonomy.

func (*Taxonomy) MinRank

func (tx *Taxonomy) MinRank() Rank

MinRank returns the most inclusive rank found in the taxonomy.

func (*Taxonomy) Rank

func (tx *Taxonomy) Rank(id int64) Rank

Rank returns the first defined rank of a taxon, or any of its parents.

func (*Taxonomy) Stage

func (tx *Taxonomy) Stage()

Stage add the taxa in the temporal space to the taxonomy,

func (*Taxonomy) Taxon

func (tx *Taxonomy) Taxon(id int64) Taxon

Taxon returns a taxon with a given ID.

func (*Taxonomy) Write

func (tx *Taxonomy) Write(w io.Writer) error

Write writes a taxonomy into a TSV table.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL