% difference with that in:
% no_change is still recorded, but not translated.
% Reasons for recording no_change: avoid hypothesize to two states. 
% the sign is given 100 for those agree, since it is not compression, but counting the number


:- dynamic enzyme_state/2.


%:-['counting.pl'].
:-['counting_includeLength.pl'].:-['topCla'].
:-['b_control'].

%set(depthLimit,s(s(s(s(s(s(s(s(0))))))))). %PianoNumDepthLimit):- numMap(6,PianoNumDepthLimit).
set(depthLimit,s(s(0))).
%set(depthLimit,s(s(s(0)))).
%set(depthLimit,s(s(s(s(s(s(s(s(s(s(0))))))))))).
%set(depthLimit,s(s(s(s(s(0)))))).
set(etoB,yes).





/*********** using other examples ***********/
concentration(DepthLimit,Tr,Tr,VisitedNodes,X,Change):-	
	set(depthLimit,DepthLimit0),
	DepthLimit \== DepthLimit0,
	ex(EI,concentration(X,Change),1),!,
	write('***using this example***'), write(X),nl.


concentration(DepthLimit,Tr,Tr,VisitedNodes,X,Change):- 
	neg(Change,OppositeChange),
	ex(EI,concentration(X,OppositeChange),1),%write('!!! you are looking for sth inconsistent'),
	!,
	fail.

neg(up,down).
neg(down,up).



/***************************** Regulation Rules ******************************/
/****************** Direct Effect ******************/

/*---------- Blocked/Slower down ----------*/
% 12,15,18 enzyme inhibited
concentration(DepthLimit,TrSoFar,Tr,VisitedNodes,PID,down):-
	produced_by(PID,ReactionID,'IMPD'),
	catalyzed_by(ReactionID,EnzID,'IMPD'),
	enzyme_state(TrSoFar,Tr,EnzID,inhibited),portray_clause(VisitedNodes).

/*
% enzyme inhibited
concentration(DepthLimit,TrSoFar,Tr,VisitedNodes,SID,up):-				%concept_name(S,SID,true),	
	consumed_by(SID,ReactionID,'IMPD'),	%reaction(ReactionID,'','LycoCyc','IMPD'),
	catalyzed_by(ReactionID,EnzID,'IMPD'),
	enzyme_state(TrSoFar,Tr,EnzID,inhibited),portray_clause(VisitedNodes).
*/

/*---------- Speeded Up ----------*/
% 10,13,16 enzyme activated
concentration(DepthLimit,TrSoFar,Tr,VisitedNodes,PID,up):-
	produced_by(PID,ReactionID,'IMPD'),
	catalyzed_by(ReactionID,EnzID,'IMPD'),
	enzyme_state(TrSoFar,Tr,EnzID,activated),portray_clause(VisitedNodes).

/*
% enzyme activated
concentration(DepthLimit,TrSoFar,Tr,VisitedNodes,SID,down):-				%concept_name(S,SID,true),	
	consumed_by(SID,ReactionID,'IMPD'),	%reaction(ReactionID,'','LycoCyc','IMPD'),
	catalyzed_by(ReactionID,EnzID,'IMPD'),
	enzyme_state(TrSoFar,Tr,EnzID,activated),portray_clause(VisitedNodes).
*/


/****************** Indirect Effect ******************/
% enzyme no_change -- S up
concentration(s(DepthLimit),TrSoFar,Tr,VisitedNodes,PID,up):-				%concept_name(P,PID,true),	
	produced_by(PID,ReactionID,'IMPD'),	%reaction(ReactionID,'','LycoCyc','IMPD'),
	catalyzed_by(ReactionID,EnzID,'IMPD'), 
	\+enz_concentration(EnzID,Change),
	enzyme_state(TrSoFar,Tr1,EnzID,no_change),
	consumed_by(SID,ReactionID,'IMPD'), \+member(SID,VisitedNodes),
	concentration(DepthLimit,Tr1,Tr,[SID|VisitedNodes],SID,up).

% enzyme no_change -- S down
concentration(s(DepthLimit),TrSoFar,Tr,VisitedNodes,PID,down):-				%concept_name(P,PID,true),	
	produced_by(PID,ReactionID,'IMPD'),	%reaction(ReactionID,'','LycoCyc','IMPD'),
	catalyzed_by(ReactionID,EnzID,'IMPD'), 
	\+enz_concentration(EnzID,Change),
	enzyme_state(TrSoFar,Tr1,EnzID,no_change),
	consumed_by(SID,ReactionID,'IMPD'), \+member(SID,VisitedNodes),
	concentration(DepthLimit,Tr1,Tr,[SID|VisitedNodes],SID,down).




/*************** Abduce enzyme_state	****************/
/* Simple version -- no incorporation of integrity constraint
enzyme_state(TrSoFar,Tr,EnzID,State):-
	Tr=[[enzyme_state-{EnzID,State}]|TrSoFar].
*/


% incorporate integrity constraint
% 1. one enzyme not to be hypothesized to several states: (1) the existing B; (2) the same 
% 2. the gene expression data. 

propotional(activated,up).
propotional(inhibited,down).
propotional(no_change,no_change).

% This is not suitable when there are alternative similar rules 

enzyme_state(TrSoFar,Tr,EnzID,State):-
	(appeared(EnzID,TrSoFar,State2)->
		State2==State, write('not contradiction'),nl,
		Tr=TrSoFar;
		(enz_concentration(EnzID,Change)->
			nl,write('----- genomic data available'), write({EnzID,State,Change}),
			(propotional(State,Change)->
				Sign=100,write('Yes, agreed'),nl;  % whatever up/down/no_change, as long as they agree with each other
				Sign=1,write('No, disagreed'),nl
			);
			Sign=10
		),
		Tr=[[enzyme_state-{Sign,EnzID,State}]|TrSoFar]
	).


appeared(EnzID,TrSoFar,State):-
	member([enzyme_state-{Sign,EnzID,State}],TrSoFar),nl,write('--Aha, appear before!--'),nl.
% appeared(EnzID,TrSoFar,State):-	% won't happen since no inhibited is known, nor added to the background knowledge
%	enzyme_state(EnzID,State).



