lineage/gene

Types

Configuration of a gene

pub type Allele =
  String

Maps gene configurations (alleles) found in an individual to a phenotype.

Not all genes can be linked to a single phenotype. In this case the function will return None

pub type Expression =
  fn(List(String)) -> option.Option(String)

Single gene found within a species.

A gene is defgined by its name, chromosomal position, a set of possible alleles (configurations) it can take, and and optional expression rule that determines what phenotype a given set of alleles produce.

Fields

  • name - A human-readable identifier for the gene like “flower color”
  • position - Fixed position of the gene within the genome of the species
  • alleles - The set of valid alleles for this gene.
  • expression- Deduces the phenotype of a given set of alleles. None indicates the gene has no expression or phenotypic effect.
pub type Gene {
  Gene(
    name: String,
    position: GenePosition,
    alleles: set.Set(String),
    expression: option.Option(
      fn(List(String)) -> option.Option(String),
    ),
  )
}

Constructors

Position of gene within the genome of an individual Supported are:

  • Autosomes with autosome number
  • X gonosome
  • Y gonosome
  • Other chromosome types by name
pub type GenePosition {
  Autosome(no: Int, index: Int)
  X(index: Int)
  Y(index: Int)
  Other(name: String, index: Int)
}

Constructors

  • Autosome(no: Int, index: Int)
  • X(index: Int)
  • Y(index: Int)
  • Other(name: String, index: Int)

Values

pub fn decode_gene() -> decode.Decoder(Gene)

Decodes a Gene from a JSON object.

Expects the following fields:

  • "name" — String
  • "position" — Object, decoded via decode_position
  • "alleles" — Array of Strings

The expression field is not decoded and always set to None. To set an expression, use gene.with_expression after decoding.

pub fn encode_gene(gene: Gene) -> json.Json

Encodes a Gene as a JSON object.

The expression field is not encoded. To decode the result back into a Gene, use decode_gene.

Examples

let gene = Gene(
  "seed_colour", Autosome(1, 0), set.from_list(["A", "a"]), option.None
)
encode_gene(gene) |> json.to_string

will yield

{
  "name":"seed_colour",
  "position":{"type":"autosome","no":1,"index":0},
  "alleles":["A","a"]
}
pub fn index(gene: Gene) -> Int

Returns the index of a gene related to the chromosome it is located on

Sometimes the index on the chromosome is more important like the type of chromosome.

Example

index(Gene("name", Autosome(3, 4), set.from_list(["A","b"]), option.None))
// -> 4
pub fn landscape(
  genes: List(Gene),
) -> dict.Dict(GenePosition, Gene)

Transforms a list of genes into a map of positions to gene.

Makes a dict out of the list for convinient indexing, if needed.

Examples

let first = Gene("first", Autosome(3, 4), set.from_list(["A","b"]), option.None)
let second = Gene("sec", Autosome(2, 1), set.from_list(["C","d"]), option.None)
let result = landscape([first, second])
dict.size(result)
// -> 2
dict.get(result, Autosome(3, 4)) == Ok(first)
// -> True
pub fn multi_sample(gene: Gene, amount: Int) -> List(String)

Samples multiple alleles (gene configurations) from a gene.

Creates a list of alleles that can be used for the creation of chromosomes. If the specified amount is zero or less an empty list will be returned. This function is not tail-recursive as ploidity of most species is way below 10.

Examples

let first = Gene("first", Autosome(3, 4), set.from_list(["A","b"]), option.None)
let result = multi_sample(first, 10)
list.size(result)
// -> 10
pub fn sample(gene: Gene) -> String

Returns a random allele (configuration) of a gene.

In the case of an empty gene (which should not exist) the result will be “Unknown”

Examples

let allele = sample(Gene("first", Autosome(3, 4), set.from_list(["A","b"]), option.None))
list.contains(["A", "b", allele)
// -> True
sample(Gene("first", Autosome(3, 4), set.from_list([]), option.None))
// -> "Unknown"
pub fn with_expression(
  gene: Gene,
  expression: option.Option(
    fn(List(String)) -> option.Option(String),
  ),
) -> Gene

Returns a copy of a gene with the given expression rule set.

Examples

let gene = Gene("seed_colour", Autosome(1, 0), set.from_list(["A", "a"]), option.None)
with_expression(gene, option.Some(Dominant))
// -> Gene("seed_colour", Autosome(1, 0), set.from_list(["A", "a"]), option.Some(Dominant))
Search Document