:-['observations/metabolites/10Feb11-KGGEName/ternaryMet_newOndexID.pl'].	%%hiroaki_60Met
%:-['observations/metabolites/10Feb11-KGGEName/foldInfo.pl']. -- this is unnecessary when doing leave-one-out
:-['observations/ge/allDoeseGE.pl']. %Feb17-ThreeState-Prolog-ProbWithoutQuotes/linkFile

set(ge_data_available,yes).



%:-['regulationRules/enzymeLimiting_substrateLimiting/t_control.pl'].
%:-['regulationRules/enzymeLimiting_substrateLimiting_counting/t_control.pl'].
%:-['regulationRules/enzymeLimiting_substrateLimiting_counting_EC/t_control.pl'].
%:-['regulationRules/2010_9_23/t_SID.pl'].
%:-['regulationRules/2010_9_23/t_singleC1.pl']. 
%:-['regulationRules/2011_01_21/t_noEC_constrainIncoporate.pl']. 
:-['regulationRules/2011_05_24/t_tomatoComparable.pl']. % t_simpleRecord %t_noEC_constrainIncoporate
%:-['regulationRules/2011_01_21/t_noEC_assumptionUpdated.pl']. 



:-['networkData/2012_2/keggmap_rn_rno.pl'].
:-['networkData/ubiquitous_compounds/ondexID_2012_2.pl'].
%:-['networkData/2011_1/kegg_rno-PreferredFirstNameFiltered-Mapped-RelationsCollapsed-UbiquitousRemoved.pl'].
%:-['networkData/2010_9_1/kegg_rno_removed.pl'].
%--
:-['networkData/a.pl'].
%:-['networkData/m.pl'].
%--:-['networkData/visualizationProcessing.pl'].

:-['score/score.pl'].



sharedOutputToC:-
	numbersList(157,208,AllEIs),
	gen_output_readIn_candiateH(AllEIs),
	indentifySharedHs(AllEIs,T_EITIs,OrderedGroupedCandidateHs),
	outputToC(PosEIs,T_EITIs),
	tell('sharedCandidate.pl'),
	filterIsolated(OrderedGroupedCandidateHs),
	told.

s:-
	numbersList(157,208,AllEIs),
	indentifySharedHs(AllEIs).



hs(PosEIs):-	%(PosEIs)

PosEIs=[75,116], %4,32,37%PosEIsNOR_Late % [89,90,91,92,96,97,98,101,102,103,105,106,107,108,109]

prefixTreeBuilder(PosEIs),listing,
claNode(startNode,StartNodeCoverage),
tell('cancer_hypothesisSelection_day1.txt'),
hypothesisSelection(startNode-StartNodeCoverage,FinalHypothesis),
print_list(FinalHypothesis),nl,
told.



hs0:-
getAllEx_oneTimePoint('Day1',PosEIs),
prefixTreeBuilder(PosEIs),
claNode(startNode,StartNodeCoverage),
hypothesisSelection(startNode-StartNodeCoverage,FinalHypothesis),
FinalHypothesis=[IsolatedEIExplanations,CombinedExplanation],
write('Here are the final Hypothesis'),nl,
print_list(CombinedExplanation),nl,
nl,

write('The followings are explanations which do not overlap with others '),nl,
print_list(IsolatedEIExplanations),nl,

tell('day1_dose1000.txt'),
translateFinalHypothesis([IsolatedEIExplanations,CombinedExplanation],FinalH), %write('Finish translating'),nl,
write('# Isolated Explanations'),
analyzeIsolated(IsolatedEIExplanations),
nl,write('# Shared Control Points Explanations'),
analyzeCombined(CombinedExplanation), write('#Finish explanation for each metabolite'),nl,
told. 

	
g0:-
  numbersList(1,208,PosEIs0),
  selectlist(zeroHypothesisCheck,PosEIs0,PosEIs),
  nl,write(PosEIs),nl,
  ord_subtract(PosEIs0,PosEIs,EmptyH_EIList),  write(EmptyH_EIList),nl,
  findall(EI,ex(EI,concentration(MID,no_change,Time),1),NoChangeList),write(NoChangeList),nl,
  (EmptyH_EIList==NoChangeList ->
    write('yes,the same');
    write('not the same'), ord_subtract(EmptyH_EIList,NoChangeList,Diff_EIList), nl,write(Diff_EIList)
  ).

zeroHypothesisCheck(EI):-
  g(EI,T),T\==[].


/*Day1=[[3,4,5,7,9,10,11,16,20,22,26,27,29,30,32,36,37,38,40,41,50,53,56],
Day4=[69,70,71,72,73,75,76,77,80,81,82,83,84,86,88,93,95,96,97,98,99,100,101,103,106,109,110,111,112,114,116,118,121,123,124,125],
Day7=[136,137,139,140,141,142,143,145,148,151,153,154,158,160,161,162,163,164,165,166,169,172,175,176,178,180,183,188,189,190,191],
Day14=[202,203,204,205,207,208,209,211,216,221,222,226,228,230,232,235,238,239,240,242,244,246,248,250,252,255,257] */






c:-
        statistics(cputime,[Total1,Previous]),

	tell('cancer_day14.txt'),
	%numbersList(231,272,PosEIsNOR_Late),
	%PosEIsNOR_Late=[89,90,91,92,96,97,98,101,102,103,105,106,107,108,109],
	numbersList(157,208,PosEIsDay14),
	%PosEIsDay14=[202,203,204,205,207,208,209,211,216,221,222,226,228,230,232,235,238,239,240,242,244,246,248,250,252,255,257],
	NegEIs=[],
	
	cover(PosEIsDay14,NegEIs,[],FinalTI), 

	statistics(cputime,[Total2,Now]),
	TimeTaken is Now-Previous,
	write('Final Learning Result'),nl,
	tInterpreter(FinalTI,FinalT),
	print_list(FinalT),
	tCompScore(FinalTI,DL),write(DL),
	%write('Total Time Taken is '), %write(TimeTaken),
	told.


/*lv:-
	numbersList(1,60,PosEIsDay1),
	cross_validation(PosEIsDay1,PA1),
	nl,write('Predictive Accurracy '),write(PA1),nl,nl,
	numbersList(61,120,PosEIsDay3),
	cross_validation(PosEIsDay3,PA2),
	nl,write('Predictive Accurracy '),write(PA2),nl,nl,
	numbersList(121,180,PosEIsDay7),
	cross_validation(PosEIsDay7,PA3),
	nl,write('Predictive Accurracy '),write(PA3),nl,nl,

	numbersList(181,240,PosEIsDay14),AllEIs=PosEIsDay14,
	cross_validation(AllEIs,PA),
	nl,write('Predictive Accurracy '),write(PA).
*/
lv:-
	numbersList(1,52,PosEIsDay1),
	cross_validation(PosEIsDay1,PA1),
	nl,write('Predictive Accurracy '),write(PA1),nl,nl,
	numbersList(53,104,PosEIsDay3),
	cross_validation(PosEIsDay3,PA2),
	nl,write('Predictive Accurracy '),write(PA2),nl,nl,
	numbersList(105,156,PosEIsDay7),
	cross_validation(PosEIsDay7,PA3),
	nl,write('Predictive Accurracy '),write(PA3),nl,nl,

	numbersList(157,208,PosEIsDay14),AllEIs=PosEIsDay14,
	cross_validation(AllEIs,PA),
	nl,write('Predictive Accurracy '),write(PA).


/*tell('cancer_cv_day14.txt'),		

numbersList(157,208,PosEIsDay14),
%PosEIsDay14=[202,203,204,205,207,208,209,211,216,221,222,226,228,230,232,235,238,239,240,242,244,246,248,250,252,255,257],
PosEIs=PosEIsDay14,
	leaveOneOut(PosEIs,PosEIs,Results),
	
	% Results is a list of Uncovered test data -- you may trace the learning result and see why
	percentage(Results,PosEIs,PA),
	%sumList(Results,TotalA),length(Results,TotalN),PA is TotalA/TotalN, nl, %write('PA is '), write(PA), nl, %percentage(Results,PosEIs,PA),
	write('Predictive Accuracy is'),write(PA),nl,
        told,
	nl. 
*/




forAll(P,Q):- \+ (P, \+Q).
g:-
	tell('cancer_H_for_each_example.txt'),
        statistics(cputime,[Total1,Previous]),

	numbersList(157,208,PosEIs),
	%PosEIs= [1,3,4,5,6,7,8,9,10,11,12],
	forAll(member(EI,PosEIs),(nl,write(EI),nl,g(EI,T))),

	statistics(cputime,[Total2,Now]),
	TimeTaken is Now-Previous,
	write('Total Time Taken is '), write(TimeTaken),
	told.


