Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Equidea\Engine\Horse;
- /**
- * An object representation of a full horse color genome.
- *
- * A genome contains many different locuses, which are the places for genetic information
- * about color mutations and manipulation of molecules such as eumelanin and pheomelanin.
- *
- * It provides methods for most common operations and supports JSON type array input
- * for allele locuses.
- *
- * @see https://en.wikipedia.org/wiki/Equine_coat_color_genetics
- *
- * @author Lisa Saalfrank <lisa.saalfrank@web.de>
- * @copyright 2020 Lisa Saalfrank
- * @package Equidea\Engine
- * @version 0.1.0
- */
- class ColorGenome {
- public const AGOUTI_INACTIVE = 'a';
- public const AGOUTI_SEALBROWN = 'At';
- public const AGOUTI_BAY = 'A';
- public const AGOUTI_WILDBAY = 'A+';
- public const EXTENSION_INACTIVE = 'e';
- public const EXTENSION_ACTIVE = 'E';
- public const FLAXEN_INACTIVE = 'F';
- public const FLAXEN_ACTIVE = 'f';
- protected array $agouti = [
- self::AGOUTI_INACTIVE,
- self::AGOUTI_INACTIVE
- ];
- protected array $extension = [
- self::EXTENSION_INACTIVE,
- self::EXTENSION_INACTIVE
- ];
- protected array $flaxen = [
- self::FLAXEN_INACTIVE,
- self::FLAXEN_INACTIVE
- ];
- /**
- * Returns the allele on the agouti locus that controls the restriction of eumelanin
- * in the horses coat.
- *
- * There are for different variants of the gene:
- * - 'a' which results in black horses
- * - 'At' which results in seal brown horses
- * - 'A' which results in normal type bay horses
- * - 'A+' which results in wild type bay horses
- *
- * @see https://en.wikipedia.org/wiki/Equine_coat_color_genetics#Agouti_phenotypes
- *
- * @return array The agouti locus
- */
- public function getAgouti() : array {
- return $this->agouti;
- }
- /**
- * Returns the allele on the extension locus that controls whether a horses hair should
- * be black or red.
- *
- * There are two different variants of the gene:
- * - 'e' which will produce chestnut horses
- * - 'E' which produces black, seal brown, bay or wild bay horses
- *
- * @see https://en.wikipedia.org/wiki/Equine_coat_color_genetics#Extension_phenotypes
- *
- * @return array The extension locus
- */
- public function getExtension() : array {
- return $this->extension;
- }
- /**
- * Returns the allele on the flaxen locus that only affects chestnut based colors.
- * It controls whether the mane and tale are red or blond.
- *
- * There are two different variants of the gene:
- * - 'f' which causes the hair to turn blond, making the color flaxen chestnut
- * - 'F' Which causes th hair to turn red, making it a normal chestnut
- *
- * @see https://en.wikipedia.org/wiki/Flaxen_gene
- *
- * @return array The flaxen locus
- */
- public function getFlaxen() : array {
- return $this->flaxen;
- }
- /**
- * Checks whether either one or both of the two genes of the allele on the agouti locus
- * match the given single gene.
- *
- * @param string $gene The gene to search for
- *
- * @return bool The result of the search
- */
- public function agoutiHas(string $gene) : bool {
- return in_array($gene, $this->agouti);
- }
- /**
- * Checks whether either one or both of the two genes of the allele on the extension
- * locus match the given single gene.
- *
- * @param string $gene The gene to search for
- *
- * @return bool The result of the search
- */
- public function extensionHas(string $gene) : bool {
- return in_array($gene, $this->extension);
- }
- /**
- * Checks whether either one or both of the two genes of the allele on the flaxen locus
- * match the given single gene.
- *
- * @param string $gene The gene to search for
- *
- * @return bool The result of the search
- */
- public function flaxenHas(string $gene) : bool {
- return in_array($gene, $this->flaxen);
- }
- /**
- * Fills all locuses with their allele pairs. Array must be a multi-dimensional
- * associative array with the keys for agouti, extension and flaxen.
- * The genes of an allele must be provided as an indexed array.
- *
- * Example:
- * [
- * 'agouti' => ['a', 'a'],
- * 'extension' => ['e', 'e'],
- * 'flaxen' => ['f', 'f']
- * ]
- *
- * @param array $dna All color alleles for each locus of a genome
- *
- * @return void
- */
- public function setAllAlleles(array $dna) : void
- {
- $this->agouti = $dna['agouti'];
- $this->extension = $dna['extension'];
- $this->flaxen = $dna['flaxen'];
- }
- /**
- * Retrieves all locuses with their allele pairs as a multi-dimensional
- * associative array with the keys for agouti, extension and flaxen.
- * The genes of an allele are provided as an indexed array.
- *
- * Example:
- * [
- * 'agouti' => ['a', 'a'],
- * 'extension' => ['e', 'e'],
- * 'flaxen' => ['f', 'f']
- * ]
- *
- * @return array All color alleles for each locus of a genome
- */
- public function getAllAlleles() : array
- {
- return [
- 'agouti' => $this->agouti,
- 'extension' => $this->extension,
- 'flaxen' => $this->flaxen
- ];
- }
- /**
- * Receives an associative array of JSON-encoded allele pairs for each locus.
- * Decodes the JSON import to indexed arrays and stores them in the class. Must
- * contain the locuses agouti, extension and flaxen.
- *
- * Example:
- * [
- * 'agouti' => '["a","a"]',
- * 'extension' => '["e","e"]',
- * 'flaxen' => '["f","f"]'
- * ]
- *
- * @param array $jsonDna All color alleles encoded as JSON
- *
- * @return void
- */
- public function importJson(array $jsonDna) : void
- {
- $this->agouti = json_decode($jsonDna['agouti']);
- $this->extension = json_decode($jsonDna['extension']);
- $this->flaxen = json_decode($jsonDna['flaxen']);
- }
- /**
- * Returns an associative array of JSON-encoded allele pairs for each locus, which
- * are the locuses agouti, extension and flaxen. Note that only the alleles are
- * JSON encoded but not the associations with locuses.
- *
- * Example:
- * [
- * 'agouti' => '["a","a"]',
- * 'extension' => '["e","e"]',
- * 'flaxen' => '["f","f"]'
- * ]
- *
- * @return All color alleles encoded as JSON
- */
- public function exportJson() : array
- {
- return [
- 'agouti' => json_encode($this->agouti),
- 'extension' => json_encode($this->extension),
- 'flaxen' => json_encode($this->flaxen)
- ];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement