forked from qfo/benchmark-webservice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServerMain.drw
990 lines (887 loc) · 39 KB
/
ServerMain.drw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
##############################################
# Backend for the BenchmarkWebservice #
# Reads the 'BSin' pipe and executes the #
# commands. #
##############################################
if not assigned(DEBUG) then DEBUG := false fi:
if not assigned(RUNLOCAL) then RUNLOCAL := true fi:
noRemember := true;
SetRandSeed();
Set(printgc=false); Set(gc=1e8):
ReadProgram(getenv('DARWIN_ORTHOLOG_BENCHMARK_REPO_PATH').'/lib/darwinit');
print(getpid());
version();
t:=TimedCallSystem('ulimit -a'):
prints(t[2]);
darwin64 := 'darwin -q';
logfile := getenv('DARWIN_LOG_PATH').'/BS_server.log';
NrGenomes('RefSet5');
NrGenomes('RefSet17');
NrGenomes('RefSet18');
google_analytics := ReadRawFile(cdir.'/templates/analytics.htmlc'):
# --------------------- General Functions -------------------------
#################################
# Run server is the main loop #
# that runs forever. #
#################################
RunServer := proc()
global StartTime,nReq;
WriteLog('server started on '.hostname().': '.getpid());
inpipe := getenv('DARWIN_RUN_PATH').'/BSin.'.hostname();
StartTime := date();
nReq :=0;
do
OpenReading(inpipe);
do
t := ReadRawLine();
if t=EOF then break fi;
pt := t;
cp := SearchString('cookies=table([{NULL}]',pt);
if cp>-1 then pt := pt[1..cp-1].pt[cp+35..-1] fi;
WriteLog(pt[1..-2].' requested');
if t[1..7]='Request' then
prints(t);
e := traperror(eval(parse(t)));
if e=lasterror then
WriteLog(sprintf('*** ERROR: %a',e));
# if too many files are open, it can no longer
# create a pipe. We need to restart
if e='Cannot create pipe' then quit fi;
else
WriteLog(pt[1..-2].' completed');
nReq := nReq+1;
fi;
fi;
od;
od;
end:
###############################
# Write log #
###############################
WriteLog := proc(s:string)
OpenAppending(logfile);
printf('%s (%s, %d): %s\n',date(),hostname(),getpid(),s);
OpenAppending(previous);
end:
#######################################
# general Error message handler #
#######################################
UNEXPECTED_ERROR_MSG := proc(fun:string, var:string)
msg := sprintf('*** An unexpected Error occured in %s (%s). '.
'Please report to [email protected]. Thanks', fun, var);
WriteLog(msg);
return(msg);
end:
#######################################
# Page to display in case of an error #
#######################################
ErrorPage := proc(filename:string,msg:string)
Logger( print(msg), 'DEBUG');
vars := table(''):
#vars['header'] := MakeHeader('SearchDb','');
vars['message'] := msg;
return(GenerateTemplate(cdir.'/templates/error.html',vars));
end:
#########################################
# Write resulting page #
# We write first to a normal file and #
# then cat the fiel to the pipe. In #
# the case noone reads the pipe, we #
# wait at most 2 seconds and then #
# return. #
#########################################
WriteResult := proc(filename:string, html:string)
OpenWriting(filename.'tmp');
p := SearchString('</body>',html);
if p>-1 then
prints(html[1..p]);
prints(google_analytics);
prints('</html>');
else
prints(html);
fi;
OpenWriting(previous);
TimedCallSystem('cat '.filename.'tmp >>'.filename,10);
CallSystem('rm '.filename.'tmp');
end:
# --------------- Server Functions -------------------------------
#################################################
# the main function that processes all requests.#
#################################################
Request := proc(funcname:string,filename:string;
'params'=(params:list),
'pnames'=(pnames:list),
'cookies' = (cookies:table))
global DB,InDB,Cookies;
WriteResult(filename.'.alive','ALIVE\n');
if assigned(cookies) then
Cookies := cookies;
else
Cookies := table(NULL);
fi;
if funcname = 'Index' then
html := traperror(bsIndex(op(params)));
elif funcname = 'UploadData' then
html := traperror(bsUploadData(op(params)));
elif funcname = 'RedoProjectMapping' and length(params)=8 then
html := traperror(bsUploadData(op(params)));
elif funcname = 'MapData' then
html := traperror(bsMapData(op(params)));
elif funcname = 'MapRels' then
html := traperror(bsMapRels(op(params)));
elif funcname = 'CheckRelMap' then
html := traperror(bsCheckRelMap(params[1]));
elif funcname = 'TestSelection' then
html := traperror(bsTestSelection(op(params)));
elif funcname = 'RunTests' then
html := traperror(bsRunTests(params,pnames));
elif funcname = 'CheckResults' then
html := traperror(bsCheckResults(params[1]));
elif funcname = 'ShowProject' then
html := traperror(bsShowProject(If(type(params,list),params[1],NULL)));
elif funcname = 'About' then
html := traperror(bsAbout());
elif funcname = 'Service' then
html := traperror(bsService());
# cookies/settings
elif funcname = 'ViewCookie' then
html := traperror(bsViewCookie());
elif funcname = 'Settings' then
html := traperror(bsSettings());
else
html := traperror(NotImplemented(funcname));
fi;
if html=lasterror then
Logger(lasterror,'ERROR');
res := '';
for z in [lasterror] do
res := res . sprintf('%a ',z);
od:
html := ErrorPage(filename,res);
fi;
WriteResult(filename,html);
return(true);
end:
####################################
# Index Page #
####################################
bsIndex := proc(;itype:string)
if itype='params' then
if Cookies['FormSize']<>NULL then
itype := Cookies['FormSize'];
else itype := 'small' fi;
fi;
vars := table('');
vars['nspecies'] := string(NS);
vars['logo'] := '/OMAbrowser.gif';
return(GenerateTemplate(cdir.'/templates/index.html',vars));
end:
bsShowProject := proc()
if nargs=1 then
if args[1]='RefSet5' then
prjs := GetPublicProjects('RefSet5');
elif args[1]='RefSet17' then
prjs := GetPublicProjects('RefSet17');
elif args[1]='RefSet18' then
prjs := GetPublicProjects('RefSet18');
else
prjs := [GetPKeyData(args[1])];
fi
elif nargs=0 then
prjs := GetPublicProjects('RefSet5');
else error('unexpected parameters');
fi;
prjs := sort(prjs, x->uppercase(x['Title']));
vars := table(''):
cont := []:
for p in prjs do
t := table('');
for key in ['Description','Title','Website'] do
t[key] := p[key];
od:
path := p['fnBase'];
for k from length(path) to 1 by -1 while path[k]<>'/' do od:
datafn := rawdir.path[k+1..-1].'.rels.raw.gz';
dataUrl := rawurl.path[k+1..-1].'.rels.raw.gz';
if length(FileStat(datafn))=0 then
t['hasData'] := false; t['Predictions'] := 'n/a';
else t['hasData'] := true; t['Predictions'] := dataUrl;
fi;
logfn := rawdir.path[k+1..-1].'.rel.log';
logUrl := rawurl.path[k+1..-1].'.rel.log';
if length(FileStat(logfn))=0 then
t['hasLog'] := false;
else t['hasLog'] := true; t['LogLnk'] := logUrl;
fi;
t['tags'] := ProjectButtons(p);
covered := p['OrgsCovered'];
if covered=intersect() or length(covered)>=length(KnownSpecies(p['ref'])) then
t['coverage'] := 'covers all genomes';
else
missing := {op(KnownSpecies(p['ref']))} minus covered;
if length(missing)>5 then
t['coverage'] := sprintf('%d genomes missing', length(missing));
else
t['coverage'] := sprintf('missing genomes: %a', missing);
fi:
fi;
t['uploadDate'] := p['createDat'];
cont := append(cont, GenerateTemplate(cdir.'/templates/secProject.htmlc',t));
od:
vars['content'] := ConcatStrings(cont,'\n');
vars['title'] := 'Overview of '.If(nargs=0,'all public projects', prjs[1,'Title']);
return( GenerateTemplate(cdir.'/templates/showProjects.html',vars));
end:
####################################
# Upload Data #
####################################
bsUploadData := proc(fnBase:string, tit:string, nrProts, nrOrth, reference,
isPublic, methDesc, methURL, email)
Logger(sprintf('Upload: %A', args), 'DEBUG');
id := AddPKeyData(tit,fnBase, 'NSeqSub'=nrProts, 'NOrthSub'=nrOrth,
'reference'=reference,'description'=methDesc,'url'=methURL,
'isPublic'=isPublic, 'email'=email):
return('Location: gateway.pl?f=MapData&p1='.id.'\n\n');
end:
####################################
# About page #
####################################
bsAbout := proc()
vars := table(''):
return( GenerateTemplate(cdir.'/templates/about.html',vars) );
end:
#################################
# MapData #
#################################
bsMapData := proc(PID:string)
pKey := GetPKeyData(PID);
fnBase := pKey['fnBase'];
seqMapResFn := fnBase.'.seqmap';
lock := fnBase.'.lock';
vars := table(''):
vars['tit'] := pKey['Title'];
vars['nrOrth'] := pKey['NOrthSub'];
vars['nrProt'] := pKey['NSeqSub'];
vars['reloadin'] := 30;
vars['PID'] := PID;
if pKey['ref']<>'OMA' then
if pKey['email']<>'' then
map_data_url := 'http://'.host.'/cgi-bin/gateway.pl?f=MapRels&p1='.PID;
msg := 'The orthology benchmarking status of your submitted project '.
'is be available on the following page for you:\n'.pKey['Title'].': '.map_data_url.
'\n\nWe thank you for using the orthology benchmarking webservice.';
traperror(SendEMail(msg, email, 'Link to benchmark project "'.pKey['Title'].'"'));
fi:
return('Location: gateway.pl?f=MapRels&p1='.PID.'\n\n');
else
error('OMA as reference dataset is no longer suported');
fi
end:
bsCheckRelMap := proc(PID:string)
pKey := GetPKeyData(PID);
fnBase := pKey['fnBase'];
dbFn := fnBase.'.db';
lock := fnBase.'.rel.lock';
logFn := fnBase.'.rel.log';
vars := table(''):
vars['tit'] := GetPKeyData(PID)['Title'];
vars['reloadin'] := 30;
vars['PID'] := PID;
if FileExists(lock) then
vars['mappingStatus'] := HandleLockFile(lock);
if FileExists(logFn) then vars['log'] := ReadRawFile(logFn) fi:
return( GenerateTemplate(cdir.'/templates/checkRelMapping.html',vars) );
elif FileExists(dbFn) then
CallSystem('ln -s '.logFn.' '.rawdir);
return(bsTestSelection(PID));
else error('RelMapping not started for '.PID) fi:
end:
bsMapRels := proc(PID:string)
global SPS:
fnBase := GetPKeyData(PID)['fnBase'];
dbFn := fnBase.'.db';
lock := fnBase.'.rel.lock';
logFn := fnBase.'.rel.log';
reference := GetPKeyData(PID)['ref'];
vars := table(''):
vars['tit'] := GetPKeyData(PID)['Title'];
# check if mapping process is already running
if FileExists(lock) then
vars['content'] := HandleLockFile(lock);
elif FileExists(dbFn) then
# in general, this should not be the case!
# provide test selection page:
return( bsTestSelection(PID) );
else
# the mapping did not start. start it! :-)
CallSystem('touch '.lock);
# start computation as background process
cmd := sprintf('echo "ReadProgram(''%s/lib/darwinit''): resDBfn:=''%s'': '.
'relsinfn := ''%s'': lock:=''%s'': logFn:=''%s''; PID := ''%s'': '.
'ReadProgram(''%s/ComputeRelMapping.drw''): done;" | nice -n 19 %s -E &',
cdir, dbFn, fnBase.'.rels', lock, logFn, PID, cdir, darwin64);
Logger( 'starting command: '.cmd, 'INFO');
CallSystem( cmd );
fi:
return('Location: gateway.pl?f=CheckRelMap&p1='.PID.'\n\n');
end:
bsTestSelection := proc(PID:string)
pKey := GetPKeyData(PID);
fnBase := pKey['fnBase'];
dbFn := fnBase.'.db';
if not FileExists(dbFn) then
error('Project "'.GetPKeyData(PID)['Title'].'" was not corretely uploaded');
fi:
vars := table(''):
vars['tit'] := pKey['Title'];
dataset := pKey['ref'];
vars['ref'] := dataset;
vars['isRefSet'] := evalb(dataset<>'OMA');
vars['notRefSet'] := evalb(dataset='OMA');
if FileExists(pKey['fnBase'].'.rel.log') then
vars['has_mapping_log'] := true:
basename := SearchDelim('/', pKey['fnBase'])[-1];
vars['mapping_log_lnk'] := rawurl.basename.'.rel.log';
else
vars['has_mapping_log'] := false;
fi:
t := [seq(If(z['PID']<>PID,[z['Title'],z['PID'], z],NULL),
z=GetPublicProjects(dataset))]:
if length(t)>0 then
t := transpose(sort(t)):
pubPID := t[2]; publicProjects := t[1]; pKeys := t[3]:
else pubPID := publicProjects := pKeys := [];
fi:
Npub := length(pubPID):
pairwiseOverlap := [seq( ProjSpeciesOverlap([PID,z]), z=pubPID)];
for z in ['Euk','Bac','Fun'] do
if ProjMetProperty(PID, GetTestProperty('TreeTest_'.z)) then
vars['TT'.z.'Projects'] := ConcatStrings(
[seq(ProjectCheckbox(pKeys[pNr], sprintf('pTT%sPrj%d', z, pNr),
ProjMetProperty(pubPID[pNr],GetTestProperty('TreeTest_'.z))),
pNr=1..Npub)],'\n');
vars['style'.z] := 'checked="checked"'; vars['has'.z] := true;
else vars['style'.z] := 'disabled="disabled"'; vars['has'.z] := false;
fi:
od:
# large Species Tree discordance test
for problem in ['Luca','Euk','Ver','Fun'] do
if dataset='OMA' then
vars['hasSTD'.problem] := false;
else
vars['STD'.problem.'Projects'] := ConcatStrings(
[seq(ProjectCheckbox(pKeys[pNr], sprintf('pSTD%sPrj%d', problem, pNr)),
pNr=1..Npub)], '\n');
vars['hasSTD'.problem] := SearchString('<input',vars['STD'.problem.'Projects'])>=0;
vars['styleSTD'.problem] := If(vars['hasSTD'.problem], 'checked="checked"','');
fi:
od:
# load the TreeCases of the available reconciled tree problems
refPhyloProbs := [seq(GetTreeCase( z, dataset ), z=GetAllTreeCases(dataset))];
stub := 'pRefPhyloPrj';
vars['RefPhyloProjects'] := ConcatStrings(
[seq(If( length(pairwiseOverlap[pNr])>1,
ProjectCheckbox(pKeys[pNr], sprintf('%s%d', stub, pNr)),
''),
pNr=1..Npub)], '\n');
stub := 'pRefPhyloProb';
vars['RefPhyloProblems'] := ConcatStrings(
[seq(If( ProjMetProperty(PID, GetTestProperty(z['Name'])),
sprintf('<input type="checkbox" id="%s%s" name="%s%s" checked="checked" />'.
'<label for="%s%s"><span title="%s">%s</span></label> <br/>',
stub,z['Name'],stub,z['Name'],stub,z['Name'],z['Reference'],z['DisplayName']),
''),
z=refPhyloProbs)],'\n');
vars['RefPhyloProb1_id'] := 'RefPhyloProb'.refPhyloProbs[1,'Name'];
vars['hasRefPhylo'] := SearchString('<input',vars['RefPhyloProjects'])>=0 and
SearchString('<input',vars['RefPhyloProblems'])>=0;
vars['styleRefPhylo'] := If(vars['hasRefPhylo'] or dataset<>'OMA',
'checked="checked"', 'disabled="disabled"');
# load the semiautomatic TreeCases
testset := 'SemiAuto';
autoPhyloProbs := [seq(GetTreeCase( z, dataset,'testset'=testset ), z=GetAllTreeCases(dataset,'testset'=testset))];
stub := 'pAutoPhyloPrj';
if length(autoPhyloProbs) > 0 then
vars['AutoPhyloProjects'] := ConcatStrings(
[seq(If( length(pairwiseOverlap[pNr])>1,
ProjectCheckbox(pKeys[pNr], sprintf('%s%d', stub, pNr)),
''),
pNr=1..Npub)],'\n');
stub := 'pAutoPhyloProb';
vars['AutoPhyloProblems'] := ConcatStrings(
[seq(If( ProjMetProperty(PID, GetTestProperty(z['Name'])),
sprintf('<input type="checkbox" id="%s%s" name="%s%s" checked="checked" />'.
'<label for="%s%s"><span title="%s">%s</span></label> <br/>',
stub,z['Name'],stub,z['Name'],stub,z['Name'],z['Reference'],z['DisplayName']),
''),
z=autoPhyloProbs)],'\n');
vars['AutoPhyloProb1_id'] := 'AutoPhyloProb'.autoPhyloProbs[1,'Name'];
vars['hasAutoPhylo'] := SearchString('<input',vars['AutoPhyloProjects'])>=0 and
SearchString('<input',vars['AutoPhyloProblems'])>=0;
else
vars['hasAutoPhylo'] := false;
fi:
vars['styleAutoPhylo'] := If(vars['hasAutoPhylo'] or dataset<>'OMA',
'checked="checked"', 'disabled="disabled"');
##################################
# Multi Domain Homology
if dataset='OMA' then
vars['hasHom'] := false;
else
stub := 'pHomPrj';
vars['HomProjects'] := ConcatStrings(
[seq(If( length(pairwiseOverlap[pNr])>1,
ProjectCheckbox(pKeys[pNr], sprintf('%s%d', stub, pNr)),
''),
pNr=1..Npub)],'\n');
stub := 'pHomProb'; name := 'HumMus';
vars['HomProblems'] := sprintf(
'<input type="checkbox" id="%s%s" name="%s%s" checked="checked" />'.
'<label for="%s%s"><span title="%s">%s</span></label> <br/>',
stub, name, stub, name, stub, name, 'Song <i>et al</i>, '.
'PLOS Comp Biol, 2008', 'Multidomain homologs between Human and Mouse');
vars['hasHom'] := SearchString('<input',vars['HomProjects'])>=0;
fi:
vars['styleHom'] := If(vars['hasHom'] or dataset<>'OMA',
'checked="checked"', 'disabled="disabled"');
##################################
# Function based
stub := 'pGOPrj';
vars['GOprojects'] := ConcatStrings(
[seq(If( length(pairwiseOverlap[pNr])>1,
ProjectCheckbox(pKeys[pNr], sprintf('%s%d', stub, pNr)),
''),
pNr=1..Npub)],'\n');
vars['hasGO'] := SearchString('<input',vars['GOprojects'])>=0;
vars['styleGO'] := If(vars['hasGO'] or dataset<>'OMA',
'checked="checked"', 'disabled="disabled"');
stub := 'pECPrj';
vars['ECprojects'] := ConcatStrings(
[seq(If( length(pairwiseOverlap[pNr])>1,
ProjectCheckbox(pKeys[pNr], sprintf('%s%d', stub, pNr)),
''),
pNr=1..Npub)],'\n');
vars['hasEC'] := SearchString('<input',vars['ECprojects'])>=0;
vars['styleEC'] := If(vars['hasEC'] or dataset<>'OMA', 'checked="checked"', 'disabled="disabled"');
vars['PID'] := PID;
return( GenerateTemplate(cdir.'/templates/testSelection.html',vars) );
end:
StartTreeTest := proc(PID:string, king:string, params:list, pnames:list )
fnBase := GetPKeyData(PID)['fnBase'];
lock := sprintf('%s.%s.lock',fnBase,king);
vars := table('');
vars['case'] := king;
vars['idhtml'] := ReplaceString(' ', '', king.' Tree');
vars['resheader'] := king.' Tree';
vars['resFigReady'] := false;
vars['ref'] := GetPKeyData(PID)['ref'];
vars['testRef_Lnk'] := 'http://dx.doi.org/10.1371/journal.pcbi.1000262';
vars['has_Ref'] := true;
vars['testRef_Desc'] := 'Altenhoff and Dessimoz, 2009, <b>Phylogenetic and Functional Assessment of Orthologs Inference Projects and Methods</b> <i>PLoS Computational Biology</i>,5(1): e1000262';
vars['resId'] := 'TT'.king;
projs := [op( {op(GetPublicProjects(vars['ref']))} minus {GetPKeyData(PID)} )];
projs := sort( projs, x->x['Title'] );
is_all_pub := parse(string(ParseParam('pAllPublic', pnames, params, 'default'=false))):
if not is_all_pub then
sel := [seq(If(length(z)>9 and z[1..9]='pTT'.king[1..3].'Prj', parse(z[10..-1]), NULL), z=pnames)];
else
sel := [seq(i,i=1..length(projs))];
fi:
projs := [seq(projs[i,'PID'], i=sel), PID];
vars['PIDs'] := projs:
meth := ParseStrategy(pnames,params):
treebuilder := ParseParam('pSTD_treebuilder', pnames, params, default='LSTree');
resBase := sprintf('TreeTest.%s.%a', king, hash_sha2([projs,meth,treebuilder]));
resFn := sprintf('%s/%s.drw', resdir, resBase );
isRunning := true;
if FileExists(lock) then
vars['content'] := HandleLockFile(lock);
elif FileExists(resFn.'.gz') then
isRunning := false;
HandleBoxRFFiles(meth, resFn, resBase, vars);
else
cmd := sprintf('echo "ReadProgram(''%s/lib/darwinit''): resFn :=''%s'': '.
'problem := ''%s/TreeCat_%s_%s.drw'': projs := %A: lock:=''%s'': meth:=''%s'': '.
'treebuilder := ''%s''; '.
'ReadProgram(''%s/TreeTest.drw''): done:" | nice -n 19 %s &',
cdir, resFn, datdir, king, vars['ref'], projs, lock, meth, treebuilder, cdir, darwin64);
Logger( 'starting TreeTest command: '.cmd, 'INFO');
CallSystem( cmd );
vars['content'] := '<p>Computation started...</p>';
fi:
template := If(vars['hasMultiFig']=true,
'/templates/secResultMultifig.htmlc',
'/templates/secResult.htmlc');
return( [GenerateTemplate(cdir.template, vars), isRunning] );
end:
StartSTDTest := proc(PID:string, problem:string, params:list, pnames:list )
fnBase := GetPKeyData(PID)['fnBase'];
lock := sprintf('%s.STD%s.lock',fnBase, problem);
datasets := ['Eukaryota', 'Fungi', 'Bacteria', 'Vertebrata'];
vars := table('');
for k to length(datasets) while SearchString(problem, datasets[k])<0 do od:
vars['resheader'] := If(k<=length(datasets), datasets[k], problem).' Generalized Species Tree';
vars['idhtml'] := ReplaceString(' ', '', If(k<=length(datasets), datasets[k], problem).' Generalized Species Tree');
vars['resFigReady'] := false;
vars['ref'] := GetPKeyData(PID)['ref'];
vars['testNote'] := '<p>The level 90 species phylogeny assembled by the <a href="http://swisstree.vital-it.ch/species_tree" target="_new">QfO Species Tree Working Group</a> is used as the reference phylogeny.</p>';
vars['testRef_Lnk'] := '';
vars['has_Ref'] := false;
vars['testRef_Desc'] := '';
vars['resId'] := 'STD'.problem;
projs := [op( {op(GetPublicProjects(vars['ref']))} minus {GetPKeyData(PID)} )];
projs := sort( projs, x->x['Title'] );
is_all_pub := parse(string(ParseParam('pAllPublic', pnames, params, 'default'=false))):
if not is_all_pub then
baseParam := 'pSTD'.problem.'Prj';
lenBaseParam := length(baseParam);
sel := [seq(If(length(z)>lenBaseParam and z[1..lenBaseParam]=baseParam,
parse(z[lenBaseParam+1..-1]), NULL), z=pnames)];
else
sel := [seq(i,i=1..length(projs))];
fi:
projs := [seq(projs[i,'PID'], i=sel), PID];
vars['PIDs'] := projs:
meth := ParseStrategy(pnames,params):
conf_int := parse(string(ParseParam('pSTDconf', pnames, params, 'default'=71)));
conf_str := sprintf('_conf%d', conf_int);
treebuilder := ParseParam('pSTD_treebuilder', pnames, params, default='LSTree');
resBase := sprintf('STDTest.%a', hash_sha2([problem,projs,meth,conf_str,treebuilder]));
resFn := sprintf('%s/%s.drw', resdir, resBase );
isRunning := true;
if FileExists(lock) then
vars['content'] := HandleLockFile(lock);
elif FileExists(resFn.'.gz') then
isRunning := false;
HandleBoxRFFiles(meth, resFn, resBase, vars);
else
cmd := sprintf('echo "ReadProgram(''%s/lib/darwinit''): resFn :=''%s'': '.
'projs := %A: lock:=''%s'': meth:=''%s'': problem := ''%s'': '.
'confidence := %d: treebuilder := ''%s'': '.
'ReadProgram(''%s/SpeciesTreeDiscordanceTest.drw''): done:" | nice -n 19 %s &',
cdir, resFn, projs, lock, meth, problem, conf_int, treebuilder, cdir, darwin64);
Logger( 'starting STDTreeTest command: '.cmd, 'INFO');
CallSystem( cmd );
vars['content'] := '<p>Computation started...</p>';
fi:
template := If(vars['hasMultiFig']=true,
'/templates/secResultMultifig.htmlc',
'/templates/secResult.htmlc');
return( [GenerateTemplate(cdir.template, vars), isRunning] );
end:
StartRefPhyloTest := proc(PID:string, params:list, pnames:list ;
'testset'=((testset='Ref'):{'Ref','Auto'}) )
fnBase := GetPKeyData(PID)['fnBase'];
lock := sprintf('%s.%sPhyl.lock',fnBase,testset);
vars := table('');
if testset='Ref' then
vars['resheader'] := 'Agreement with Reference Gene Phylogenies: <a href="http://wiki.isb-sib.ch/swisstree" target="_new">SwissTrees</a>';
vars['idhtml'] := ReplaceString(' ', '','Agreement with Reference Gene');
vars['has_Ref'] := true;
vars['testRef_Lnk'] := 'http://dx.doi.org/10.1093/bib/bbr034';
vars['testRef_Desc'] := 'Brigitte Boeckmann, Marc Robinson-Rechavi, Ioannis Xenarios, Christophe Dessimoz, 2011 <b>Conceptual Framework and Pilot Study to Benchmark Phylogenomic Databases Based on Reference Gene Trees</b> <i>Briefings in Bioinformatics</i>, 12:5 (pp. 474-484).';
vars['testNote'] := '<p>A detailed description of our implementation is provided <a href="/doc/refGeneTrees.pdf">here</a></p>';
elif testset='Auto' then
vars['idhtml'] := 'Semi-automated';
vars['resheader'] := 'Agreement with Reference Gene Phylogenies: TreeFam-A';
vars['testRef_Lnk'] := 'http://dx.doi.org/10.1093/nar/gkj118';
vars['has_Ref'] := true;
vars['testRef_Desc'] := 'Heng Li <i>et. al</i>, 2006 <b>TreeFam: a curated database of phylogenetic trees of animal gene families</b> <i>Nucl. Acids Res.</i>, 34(suppl 1): D572-D580 484';
vars['testNote'] := '<p>A detailed description of our implementation is provided <a href="/doc/refGeneTrees.pdf">here</a></p>';
fi:
vars['resFigReady'] := false;
vars['ref'] := GetPKeyData(PID)['ref'];
projs := [op( {op(GetPublicProjects(vars['ref']))} minus {GetPKeyData(PID)} )];
projs := sort( projs, x->x['Title'] );
is_all_pub := parse(string(ParseParam('pAllPublic', pnames, params, 'default'=false))):
if not is_all_pub then
prefix := sprintf('p%sPhyloPrj', testset);
sel := ParseAllPrefixParams( prefix, pnames, params, 'onlyIf'='on');
else
sel := [seq(i,i=1..length(projs))];
fi:
projs := [seq(projs[i,'PID'], i=sel), PID];
vars['PIDs'] := projs:
k := SearchArray( sprintf('p%sPhylAggMeas',testset), pnames );
measure := If(k>0,params[k],'sample variance');
meth := ParseStrategy(pnames,params):
prefix := sprintf('p%sPhyloProb', testset);
problems := ParseAllPrefixParams( prefix, pnames, params, 'onlyIf'='on' );
resBase := sprintf('%sPhyl.%a', testset, hash_sha2([projs,measure,problems,meth]) );
resFn := sprintf('%s/%s.drw', resdir, resBase );
isRunning := true;
if FileExists(lock) then
vars['content'] := HandleLockFile(lock);
elif FileExists(resFn.'.gz') then
isRunning := false;
Handle2dROCFiles(meth, resFn, resBase, problems, projs, vars, 'aggregate'=measure);
else
cmd := sprintf('echo "ReadProgram(''%s/lib/darwinit''): resFn :=%A: '.
'projs := %A: lock := %A: problems := %A: measure := %A: meth := %A: '.
'testset := %A: ReadProgram(''%s/RefPhyloTest.drw''): done:" '.
'| nice -n 19 %s &',
cdir, resFn, projs, lock, problems, measure, meth, testset, cdir, darwin64);
Logger( 'starting RefPhylo command: '.cmd, 'INFO');
CallSystem( cmd );
WriteLog('started command: '.cmd);
vars['content'] := '<p>Computation started...</p>';
fi:
Logger(sprintf('%a',vars),'INFO'):
return( [GenerateTemplate(cdir.'/templates/secResult.htmlc', vars), isRunning] );
end:
StartEcTest := proc(PID:string, params:list, pnames:list)
fnBase := GetPKeyData(PID)['fnBase'];
lock := sprintf('%s.EC.lock',fnBase);
vars := table('');
vars['resheader'] := 'Enzyme Classification (EC) conservation test';
vars['resFigReady'] := false;
vars['idhtml'] := 'EnzymeClassification(EC)';
vars['ref'] := GetPKeyData(PID)['ref'];
vars['testRef_Lnk'] := 'http://dx.doi.org/10.1371/journal.pcbi.1000262';
vars['has_Ref'] := true;
vars['testRef_Desc'] := 'Altenhoff and Dessimoz, 2009, <b>Phylogenetic and Functional Assessment of Orthologs Inference Projects and Methods</b> <i>PLoS Computational Biology</i>,5(1): e1000262';
projs := [op( {op(GetPublicProjects(vars['ref']))} minus {GetPKeyData(PID)} )];
projs := sort( projs, x->x['Title'] );
is_all_pub := parse(string(ParseParam('pAllPublic', pnames, params, 'default'=false))):
if not is_all_pub then
sel := [seq(If(length(z)>6 and z[1..6]='pECPrj', parse(z[7..-1]), NULL), z=pnames)];
else
sel := [seq(i,i=1..length(projs))];
fi:
projs := [seq(projs[i,'PID'], i=sel), PID];
vars['PIDs'] := projs:
measure := ParseParam('pECMeasure', pnames, params, default='avg Schlicker');
meth := ParseStrategy(pnames,params):
resBase := sprintf('EC.%a', hash_sha2([projs,measure,meth]) );
resFn := sprintf('%s/%s.drw', resdir, resBase );
isRunning := true;
if FileExists(lock) then
vars['content'] := HandleLockFile(lock);
elif FileExists(resFn.'.gz') then
isRunning := false;
Handle2dSimFiles(meth, resFn, resBase, vars, 'measure'=measure);
else
cmd := sprintf('echo "ReadProgram(''%s/lib/darwinit''): resFn :=%A: '.
'projs := %A: lock:=%A: measure:=%A: meth:=%A: '.
'ReadProgram(''%s/EcTest.drw''): done;" | nice -n 19 %s &',
cdir, resFn, projs, lock, measure, meth, cdir, darwin64);
Logger( 'starting EcTest command: '.cmd, 'INFO');
CallSystem( cmd );
vars['content'] := '<p>Computation started...</p>';
fi:
return( [GenerateTemplate(cdir.'/templates/secResult.htmlc', vars), isRunning] );
end:
StartGoTest := proc(PID:string, params:list, pnames:list)
fnBase := GetPKeyData(PID)['fnBase'];
lock := sprintf('%s.GO.lock',fnBase);
vars := table('');
vars['resheader'] := 'Gene Ontology conservation test';
vars['resFigReady'] := false;
vars['ref'] := GetPKeyData(PID)['ref'];
vars['idhtml'] := 'GeneOntologyconservation';
vars['testRef_Lnk'] := 'http://dx.doi.org/10.1371/journal.pcbi.1000262';
vars['has_Ref'] := true;
vars['testRef_Desc'] := 'Altenhoff and Dessimoz, 2009, <b>Phylogenetic and Functional Assessment of Orthologs Inference Projects and Methods</b> <i>PLoS Computational Biology</i>,5(1): e1000262';
exEv := {EXP,IDA,IPI,IMP,IGI,IEP,ISS,ISO,ISA,ISM,IGC,IBA,IBD,IKR,IRD,RCA,TAS,NAS,IEA,IC,NR};
projs := [op( {op(GetPublicProjects(vars['ref']))} minus {GetPKeyData(PID)} )];
projs := sort( projs, x->x['Title'] );
is_all_pub := parse(string(ParseParam('pAllPublic', pnames, params, 'default'=false))):
if not is_all_pub then
sel := [seq(If(length(z)>6 and z[1..6]='pGOPrj',
parse(z[7..-1]), NULL), z=pnames)];
else
sel := [seq(i,i=1..length(projs))];
fi:
projs := [seq(projs[i,'PID'], i=sel), PID];
vars['PIDs'] := projs:
filter := {seq( If(length(z)>6 and z[1..6]='pGOFil',
parse(z[7..-1]),NULL), z=pnames)};
filter := intersect(filter, exEv);
measure := ParseParam('pGOMeasure', pnames, params, default='avg Schlicker');
meth := ParseStrategy(pnames,params):
resBase := sprintf('GO.%a', hash_sha2([projs,filter,measure,meth]) );
resFn := sprintf('%s/%s.drw', resdir, resBase );
isRunning := true;
if FileExists(lock) then
vars['content'] := HandleLockFile(lock);
elif FileExists(resFn.'.gz') then
isRunning := false;
Handle2dSimFiles(meth, resFn, resBase, vars, 'measure'=measure);
else
cmd := sprintf('echo "ReadProgram(''%s/lib/darwinit''): resFn :=%A: filter := %A:'.
'projs := %A: lock:=%A: measure:=%A: meth := %A: '.
'ReadProgram(''%s/GoTest.drw''): done:" | nice -n 19 %s &',
cdir, resFn, filter, projs, lock, measure, meth, cdir, darwin64);
Logger( 'starting GoTest command: '.cmd, 'INFO');
CallSystem( cmd );
vars['content'] := '<p>Computation started...</p>';
fi:
return( [GenerateTemplate(cdir.'/templates/secResult.htmlc', vars),isRunning] );
end:
StartHomologyTest := proc(PID:string, params:list, pnames:list)
fnBase := GetPKeyData(PID)['fnBase'];
lock := sprintf('%s.Homology.lock',fnBase);
vars := table('');
vars['idhtml'] := 'Multi-Domain';
vars['resheader'] := 'Correct Homology Detection of Multi-Domain Proteins';
vars['contributor'] := '';
vars['has_Ref'] := false;
vars['pubref'] := '';
vars['testNote'] := '<p>A description of the implementation is provided <a href="/doc/homologyBenchmark.pdf">here</a></p>';
vars['resFigReady'] := false;
vars['ref'] := GetPKeyData(PID)['ref'];
projs := [op( {op(GetPublicProjects(vars['ref']))} minus {GetPKeyData(PID)} )];
projs := sort( projs, x->x['Title'] );
is_all_pub := parse(string(ParseParam('pAllPublic', pnames, params, 'default'=false))):
if not is_all_pub then
sel := [seq(If(length(z)>7 and z[1..7]='pHomPrj', parse(z[8..-1]), NULL), z=pnames)];
else
sel := [seq(i,i=1..length(projs))]:
fi:
projs := [seq(projs[i,'PID'], i=sel), PID];
meth := ParseStrategy(pnames,params):
measure := ParseParam('pHomAggMeas', pnames, params, 'default'='sample variance');
problems := ParseAllPrefixParams( 'pHomProb', pnames, params, 'onlyIf'='on');
resBase := sprintf('Homology.%a', hash_sha2([projs,problems,measure,meth]) );
resFn := sprintf('%s/%s.drw', resdir, resBase );
isRunning := true;
if FileExists(lock) then
vars['content'] := HandleLockFile(lock);
elif FileExists(resFn.'.gz') then
isRunning := false;
Handle2dROCFiles(meth, resFn, resBase, problems, projs, vars,
'aggregate'=measure,'FPRLabel'='coverage',
'TPRLabel'='false discovery rate');
else
cmd := sprintf('echo "ReadProgram(''%s/lib/darwinit''): resFn :=%A: '.
'projs := %A: problems := %A: measure := %A: lock:=%A: meth:=%A: '.
'ReadProgram(''%s/HomologyTest.drw''): done:" | nice -n 19 %s &',
cdir, resFn, projs, problems, measure, lock, meth, cdir, darwin64);
Logger( 'starting HomologyTest command: '.cmd, 'INFO');
CallSystem( cmd );
vars['content'] := '<p>Computation started...</p>';
fi:
return( [GenerateTemplate(cdir.'/templates/secResult.htmlc', vars), isRunning] );
end:
#################################
# Run Tests #
#################################
bsRunTests := proc(params_:list, pnames_:list)
pnames := pnames_; params := params_;
if length(params) <> length(pnames) then
error('unexpected parameters'); fi;
email_pos := SearchArray('pEmail', pnames);
if email_pos > 0 then
email := params[email_pos];
pnames := [op(pnames[1..email_pos-1]), op(pnames[email_pos+1..-1])];
params := [op(params[1..email_pos-1]), op(params[email_pos+1..-1])];
else email := '';
fi:
h := string(hash_sha2( [params, pnames] ));
OpenWriting( sessiondir.h );
printf('# %s\n__SessionParams:=%A:\n__SessionPnames:=%A:\n', date(), params, pnames);
OpenWriting(previous);
if email='' then
pKey := GetPKeyData(ParseParam('pPID', pnames, params));
email := pKey['email'];
fi:
if email<>'' then
test_result_url := 'http://'.host.'/cgi-bin/gateway.pl?f=CheckResults&p1='.h;
msg := 'The orthology benchmarking results for the parameters you selected '.
'will be available on the following page for you: '.test_result_url.
'\n\nWe thank you for using the benchmarking webservice.';
traperror(SendEMail(msg, email, 'Link to benchmark results'));
fi:
return('Location: gateway.pl?f=CheckResults&p1='.h.'\n\n');
end:
bsCheckResults := proc(sessionkey)
global __SessionParams, __SessionPnames;
__SessionParams := __SessionPnames := 0;
fn := sessiondir.string(sessionkey);
Logger( 'SessionFile: '.fn, 'DEBUG');
traperror(ReadProgram( fn ));
if __SessionParams=0 or __SessionPnames=0 then
Logger( sprintf('Session loading failed: %A, %A, %s',
__SessionParams,__SessionParams,lasterror), 'ERROR');
error('could not load session information') fi;
pnames := __SessionPnames; params := __SessionParams;
PID := params[SearchArray('pPID',pnames)];
vars := table('');
pData := GetPKeyData(PID):
if pData['ref']='OMA' or not pData['isPublic'] then
vars['tit'] := pData['Title'];
fi:
vars['sessionkey'] := string(sessionkey);
refresh := false;
for problem in ['Eukaryota','Fungi','Bacteria'] do
short := problem[1..3];
k := SearchArray('pTT'.short.'1', pnames);
if k>0 and params[k]='on' then
# do traditional species tree discordance test
t := StartTreeTest(PID,problem,params, pnames);
vars['TT'.short.'1'] := t[1];
if t[2]=true then refresh := true fi:
fi;
od:
for problem in ['Luca','Euk','Ver','Fun'] do
k := SearchArray('pSTD'.problem.'1', pnames);
if k>0 and params[k]='on' then
# do large species tree discordance test
t := StartSTDTest(PID,problem,params,pnames);
vars['STD'.problem.'1'] := t[1];
if t[2]=true then refresh := true fi:
fi;
od:
k := SearchArray('pRefPhylo1', pnames);
if k>0 and params[k]='on' then
# do reference gene phylogenies based test
t := StartRefPhyloTest(PID, params, pnames);
vars['RefPhylo'] := t[1];
if t[2]=true then refresh := true fi:
fi;
k := SearchArray('pAutoPhylo1', pnames);
if k>0 and params[k]='on' then
# do semi-auto reference gene phylogenies based test
t := StartRefPhyloTest(PID, params, pnames,'testset'='Auto');
vars['AutoPhylo'] := t[1];
if t[2]=true then refresh := true fi:
fi;
k := SearchArray('pHom1', pnames);
if k>0 and params[k]='on' then
t := StartHomologyTest(PID, params, pnames);
vars['Hom'] := t[1];
if t[2]=true then refresh := true fi:
fi:
k := SearchArray('pGO1',pnames);
if k>0 and params[k]='on' then
t := StartGoTest(PID, params, pnames);
vars['GO'] := t[1];
if t[2]=true then refresh := true fi:
fi:
k := SearchArray('pEC1', pnames);
if k>0 and params[k]='on' then
t := StartEcTest(PID,params, pnames);
vars['EC'] := t[1];
if t[2]=true then refresh := true fi:
fi:
if refresh then vars['reloadin'] := 120 fi;
vars['refresh'] := refresh;
return( GenerateTemplate(cdir.'/templates/testResults.html', vars) );
end:
##########################################
# Not yet implemented functions #
##########################################
NotImplemented := proc(text:string)
vars := table('');
vars['function'] := text;
return(GenerateTemplate(cdir.'/templates/notimpl.html',vars));
end:
# -------------------------------------------------------------------------
printlevel := 2;
if DEBUG then
Cookies := table(NULL);
printlevel := 10;
else
lprint('Server started, pid =',getpid());
RunServer()
fi;