Counting conditional occurrences using Prolog.
I wanted to implement the following rule in prolog for my IISA project.
If the percentage of coil region is greater than 20% the homologue detection algorithms may become unreliable. The coil module of IISA returns prolog database in the following format.
ie coil(position, aminoacid, probability of being part of coil).
I wanted to count the number of facts with the probability exceeding a cutoff value, say 0.7.
Though it is simple problem, I could not find any solution for this even after googling for few hours. Finally I found this code on the net.
%Code to count the number of proofs for a goal. Found on the net.
count_proof(Goal, N) :-
flag(counter, Outer, 0),
flag(counter, Inner, Inner+1),
flag(counter, Count, Outer),
N = Count
Though it worked well (I have still not figured out how!) the code is SWI-Prolog specific and did not work in JLog prolog applet I use for IISA web interface.
Finally I learned about findall and bagof
But still it took some time to figure out how to use findall for my purpose because the description read findall (Var, Database, Array) and to use length(Array). Using coil (_,_,A) as database will count only the number of aminoacids and I didn’t know how to implement the condition A>0.7.
Finally somewhere I found the actual definition for findall (Var, Goal, Array) which solved my problem, though I wasted a whole day on this simple problem.
Here is the final code.
%The region is coil if the value is greater than threshold
coil_percent(Region, Total, Percent):-
Total>0, %Avoid division by zero
Percent is (Region/Total) * 100,!.
IISA Home Page.
Add Your Comments/Suggestions/Criticisms! | View Comments | Links to this post