elynx-tree-0.5.0: Handle phylogenetic trees
Copyright(c) Dominik Schrempf 2020
LicenseGPL-3.0-or-later
Maintainerdominik.schrempf@gmail.com
Stabilityunstable
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

ELynx.Tree.Measurable

Description

Creation date: Thu Jan 17 14:16:34 2019.

Non-negativity of lengths is not completely ensured. See the documentation of Length.

Synopsis

Non-negative length

data Length Source #

Non-negative length.

However, non-negativity is only checked with toLength, and negative values can be obtained using the Num and related instances.

Safe operations with conversion from and to length are roughly 50 percent slower.

benchmarking length/length sum foldl' with safe conversion
time                 110.4 ms   (109.8 ms .. 111.0 ms)
                     1.000 R²   (1.000 R² .. 1.000 R²)
mean                 110.2 ms   (110.0 ms .. 110.6 ms)
std dev              501.8 μs   (359.1 μs .. 730.0 μs)

benchmarking length/length sum foldl' num instance
time                 89.37 ms   (85.13 ms .. 94.27 ms)
                     0.996 R²   (0.992 R² .. 1.000 R²)
mean                 86.53 ms   (85.63 ms .. 88.52 ms)
std dev              2.239 ms   (1.069 ms .. 3.421 ms)

benchmarking length/double sum foldl'
time                 85.47 ms   (84.88 ms .. 86.42 ms)
                     1.000 R²   (0.999 R² .. 1.000 R²)
mean                 85.56 ms   (85.26 ms .. 86.02 ms)
std dev              611.9 μs   (101.5 μs .. 851.7 μs)

Instances

Instances details
Enum Length Source # 
Instance details

Defined in ELynx.Tree.Measurable

Eq Length Source # 
Instance details

Defined in ELynx.Tree.Measurable

Methods

(==) :: Length -> Length -> Bool #

(/=) :: Length -> Length -> Bool #

Floating Length Source # 
Instance details

Defined in ELynx.Tree.Measurable

Fractional Length Source # 
Instance details

Defined in ELynx.Tree.Measurable

Num Length Source # 
Instance details

Defined in ELynx.Tree.Measurable

Ord Length Source # 
Instance details

Defined in ELynx.Tree.Measurable

Read Length Source # 
Instance details

Defined in ELynx.Tree.Measurable

Real Length Source # 
Instance details

Defined in ELynx.Tree.Measurable

RealFloat Length Source # 
Instance details

Defined in ELynx.Tree.Measurable

RealFrac Length Source # 
Instance details

Defined in ELynx.Tree.Measurable

Methods

properFraction :: Integral b => Length -> (b, Length) #

truncate :: Integral b => Length -> b #

round :: Integral b => Length -> b #

ceiling :: Integral b => Length -> b #

floor :: Integral b => Length -> b #

Show Length Source # 
Instance details

Defined in ELynx.Tree.Measurable

Generic Length Source # 
Instance details

Defined in ELynx.Tree.Measurable

Associated Types

type Rep Length :: Type -> Type #

Methods

from :: Length -> Rep Length x #

to :: Rep Length x -> Length #

Semigroup Length Source # 
Instance details

Defined in ELynx.Tree.Measurable

Monoid Length Source # 
Instance details

Defined in ELynx.Tree.Measurable

NFData Length Source # 
Instance details

Defined in ELynx.Tree.Measurable

Methods

rnf :: Length -> () #

ToJSON Length Source # 
Instance details

Defined in ELynx.Tree.Measurable

FromJSON Length Source # 
Instance details

Defined in ELynx.Tree.Measurable

Splittable Length Source # 
Instance details

Defined in ELynx.Tree.Measurable

Methods

split :: Length -> Length Source #

Measurable Length Source # 
Instance details

Defined in ELynx.Tree.Measurable

type Rep Length Source # 
Instance details

Defined in ELynx.Tree.Measurable

type Rep Length = D1 ('MetaData "Length" "ELynx.Tree.Measurable" "elynx-tree-0.5.0-LNeltioHkaNAWvI1l3dP6J" 'True) (C1 ('MetaCons "Length" 'PrefixI 'True) (S1 ('MetaSel ('Just "fromLength") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Double)))

toLength :: Double -> Either String Length Source #

Nothing if length is negative.

toLengthUnsafe :: Double -> Length Source #

Do not check if support value is negative.

checkLength :: Length -> Either String Length Source #

Nothing if length is negative.

class Measurable e where Source #

A data type with measurable and modifiable length.

Methods

getLen :: e -> Length Source #

Get length.

setLen :: Length -> e -> e Source #

Set length.

modLen :: (Length -> Length) -> e -> e Source #

Modify length.

height :: Measurable e => Tree e a -> Length Source #

The maximum distance between origin and leaves.

The height includes the branch length of the stem.

rootHeight :: Measurable e => Tree e a -> Length Source #

The maximum distance between root node and leaves.

Functions on trees

distancesOriginLeaves :: Measurable e => Tree e a -> [Length] Source #

Distances from the origin of a tree to the leaves.

The distances include the branch length of the stem.

totalBranchLength :: Measurable e => Tree e a -> Length Source #

Total branch length of a tree.

normalizeBranchLengths :: Measurable e => Tree e a -> Tree e a Source #

Normalize branch lengths so that the sum is 1.0.

normalizeHeight :: Measurable e => Tree e a -> Tree e a Source #

Normalize height of tree to 1.0.

ultrametric :: Measurable e => Tree e a -> Bool Source #

Check if a tree is ultrametric.

makeUltrametric :: Measurable e => Tree e a -> Tree e a Source #

Elongate terminal branches such that the tree becomes ultrametric.