lv1:- % removed those covered by default noChange first.
	tell('cancer_23E_removeCovered.txt'),	

	AllEI0=[1,2,3,4,5,6,7,8,9,10,11,12,14,15,16,17,18,19,20,22,23,24],%[1,4,5,7,10,11], %[1,3,4,5,6,7,8,9,10,11],
	
		asserta((enzyme_state(EC_Number,no_change):- (\+enzyme_state(EC_Number,inhibited);\+enzyme_state(EC_Number,activated))),Ref_defaultNoChangeStatement),
					
	unCoverRecord(AllEI0,AllEI), % reduce = remove those already explained by the examples
	erase(Ref_defaultNoChangeStatement),

	length(AllEI,PK),
	leaveOneOut(AllEI,AllEI,Results),
	
	% Results is a list of Uncovered test data -- you may trace the learning result and see why
	percentage(Results,AllEI,PA),
	write('Predictive Accuracy is'),write(PA),nl,
	told.

lv:-
	tell('cancer_23E_LeaveOneOut.txt'),	
	%findall(EIp,ex(EIp,Ep,1),PosEI0s), % full size learning
	%findall(EIn,ex(EIn,En,0),NegEIs),
	%length(NegEIs,NK),
	%unCoverRecord(PosEI0s,PosEIs), % reduce = remove those already explained by the examples
	%length(PosEIs,PK),
	
/*
	PosEIs0=[1,3,4,5,6,7,8,9,10],%numbersList(1,100,PosEIs0),
	unCoverRecord(PosEIs0,PosEIs),write('Positive examples to be learned'),write(PosEIs),nl,
	%PosEIs=PosEIs0,
	NegEIs=[],

	append(PosEIs,NegEIs,AllEI),%write({PK,NK}),write('Totally '),nl,
*/
	AllEI=[1,2,3,4,5,6,7,8,9,10,11,12,14,15,16,17,18,19,20,22,23,24],
	%[1,2,3,4,5,6,7,10,11,12,14,15,16,17,18,19,20,22,23,24],%[1,4,5,7,10,11], %[1,3,4,5,6,7,8,9,10,11],
	
	leaveOneOut(AllEI,AllEI,Results),
	
	% Results is a list of Uncovered test data -- you may trace the learning result and see why
	percentage(Results,AllEI,PA),
	write('Predictive Accuracy is'),write(PA),nl,
	told.

% choose by counting
co:-
	
	tell('cancer_H_for_23exs.txt'),
        statistics(cputime,[Total1,Previous]),

	%numbersList(1,13,PosEIs),
	PosEIs= [1,2,3,4,5,6,7,8,9,10,11,12,14,15,16,17,18,19,20,22,23,24], %[1,2,3,4,5,6,7,8,9,10,11,12],
	%forAll(member(EI,PosEIs),(nl,write(EI),nl,g(EI,T))),
	genAll_EIsigned(PosEIs,AllTs,TotalNum),write('Total is '), write(TotalNum),nl,
	lazyAllTsTranslation(AllTs,NewAllClas),
	length(AllTs,K),write('Number generalized is'), write(K),nl,
	%print_list(NewAllClas),nl,

	rb_new(Tree0),
	counting(NewAllClas,Tree0,Tree),
	rb_visit(Tree,Ts),%print_list(Ts),nl,
		
	%maplist(scoreCountedT,Ts,ScoredTs),
	%sort(ScoredTs,SortedScoredTs),	
	%print_list(SortedScoredTs),nl,
	nl,nl,nl,write('Following, new results'),nl,

	chooseH(PosEIs,Ts,[],FinalH),
	print_list(FinalH),nl,

	statistics(cputime,[Total2,Now]),
	TimeTaken is Now-Previous,
	write('Total Time Taken is '), write(TimeTaken),
	told.

tc:-
	PosEIs= [1,2,3,4,5,6,7,8,9,10,11,12,14,15,16,17,18,19,20,22,23,24],
	trainANDcount(PosEIs,FinalTI),
	tInterpreter(FinalTI,FinalT),
		write('*** Learning Result is'), nl,print_list(FinalT),nl.



writeReaction(ReactionID):-
	(catalyzed_by_ECclass(ReactionID,EC_Numbers)->
		Foo=1;
		EC_Numbers='NOT annotated'
	),
	findall(SID-Snames,
		(consumed_by(SID,ReactionID,'IMPD'),
		findall(Sname,concept_name(SID,Sname,true),Snames)),
		SIDs),
	findall(PID-Pnames,
		(produced_by(PID,ReactionID,'IMPD'),
		findall(Pname,concept_name(PID,Pname,true),Pnames)),
		PIDs),
	nl,
	writeq(ReactionID),write(' Catalyzed EC number is '),write(EC_Numbers),write('  Substrates are '),write(SIDs), write('  Products are '), write(PIDs).



sg:- % scriptGenerator
scriptExGenerator('day1',1,52),
scriptExGenerator('day3',53,104),
scriptExGenerator('day7',105,156),
scriptExGenerator('day14',157,208).
