Applied Bimatics - An Informatics & eHealth Blog

I am a clinician with a passion for informatics. This blog is about my eHealth journey exploring interoperability in Electronic Medical Records (EMR/EHR), Patient Safety, Pharmacovigilance, Data Analytics, Clinical Research and Bioinformatics in a clinical context. Comparing Canadian, Indian and Middle Eastern healthcare systems and services. Join our open facebook group here: https://www.facebook.com/groups/clinical.bioinformaticians/


Counting conditional Occurrences using Prolog.


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.

coil(105,a,0.000).
coil(109,g,0.001).
coil(110,l,0.004).
coil(111,l,0.014).
coil(112,v,0.055).
coil(113,g,0.055).
coil(114,s,0.371).
coil(115,e,0.416).
coil(116,k,0.860).
coil(117,v,0.955).
coil(118,t,0.998).
coil(119,m,0.999).
coil(120,q,0.999).
coil(121,n,0.999).

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),
            (   call(Goal),
                flag(counter, Inner, Inner+1),
                fail;
                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_region(Cutoff, Val):-
                     coil(_,_,Val),
                     Val>Cutoff.
                    
coil_percent(Region, Total, Percent):-
                     setting(coil,X),
                     findall(Val,coil_region(X,Val),R),
                     length(R,Region),
                     findall(C,coil(_,_,C),A),
                     length(A,Total),
                     Total>0,        %Avoid division by zero
                     Percent is (Region/Total) * 100,!.

coil_percent(0,0,0).

IISA Home Page.

commentAdd Your Comments/Suggestions/Criticisms! | View Comments | Links to this post

About Me

As a Dermatologist and Informatician my research mainly involves application of bioinformatics techniques and tools in dermatological conditions. However my research interests are varied and I have publications in areas ranging from artificial intelligence, sequence analysis, systems biology, ontology development, microarray analysis, immunology, computational biology and clinical dermatology. I am also interested in eHealth, Health Informatics and Health Policy.

Address

Bell Raj Eapen
Hamilton, ON
Canada