/* 0. Each version's scoring is based on agreement with GE data
	agree: 0.1
	no GE data while known EC
	no GE data while unknown EC (enzyme not assigned EC; no assigned enzymes)
	
	
1. the number of examples that sharing each of its facts
	*** while this is not considering the length of each facts.
*/


% Input is the file of candidateH0
% forAll(candidateH0(EI_any,TI_any,T),scoreOneTheory(Tree,{EI_any,TI_any,T})),




scoreOneTheory(ClaCountedTree,{EI_any,TI_any,T}):-
	maplist(scoreOneCla(ClaCountedTree),T,ScoreList),
	multiplyList(ScoreList,TScore),
	portray_clause(candidateH_score(EI_any,TI_any,ScoreList,TScore)).


scoreOneCla(Tree,HypothesizedRS,Score):-
	rb_lookup(HypothesizedRS,EI_List,Tree),
	length(EI_List,SharedNum),
/*	((SharedNum=1;SharedNum=2)->
		Foo=1;
		write('One shared by more than one example '),write(SharedNum-HypothesizedRS),nl
	),*/

	HypothesizedRS=[rs-{ReactionID,LimitingType,HypothesizedState,Time}],%UsedRule,
	scoreByGEData({ReactionID,LimitingType,HypothesizedState,Time},Score_GE),
	Score is SharedNum*Score_GE.



scoreOneTheory(T,TScore):-
	maplist(scoreOneHypothesizedReactionState,T,ScoreList),
	multiplyList(ScoreList,TScore).
	%portray_clause(candidateH_score(EI_any,TI_any,ScoreList,TScore)).


scoreOneHypothesizedReactionState([rs-{ReactionID,LimitingType,HypothesizedState,Time}],Score):-
	scoreByGEData({ReactionID,LimitingType,HypothesizedState,Time},Score).

scoreByGEData({ReactionID,substrateLimiting,Any,Time},Score_GE):-
	catalyzed_by_ECclass(ReactionID,EC_Number),!,
	(concentration_e(EC_Number,GEChange,ComputedChangeDegree0,Time)->
		ComputedChangeDegree is abs(ComputedChangeDegree0-0.5),
		Score_GE is 1-(ComputedChangeDegree/0.5);
		Score_GE=1
		).

	
scoreByGEData({ReactionID,enzymeLimiting,HypothesizedState,Time},Score_GE):-
	catalyzed_by_ECclass(ReactionID,EC_Number),!,	
	(concentration_enzClass(EC_Number,GEChange,Time)->
		(propotional(HypothesizedState,GEChange)->
				Score_GE0=1; %write('Yes, agreed'),nl;  
				Score_GE0=0.001 %,write('No, disagreed'),nl
			),
		geChangeDegree(EC_Number,GEChange,ChangeDegree,Time),
		Score_GE is Score_GE0 * ChangeDegree;

		Score_GE=0.01
		).


scoreByGEData({ReactionID,LimitingType,HypothesizedState,Time},0.01). %:-write('Here is one that not annotated ').
	% what score to unannotated reaction? mid point, as unmeasured EC


propotional(cataIncreased,up).
propotional(cataDecreased,down).
propotional(cataNoChange,noChange).


%geChangeDegree(EC_Number,GEChange,ChangeDegree,Time):- concentration_e(EC_Number,GEChange,ChangeDegree,Time).

geChangeDegree(EC_Number,down,ChangeDegree,Time):- 
	concentration_e(EC_Number,down,ChangeDegree,Time).
geChangeDegree(EC_Number,up,ChangeDegree,Time):- 
	concentration_e(EC_Number,up,ComputedChangeDegree,Time),
	ChangeDegree is 1-ComputedChangeDegree.
geChangeDegree(EC_Number,noChange,ChangeDegree,Time):- 
	concentration_e(EC_Number,noChange,ComputedChangeDegree0,Time),
	ComputedChangeDegree is abs(ComputedChangeDegree0-0.5),
	ChangeDegree is 1-(ComputedChangeDegree/0.1).

