18 use commondata !> @note we need global data in every module
27 character (len=*),
parameter,
private ::
modname =
"(THE_GENOME)"
36 character(len=LABEL_LENGTH) :: allele_label
54 integer,
dimension(ADDITIVE_COMPS) :: allele_value
58 real(
srp) :: dominance_weight
112 character(len=LABEL_LENGTH) :: chromosome_label
116 type(
gene),
allocatable,
dimension(:) :: allele
162 character(len=LABEL_LENGTH) :: genome_label
173 logical :: sex_is_male
175 character(len=LABEL_LENGTH) :: sex_label
226 generic,
public :: neuro_resp => trait_init, trait_set
233 procedure,
public :: trait_init_linear => &
240 procedure,
public :: trait_set_linear => &
246 generic,
public :: linear_g2p => trait_init_linear, trait_set_linear
287 procedure,
public :: recombine_random => &
293 procedure,
public :: recombine_partial => &
299 procedure,
public :: crossover => &
326 call qsort(this%allele)
339 type(
gene),
intent(in out),
dimension(:) :: a
358 type(
gene),
intent(in out),
dimension(:) :: a
360 integer,
intent(out) :: marker
377 if (a(j)%rank_id <= x)
exit
382 if (a(i)%rank_id >= x)
exit
411 class(
gene),
intent(inout) :: this
425 class(
gene),
intent(inout) :: this
429 this%allele_value = 0
437 class(
gene),
intent(inout) :: this
446 class(
gene),
intent(inout) :: this
448 character(len=*),
intent(in) :: label
450 this%allele_label = label
457 class(
gene),
intent(in) :: this
459 character(len=LABEL_LENGTH) :: label
461 label = this%allele_label
468 class(
gene),
intent(inout) :: this
471 integer,
intent(in) :: set_value
474 integer,
intent(in) :: nr
476 this%allele_value(nr) = set_value
483 class(
gene),
intent(inout) :: this
485 integer,
dimension(ADDITIVE_COMPS),
intent(in) :: values
487 this%allele_value = values
494 class(
gene),
intent(in) :: this
497 integer,
intent(in) :: nr
502 avalue = this%allele_value(nr)
509 class(
gene),
intent(in) :: this
511 integer,
dimension(ADDITIVE_COMPS),
intent(out) :: values
513 values = this%allele_value
519 class(
gene),
intent(inout) :: this
522 integer,
intent(in) :: value_id
524 this%rank_id = value_id
531 class(
gene),
intent(inout) :: this
534 real(SRP),
optional,
intent(in) :: prob
537 real(SRP) :: prob_mut
539 integer :: this_allele_mutates
542 if (
present(prob))
then
551 if (rand_r4() < prob_mut)
then
563 class(
gene),
intent(inout) :: this
566 real(SRP),
optional,
intent(in) :: prob
569 real(SRP) :: prob_mut
572 if (
present(prob))
then
578 if (rand_r4() < prob_mut)
then
581 call this%init_allele()
599 integer,
intent(in) :: length
601 character(len=*),
optional,
intent(in) :: label
609 if (
present(label))
then
610 this%chromosome_label = label
617 this%clength = length
620 if (.not.
allocated(this%allele))
allocate(this%allele(length))
625 call this%allele(i)%init_allele()
627 call this%allele(i)%rank(i)
635 call this%allele(i)%labels( label( 1:len_trim(label)- &
636 max(0, len_trim(label)+ &
638 ) //
"_" // tostr(i,length) &
650 integer,
intent(in) :: length
652 character(len=*),
optional,
intent(in) :: label
660 if (
present(label))
then
661 this%chromosome_label = label
668 this%clength = length
671 if (.not.
allocated(this%allele))
allocate(this%allele(length))
677 do concurrent( i=1:length )
679 call this%allele(i)%create_allele()
681 this%allele(i)%rank_id = i
688 call this%allele(i)%labels( trim(label) // tostr(i,length) )
703 do concurrent( i = 1:this%clength )
705 this%allele(i)%rank_id = i
718 real(SRP),
optional,
intent(in) :: prob
720 real(SRP) :: prob_mut
722 type(
gene) :: temp_shift
723 integer :: gene_move, gene_swap
726 if (
present(prob))
then
735 if (rand_r4() < prob_mut)
then
739 gene_move = rand_i(1,this%clength)
742 gene_swap = rand_i(1,this%clength)
746 do while (gene_swap == gene_move)
747 gene_swap = rand_i(1,this%clength)
751 temp_shift = this%allele(gene_move)
754 this%allele(gene_move) = this%allele(gene_swap)
755 this%allele(gene_swap) = temp_shift
758 this%allele(gene_move)%rank_id = gene_move
759 this%allele(gene_swap)%rank_id = gene_swap
776 real(SRP),
optional,
intent(in) :: prob
778 real(SRP) :: prob_mut
780 integer :: gene_move, gene_moveto
783 if (
present(prob))
then
792 if (rand_r4() < prob_mut)
then
796 gene_move = rand_i(1,this%clength)
799 gene_moveto = rand_i(1,this%clength)
803 do while (gene_moveto == gene_move)
804 gene_moveto = rand_i(1,this%clength)
808 this%allele(gene_move)%rank_id = gene_moveto
811 call this%sort_rank_id()
814 call this%recalc_rank_id()
831 character(len=*),
optional,
intent(in) :: label
843 if (.not.
allocated(this%chromosome)) &
849 do i=1, this%genome_size
857 if (
present(label))
then
858 call this%label( label )
887 if (.not.
allocated(this%chromosome)) &
893 do i=1, this%genome_size
916 character(len=*),
optional,
intent(in) :: label
920 if (
present(label))
then
921 this%genome_label = label
942 character(len=LABEL_LENGTH) :: label_str
944 label_str = this%genome_label
959 integer :: sex_locus_sum
960 integer :: sex_locus_num
961 integer,
dimension(ADDITIVE_COMPS) :: values_from_allele
970 sex_locus_sum = 0; sex_locus_num = 0
976 cchromos:
do i=1,this%genome_size
977 callales:
do j=1, this%chromosome(i,k)%clength
985 call this%chromosome(i,k)%allele(j)%get_vector(values_from_allele)
987 sex_locus_sum = sex_locus_sum + sum(values_from_allele)
1000 if ( ((real(sex_locus_sum,
srp)/real(sex_locus_num,
srp)) / &
1003 this%sex_is_male = .
true.
1005 this%sex_label =
male
1008 this%sex_is_male = .
false.
1022 male = this%sex_is_male
1034 if (this%sex_is_male)
then
1048 character(len=LABEL_LENGTH) :: sex_label
1050 sex_label = this%sex_label
1079 this%alive = .
false.
1087 logical :: is_alive_now
1089 is_alive_now = this%alive
1097 logical :: is_dead_now
1099 is_dead_now = .
true.
1100 if (this%alive) is_dead_now = .
false.
1117 mother, father, exchange_ratio)
1125 real(SRP),
optional,
intent(in) :: exchange_ratio
1128 real(SRP) :: exchange_ratio_here
1136 integer :: n_alleles
1142 integer,
dimension(ADDITIVE_COMPS) :: acomp_vect_mother, acomp_vect_father
1148 if (
present(exchange_ratio))
then
1149 exchange_ratio_here = exchange_ratio
1172 chromosomes:
do i=1, this%genome_size
1175 n_alleles = this%chromosome(i,j)%clength
1177 alleles:
do k=1, n_alleles
1184 if ( rand_r4() < exchange_ratio_here )
then
1191 call mother%chromosome(i,j)%allele(k)%get_vector(acomp_vect_mother)
1194 call this%chromosome(i,j)%allele(k)%set_vector(acomp_vect_mother)
1202 call father%chromosome(i,j)%allele(k)%get_vector(acomp_vect_father)
1206 call this%chromosome(i,j)%allele(k)%set_vector(acomp_vect_father)
1228 mother, father, exchange_ratio)
1236 real(SRP),
optional,
intent(in) :: exchange_ratio
1239 real(SRP) :: exchange_ratio_here
1247 integer :: n_alleles
1253 integer,
dimension(ADDITIVE_COMPS) :: acomp_vect_mother, acomp_vect_father
1259 if (
present(exchange_ratio))
then
1260 exchange_ratio_here = exchange_ratio
1282 chromosomes:
do i=1, this%genome_size
1285 n_alleles = this%chromosome(i,j)%clength
1287 alleles:
do k=1, n_alleles
1294 if ( rand_r4() < exchange_ratio_here )
then
1307 call mother%chromosome(i,j)%allele(k)%get_vector(acomp_vect_mother)
1310 call this%chromosome(i,j)%allele(k)%set_vector(acomp_vect_mother)
1320 call father%chromosome(i,j)%allele(k)%get_vector(acomp_vect_father)
1324 call this%chromosome(i,j)%allele(k)%set_vector(acomp_vect_father)
1348 mother, father, pattern_matrix)
1362 logical,
dimension(MAX_NALLELES,N_CHROMOSOMES), &
1363 optional,
intent(in) :: pattern_matrix
1366 logical,
dimension(MAX_NALLELES,N_CHROMOSOMES) :: pattern_matrix_loc
1374 integer :: n_alleles
1380 integer,
dimension(ADDITIVE_COMPS) :: acomp_vect_mother, acomp_vect_father
1385 if (
present(pattern_matrix))
then
1386 pattern_matrix_loc = pattern_matrix
1397 chromosomes:
do concurrent(i=1:this%genome_size)
1400 n_alleles = this%chromosome(i,j)%clength
1402 alleles:
do concurrent(k=1:n_alleles)
1407 if ( pattern_matrix_loc(k,i) )
then
1414 call mother%chromosome(i,j)%allele(k)%get_vector(acomp_vect_mother)
1417 call this%chromosome(i,j)%allele(k)%set_vector(acomp_vect_mother)
1425 call father%chromosome(i,j)%allele(k)%get_vector(acomp_vect_father)
1429 call this%chromosome(i,j)%allele(k)%set_vector(acomp_vect_father)
1472 init_val, gerror_cv, label)
1477 real(SRP),
intent(out) :: this_trait
1480 logical,
dimension(:,:),
intent(in) :: g_p_matrix
1483 real(SRP),
intent(in) :: init_val
1488 real(SRP),
optional,
intent(in) :: gerror_cv
1491 character(len=*),
intent(in) :: label
1494 integer :: i, j, k1, k2
1495 integer,
dimension(ADDITIVE_COMPS) :: additive_vals_1, additive_vals_2
1516 cchromos:
do i=1,this%genome_size
1517 calleles:
do j=1, this%chromosome(i,k1)%clength
1518 if ( g_p_matrix(j,i) )
then
1520 call this%chromosome(i,k1)%allele(j)%labels(label)
1521 call this%chromosome(i,k2)%allele(j)%labels(label)
1526 call this%chromosome(i,k1)%allele(j)%get_vector(additive_vals_1)
1527 call this%chromosome(i,k2)%allele(j)%get_vector(additive_vals_2)
1531 if (
present(gerror_cv))
then
1532 this_trait =
gamma2gene( additive_vals_1, additive_vals_2, &
1533 init_val, gerror_cv )
1535 this_trait =
gamma2gene( additive_vals_1, additive_vals_2, &
1562 init_val, gerror_cv)
1567 real(SRP),
intent(out) :: this_trait
1570 logical,
dimension(:,:),
intent(in) :: g_p_matrix
1573 real(SRP),
intent(in) :: init_val
1578 real(SRP),
optional,
intent(in) :: gerror_cv
1581 integer :: i, j, k1, k2
1582 integer,
dimension(ADDITIVE_COMPS) :: additive_vals_1, additive_vals_2
1602 cchromos:
do i=1,this%genome_size
1603 calleles:
do j=1, this%chromosome(i,k1)%clength
1604 if ( g_p_matrix(j,i) )
then
1609 call this%chromosome(i,k1)%allele(j)%get_vector(additive_vals_1)
1610 call this%chromosome(i,k2)%allele(j)%get_vector(additive_vals_2)
1614 if (
present(gerror_cv))
then
1615 this_trait =
gamma2gene( additive_vals_1, additive_vals_2, &
1616 init_val, gerror_cv )
1618 this_trait =
gamma2gene( additive_vals_1, additive_vals_2, &
1647 this_trait, g_p_matrix, &
1648 phenotype_min, phenotype_max, label)
1653 real(SRP),
intent(out) :: this_trait
1656 logical,
dimension(:,:),
intent(in) :: g_p_matrix
1659 real(SRP),
intent(in) :: phenotype_min
1660 real(SRP),
intent(in) :: phenotype_max
1663 character(len=*),
intent(in) :: label
1666 integer :: i, j, k1, k2
1667 integer,
dimension(ADDITIVE_COMPS) :: additive_vals_1, additive_vals_2
1697 cchromos:
do i=1,this%genome_size
1698 calleles:
do j=1, this%chromosome(i,k1)%clength
1699 if ( g_p_matrix(j,i) )
then
1701 call this%chromosome(i,k1)%allele(j)%labels(label)
1702 call this%chromosome(i,k2)%allele(j)%labels(label)
1706 call this%chromosome(i,k1)%allele(j)%get_vector(additive_vals_1)
1707 call this%chromosome(i,k2)%allele(j)%get_vector(additive_vals_2)
1713 this_trait =
rescale( real(sum(additive_vals_1) + &
1714 sum(additive_vals_2), srp), &
1715 real(SCALE_GENOME_MIN, SRP), &
1716 real(SCALE_GENOME_MAX, SRP), &
1743 this_trait, g_p_matrix, &
1744 phenotype_min, phenotype_max )
1749 real(SRP),
intent(out) :: this_trait
1752 logical,
dimension(:,:),
intent(in) :: g_p_matrix
1755 real(SRP),
intent(in) :: phenotype_min
1756 real(SRP),
intent(in) :: phenotype_max
1759 integer :: i, j, k1, k2
1760 integer,
dimension(ADDITIVE_COMPS) :: additive_vals_1, additive_vals_2
1790 cchromos:
do i=1,this%genome_size
1791 calleles:
do j=1, this%chromosome(i,k1)%clength
1792 if ( g_p_matrix(j,i) )
then
1796 call this%chromosome(i,k1)%allele(j)%get_vector(additive_vals_1)
1797 call this%chromosome(i,k2)%allele(j)%get_vector(additive_vals_2)
1803 this_trait =
rescale( real(sum(additive_vals_1) + &
1804 sum(additive_vals_2), srp), &
1805 real(SCALE_GENOME_MIN, SRP), &
1806 real(SCALE_GENOME_MAX, SRP), &
1824 real(SRP),
optional,
intent(in) :: p_point
1827 real(SRP),
optional,
intent(in) :: p_set
1830 real(SRP),
optional,
intent(in) :: p_swap
1833 real(SRP),
optional,
intent(in) :: p_shift
1836 integer :: mutate_chromosome, mutate_homolog, mutate_allele
1845 mutate_chromosome = rand_i(1, this%genome_size)
1847 mutate_allele = rand_i(1, this%chromosome( &
1848 mutate_chromosome,mutate_homolog)%clength)
1849 if (
present(p_point))
then
1850 call this%chromosome(mutate_chromosome,mutate_homolog)%allele( &
1851 mutate_allele)%mutate_point(p_point)
1853 call this%chromosome(mutate_chromosome,mutate_homolog)%allele( &
1854 mutate_allele)%mutate_point()
1860 mutate_chromosome = rand_i(1, this%genome_size)
1862 mutate_allele = rand_i(1, this%chromosome( &
1863 mutate_chromosome,mutate_homolog)%clength)
1864 if (
present(p_set))
then
1865 call this%chromosome(mutate_chromosome,mutate_homolog)%allele( &
1866 mutate_allele)%mutate_set(p_set)
1868 call this%chromosome(mutate_chromosome,mutate_homolog)%allele( &
1869 mutate_allele)%mutate_set()
Sigmoidal relationship between environmental factor and the organism response, as affected by the gen...
Arbitrary rescales value(s) from one range (A:B) to another (A1:B1).
recursive pure subroutine qsort(A)
qsort and qs_partition_ are the two parts of the recursive sort algorithm qsort is the recursive fron...
pure subroutine qs_partition_rank_id(A, marker)
qsort and qs_partition_ are the two parts of the recursive sort algorithm qs_partition_rank_id is a p...
COMMONDATA – definitions of global constants and procedures.
character(len= *), parameter, private modname
MODNAME always refers to the name of the current module for use by the LOGGER function LOG_DBG....
real(srp), parameter, public genome_recombination_ratio_mother
The ratio of the genome that inherited from the mother. The other part is inherited from the father....
integer, parameter, public n_chromosomes
The number of chromosomes for the agents.
integer, parameter, public srp
Definition of the standard real type precision (SRP).
logical, dimension(max_nalleles, n_chromosomes), parameter, public sex_genotype_phenotype
Sex definition can be implemented differently from all other traits. Here is an example of the phenot...
integer, parameter, public label_length
The length of standard character string labels. We use labels for various objects,...
logical, dimension(max_nalleles, n_chromosomes), parameter, public genome_crossover_fixed_mother
Boolean 2D matrix that determines the pattern of fixed chromosome crossover. For each chromosome,...
integer, parameter, public chromosome_ploidy
The ploidy of the chromosome set. Can theoretically be haploid (=1), diploid (=2) or,...
integer, parameter, public additive_comps
Number of additive allele components.
integer, parameter, public allelerange_min
The minimum possible value of alleles (allele range minimum) See implementation notes on the_genome::...
integer, dimension(n_chromosomes), parameter, public len_chromosomes
The number of alleles in each of the chromosomes. NOTE: This must be an array (vector) of the size co...
integer, parameter, public allelerange_max
The maximum possible value of alleles (allele range maximum) See implementation notes on the_genome::...
real(srp), parameter, public mutationrate_point
Mutation rate for point allele mutations.
logical, parameter, public true
Safety parameter avoid errors in logical values, so we can now refer to standard Fortran ....
real(srp), parameter, public sex_ratio
Sex ratio for initialising genomes.
integer, parameter, public label_cen
real(srp), parameter, public relocation_swap_rate
Mutation rate for chromosome relocation, i.e. probability of a gene moving to a different position on...
real(srp), parameter, public mutationrate_batch
Mutation rate for point allele mutations, a whole batch of allele components.
character(len= *), dimension(n_chromosomes), parameter, public lab_chromosomes
Set the labels of the chromosomes. NOTE, must be an array(vector) ) of the size commondata::n_chromos...
integer, parameter, public label_cst
This parameter defines the range of characters that is used for generating random labels,...
real(srp), parameter, public relocation_shift_rate
character(len= *), parameter, public male
Set names of the sexes – the allele labels.
character(len= *), parameter, public female
character(len=label_length), parameter sexlocus_label
Labels for the sex locus alleles (gene) - vector as we don't need to label individual alleles....
logical, parameter, public false
Definition of environmental objects.
Definition the genetic architecture of the agent.
pure subroutine allele_values_vector_get(this, values)
Get the vector of all values of the alleles, i.e. gets the gene values.
subroutine genome_mutate_wrapper(this, p_point, p_set, p_swap, p_shift)
Perform a probabilistic random mutation(s) on the individual genome. This is a high level wrapper to ...
subroutine genome_sex_determine_init(this)
Sex determination initialisation subroutine.
subroutine genome_individual_recombine_homol_full_rand_alleles(this, mother, father, exchange_ratio)
Internal genetic recombination backend, exchange individual alleles between homologous chromosomes in...
subroutine allele_label_init_random(this)
The (pair of) alleles here are assigned random string labels Not sure if that is necessary for any ap...
elemental logical function genome_individual_check_alive(this)
Check if the individual is alive.
elemental integer function allele_value_get(this, nr)
Get the value of the allele.
elemental logical function genome_individual_check_dead(this)
Check if the individual is dead (the opposite of is_alive).
elemental subroutine chromosome_recalculate_rank_ids(this)
This subroutine recalculates rank_id indices for consecutive gene objects within the chromosome....
elemental subroutine genome_individual_set_alive(this)
Set the individual to be alive, normally this function is used after init or birth.
elemental subroutine allele_value_set(this, set_value, nr)
Set a single value of the allele additive component.
subroutine genome_create_zero(this)
Create a new empty genome, and set sex as determined by the sex determination locus....
subroutine chromosome_init_allocate_random(this, length, label)
This subroutine initialises the chromosome with, and allocates, random alleles, sets one of them rand...
elemental character(len=label_length) function allele_label_get(this)
Get the i-th allele label.
subroutine genome_label_set(this, label)
Label genome. If label is not provided, make a random string.
subroutine genome_individual_crossover_homol_fix(this, mother, father, pattern_matrix)
Internal fixed genetic crossover backend, exchange blocks of alleles between homologous chromosomes i...
elemental character(len=label_length) function genome_get_sex_label(this)
Get the descriptive sex label: male or female.
subroutine allele_mutate_random(this, prob)
Introduce a random point mutation to a random allele component.
subroutine chromosome_mutate_relocate_swap_random(this, prob)
Mutate within the same chromosome, relocate a gene (unit of alleles) to a different random position w...
subroutine allele_init_random(this)
Initialises allele with a random integer. Note that we do not set the labels for the alleles here dur...
subroutine trait_init_linear_sum_additive_comps_2genes_r(this, this_trait, g_p_matrix, phenotype_min, phenotype_max, label)
Initialise an individual trait of the agent that depends on the genotype. This can be any trait upwar...
elemental subroutine allele_label_set(this, label)
Set labels for the alleles. The subroutine parameter is array of labels.
subroutine chromosome_create_allocate_zero(this, length, label)
Init a new chromosome, zero, non-random.
subroutine genome_individual_recombine_homol_part_rand_alleles(this, mother, father, exchange_ratio)
Internal genetic recombination backend, exchange individual alleles between homologous chromosomes in...
subroutine trait_init_genotype_gamma2gene(this, this_trait, g_p_matrix, init_val, gerror_cv, label)
Initialise an individual trait of the agent that depends on the genotype. This can be any trait upwar...
elemental logical function genome_get_sex_is_male(this)
Get the logical sex ID of the genome object component.
subroutine trait_set_linear_sum_additive_comps_2genes_r(this, this_trait, g_p_matrix, phenotype_min, phenotype_max)
Set an individual trait of the agent that depends on the genotype. This can be any trait upwards in t...
elemental subroutine genome_individual_set_dead(this)
Set the individual to be dead. Note that this function does not deallocate the individual agent objec...
elemental subroutine allele_create_zero(this)
Create allele with zero value. We don't set labels for alleles here.
pure subroutine alleles_value_vector_set(this, values)
Set values of the alleles as a vector, i.e. sets the whole gene values.
elemental logical function genome_get_sex_is_female(this)
Get the logical sex ID of the genome object component.
subroutine genome_init_random(this, label)
Initialise the genome at random, and set sex as determined by the sex determination locus.
elemental subroutine allele_rank_id_set(this, value_id)
subroutine trait_set_genotype_gamma2gene(this, this_trait, g_p_matrix, init_val, gerror_cv)
Set an individual trait of the agent that depends on the genotype. This can be any trait upwards in t...
subroutine allele_mutate_random_batch(this, prob)
Introduce a random mutation of the whole set of additive allele components.
elemental subroutine chromosome_sort_rank_id(this)
Sort GENE objects within the CHROMOSOME by their rank_id. The two subroutines qsort and qs_partition_...
subroutine chromosome_mutate_relocate_shift_random(this, prob)
Mutate within the same chromosome, relocate a gene (unit of alleles) to a different random position w...
elemental character(len=label_length) function genome_label_get(this)
Accessor function to get the genome label. The label is a kind of a (random) text string name of the ...
Definition of a movable spatial object. It extends the the_environment::spatial object,...
This type describes the chromosome object. Chromosome consists of an array of alleles and a descripti...
This describes an individual gene object. See the genome structure for as general description and gen...
This type describes parameters of the individual agent's genome The genome is an array of allocatable...