1/*
    2Program describing the Mendelian rules of inheritance of the color of pea
    3plants. It considers a family of two parents and a child.
    4The problem is, given the alleles of the parents, predict the
    5probability of the color (or of its alleles) of a pea plant.
    6From
    7H. Blockeel. Probabilistic logical models for mendel's experiments:
    8An exercise.
    9In Inductive Logic Programming (ILP 2004), Work in Progress Track, 2004.
   10*/
   11:- use_module(library(pitaind)).   12
   13:- if(current_predicate(use_rendering/1)).   14:- use_rendering(c3).   15:- endif.   16
   17:- pitaind.   18
   19:- begin_lpad.   20:- set_pitaind(or,exc).   21
   22mother(m,s).
   23father(f,s).
   24% family with 3 members: m is the mother of s and f is the father of s
   25
   26% cg(I,C,A) means that individual I has color allele A on chromosome C
   27% the color alleles are p and w and the chromosomes are 1 and 2
   28% color(I,Col) means that individual I has color Col
   29% Col can be purple or white
   30
   31cg(m,1,p).
   32cg(m,2,w).
   33cg(f,1,w).
   34cg(f,2,p).
   35% we know with certainty the alleles of the parants of s
   36
   37cg(X,1,A):0.5 ; cg(X,1,B):0.5 :- mother(Y,X),cg(Y,1,A), cg(Y,2,B).
   38% the color allele of an individual on chromosome 1 is inherited from its
   39% mother. The two alleles of the mother have equal probability of being
   40% transmitted
   41
   42cg(X,2,A):0.5 ; cg(X,2,B):0.5 :- father(Y,X),cg(Y,1,A), cg(Y,2,B).
   43% the color allele of an individual on chromosome 2 is inherited from its
   44% father. The two alleles of the mother have equal probability of being
   45% transmitted
   46
   47
   48color(X,purple) :- cg(X,1,p).
   49% if an individual has a p allele its color is purple, i.e., purple is
   50% dominant
   51color(X,purple) :- cg(X,1,w),cg(X,2,p).
   52
   53color(X,white) :- cg(X,1,w), cg(X,2,w).
   54% if an individual has two w alleles its color is white, i.e., white is
   55% recessive
   56
   57:- end_lpad.

?- prob(color(s,purple),Prob). % what is the probability that the color of s' flowers is purple? % expected result 0.75 ?- prob(color(s,white),Prob). % what is the probability that the color of s' flowers is white? % expected result 0.25 ?- prob(cg(s,1,p),Prob). % what is the probability that the color allele on chromosme 1 of s is p? % expected result 0.5 ?- prob(cg(s,1,w),Prob). % what is the probability that the color allele on chromosme 1 of s is w? % expected result 0.5 ?- prob(cg(s,2,p),Prob). % what is the probability that the color allele on chromosme 2 of s is p? % expected result 0.5 ?- prob(cg(s,2,w),Prob). % what is the probability that the color allele on chromosme 2 of s is w? % expected result 0.5 ?- prob_bar(color(s,purple),Prob). % what is the probability that the color of s' flowers is purple? % expected result 0.75 ?- prob_bar(color(s,white),Prob). % what is the probability that the color of s' flowers is white? % expected result 0.25 ?- prob_bar(cg(s,1,p),Prob). % what is the probability that the color allele on chromosme 1 of s is p? % expected result 0.5 ?- prob_bar(cg(s,1,w),Prob). % what is the probability that the color allele on chromosme 1 of s is w? % expected result 0.5 ?- prob_bar(cg(s,2,p),Prob). % what is the probability that the color allele on chromosme 2 of s is p? % expected result 0.5 ?- prob_bar(cg(s,2,w),Prob). % what is the probability that the color allele on chromosme 2 of s is w? % expected result 0.5

*/