% These rules are essentially the same as that in MetaLog, and (I think) also the same as that in ILP2010
% These are based on the assumption of substrate limiting, although there are rules similar to enzyme limiting. 
% One main difference from the previous modeling lies in declarative bias: it is the enzyme inhibited or not, rather than certain reactions, which is rather specific.
% terminology -- enzymeUP, enzymeDOWN



%enzyme_state(EC_Number,no_change):- \+enzyme_state(EC_Number,inhibited).

concentration(X,Change):-	% using other examples
	ex(EI,concentration(X,Change),1),!.
% won't be used in reasoning, but used in T for excluding those useless
concentration(X,Change):- 
	neg(Change,OppositeChange),
	ex(EI,concentration(X,OppositeChange),1),%write('!!! you are looking for sth inconsistent'),
	!,
	fail.




/****************** Direct Effect ******************/
/*---------- Blocked/Slower down ----------*/
% 12,15,18 enzyme inhibited
concentration(PID,down):-				%concept_name(P,PID,true),	
	produced_by(PID,ReactionID,'IMPD'),	%reaction(ReactionID,'','LycoCyc','IMPD'),
	catalyzed_by(ReactionID,EnzID,'IMPD'),
	enzyme_state(EnzID,inhibited).

% enzyme inhibited
concentration(SID,up):-				%concept_name(S,SID,true),	
	consumed_by(SID,ReactionID,'IMPD'),	%reaction(ReactionID,'','LycoCyc','IMPD'),
	catalyzed_by(ReactionID,EnzID,'IMPD'),
	enzyme_state(EnzID,inhibited).

/*---------- Speeded Up ----------*/
% 10,13,16 enzyme activated
concentration(PID,up):-				%concept_name(P,PID,true),	
	produced_by(PID,ReactionID,'IMPD'),	%reaction(ReactionID,'','LycoCyc','IMPD'),
	catalyzed_by(ReactionID,EnzID,'IMPD'),
	enzyme_state(EnzID,activated).

% enzyme activated
concentration(SID,down):-				%concept_name(S,SID,true),	
	consumed_by(SID,ReactionID,'IMPD'),	%reaction(ReactionID,'','LycoCyc','IMPD'),
	catalyzed_by(ReactionID,EnzID,'IMPD'),
	enzyme_state(EnzID,activated).

/****************** Indirect Effect ******************/
% enzyme no_change -- S up
concentration(PID,up):-				%concept_name(P,PID,true),	
	produced_by(PID,ReactionID,'IMPD'),	%reaction(ReactionID,'','LycoCyc','IMPD'),
	catalyzed_by(ReactionID,EnzID,'IMPD'), 
	\+concentration_enzClass(EC_Number,Change),
	enzyme_state(EnzID,no_change),
	consumed_by(SID,ReactionID,'IMPD'), concentration(SID,up).

% enzyme no_change -- S down
concentration(PID,down):-				%concept_name(P,PID,true),	
	produced_by(PID,ReactionID,'IMPD'),	%reaction(ReactionID,'','LycoCyc','IMPD'),
	catalyzed_by(ReactionID,EnzID,'IMPD'),
	\+concentration_enzClass(EC_Number,Change),
	enzyme_state(EnzID,no_change),
	consumed_by(SID,ReactionID,'IMPD'), concentration(SID,down).



/************ Integrity Constraint **************/
integrityConstraint:-
enzyme_state(EnzID,State1),enzyme_state(EnzID,State2),State1\==State2. %,write('Integrity Constraint is Disobeyed'),nl.


/****************** Simple direct rules ******************/
%This integrity constraint can be put into top theory directly.
/* this can be transform into integrity constraint 
enzyme_state(EC_Number,activated):- concentration_enzClass(EC_Number,up).
enzyme_state(EC_Number,no_change):- concentration_enzClass(EC_Number,no_change).
enzyme_state(EC_Number,inhibited):- concentration_enzClass(EC_Number,down).
*/

set(specificScore,yes).

scoreSpecific(T,Coverage,Score):-
	tCompScore(T,TComplex),
	%Score is TComplex+Coverage.
	CoverageScore is 2*Coverage,
	Score is TComplex+CoverageScore.


tCompScore([],0).
tCompScore([ClaI|T],NTScore):-
	tCompScore(T,TScore), 
	nl,write(ClaI),nl,
	(ClaI=[enzyme_state-{EC_Number,no_change}]->
		NTScore=TScore;
		claInterpreter(ClaI,Cla),
		length(Cla,HL),
		NTScore is TScore+HL
	).	


