-
Notifications
You must be signed in to change notification settings - Fork 28
/
gui.py
2288 lines (1889 loc) · 93.1 KB
/
gui.py
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
991
992
993
994
995
996
997
998
999
1000
# Copyright (C) 2009-2020, Ecole Polytechnique Federale de Lausanne (EPFL) and
# Hospital Center and University of Lausanne (UNIL-CHUV), Switzerland
# All rights reserved.
#
# This software is distributed under the open-source license Modified BSD.
"""Connectome Mapper GUI."""
# General imports
import os
import sys
import pkg_resources
from subprocess import Popen
import subprocess
import multiprocessing
import shutil
import time
import glob
from pyface.api import ImageResource
from traitsui.qt4.extra.qt_view import QtView
from traitsui.tabular_adapter import TabularAdapter
from traitsui.api import *
from traits.api import *
from bids import BIDSLayout
import warnings
# Own imports
import cmp.bidsappmanager.project as project
from cmp.project import CMP_Project_Info
from cmp.info import __version__
from cmp.pipelines.diffusion.diffusion import DiffusionPipeline
from cmp.pipelines.functional.fMRI import fMRIPipeline
from cmtklib.util import return_button_style_sheet
# Remove warnings visible whenever you import scipy (or another package)
# that was compiled against an older numpy than is installed.
warnings.filterwarnings("ignore", message="numpy.dtype size changed")
warnings.filterwarnings("ignore", message="numpy.ufunc size changed")
# global modal_width
modal_width = 400
# global style_sheet
style_sheet = '''
QLabel {
font: 12pt "Verdana";
margin-left: 5px;
background-color: transparent;
}
QPushButton {
border: 0px solid lightgray;
border-radius: 4px;
color: transparent;
background-color: transparent;
min-width: 222px;
icon-size: 222px;
font: 12pt "Verdana";
margin: 0px 0px 0px 0px;
padding:0px 0px;
}
QPushButton:pressed {
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #dadbde, stop: 1 #f6f7fa);
}
QMenuBar {
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #dadbde, stop: 1 #f6f7fa)
font: 14pt "Verdana";
}
QMenuBar::item {
spacing: 5px; /* spacing between menu bar items */
padding: 5px 5px;
background: transparent;
border-radius: 4px;
}
QMenuBar::item:selected { /* when selected using mouse or keyboard */
background: #a8a8a8;
}
QMenuBar::item:pressed {
background: #888888;
}
QMainWindow {
background-color: yellow;
image: url("images/cmp.png");
}
QMainWindow::separator {
background: yellow;
width: 1px; /* when vertical */
height: 1px; /* when horizontal */
}
QMainWindow::separator:hover {
background: red;
}
QListView::item:selected {
border: 1px solid #6a6ea9;
}
QListView::item:selected:!active {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #ABAFE5, stop: 1 #8588B2);
}
QListView::item:selected:active {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #6a6ea9, stop: 1 #888dd9);
}
QListView::item:hover {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #FAFBFE, stop: 1 #DCDEF1);
}
QProgressBar {
border: 2px solid grey;
border-radius: 5px;
}
QProgressBar::chunk {
background-color: #05B8CC;
width: 20px;
}
'''
def get_icon(path):
"""Return an instance of `ImageResource` or None is there is not graphical backend.
Parameters
----------
path : string
Path to an image file
Returns
-------
icon : ImageResource
Return an instance of `ImageResource` or None is there is not graphical backend.
"""
on_rtd = os.environ.get("READTHEDOCS") == "True"
if on_rtd:
print('READTHEDOCS: Return None for icon')
icon = None
else:
icon = ImageResource(path)
return icon
class CMP_Project_InfoUI(CMP_Project_Info):
"""Class that extends the :class:`CMP_Project_Info` with graphical components.
It supports graphically the setting of all processing properties / attributes
of an :class:`CMP_Project_Info` instance.
Attributes
-----------
creation_mode : traits.Enum
Mode for loading the dataset. Valid values are
'Load BIDS dataset', 'Install Datalad BIDS dataset'
install_datalad_dataset_via_ssh : traits.Bool
If set to True install the datalad dataset from a remote server
via ssh.(True by default)
ssh_user : traits.Str
Remote server username.
(Required if ``install_datalad_dataset_via_ssh`` is True)
ssh_pwd <traits.Password>
Remote server password.
(Required if ``install_datalad_dataset_via_ssh`` is True)
ssh_remote : traits.Str
Remote server IP or URL.
(Required if ``install_datalad_dataset_via_ssh`` is True)
datalad_dataset_path : traits.Directory
Path to the datalad dataset on the remote server.
(Required if ``install_datalad_dataset_via_ssh`` is True)
summary_view_button : traits.ui.Button
Button that shows the pipeline processing summary table
pipeline_processing_summary_view : traits.ui.VGroup
TraitsUI VGroup that contains ``Item('pipeline_processing_summary')``
dataset_view : traits.ui.View
TraitsUI View that shows a summary of project settings and
modality available for a given subject
traits_view : QtView
TraitsUI QtView that includes the View 'dataset_view'
create_view : traits.ui.View
Dialog view to create a BIDS Dataset
subject_view : traits.ui.View
Dialog view to select of subject
subject_session_view : traits.ui.View
Dialog view to select the subject session
dmri_bids_acq_view : traits.ui.View
Dialog view to select the diffusion acquisition model
anat_warning_view : traits.ui.View
View that displays a warning message regarding
the anatomical T1w data
anat_config_error_view : traits.ui.View
Error view that displays an error message regarding
the configuration of the anatomical pipeline
dmri_warning_view : traits.ui.View
View that displays a warning message regarding
the diffusion MRI data
dmri_config_error_view : traits.ui.View
View that displays an error message regarding
the configuration of the diffusion pipeline
fmri_warning_view : traits.ui.View
View that displays a warning message regarding
the functional MRI data
fmri_config_error_view : traits.ui.View
View that displays an error message regarding
the configuration of the fMRI pipeline
open_view : traits.ui.View
Dialog view to load a BIDS Dataset
anat_select_config_to_load : traits.ui.View
Dialog view to load the configuration file of the anatomical pipeline
diffusion_imaging_model_select_view : traits.ui.View
Dialog view to select the diffusion acquisition model
dmri_select_config_to_load : traits.ui.View
Dialog view to load the configuration file of the diffusion MRI pipeline
fmri_select_config_to_load : traits.ui.View
Dialog view to load the configuration file of the fMRI pipeline
"""
creation_mode = Enum('Load BIDS dataset', 'Install Datalad BIDS dataset')
install_datalad_dataset_via_ssh = Bool(True)
ssh_user = String('remote_username')
ssh_pwd = Password('')
ssh_remote = String('IP address/ Machine name')
datalad_dataset_path = Directory(
'/shared/path/to/existing/datalad/dataset')
anat_runs = List()
anat_run = Enum(values='anat_runs')
dmri_runs = List()
dmri_run = Enum(values='dmri_runs')
fmri_runs = List()
fmri_run = Enum(values='fmri_runs')
summary_view_button = Button('Pipeline processing summary')
pipeline_processing_summary_view = VGroup(Item('pipeline_processing_summary'))
dataset_view = VGroup(
VGroup(
HGroup(
Item('base_directory', width=-0.3,
style='readonly', label="", resizable=True),
Item('number_of_subjects',
width=-0.3,
style='readonly',
label="Number of participants",
resizable=True),
'summary_view_button'),
label='BIDS Dataset'),
spring,
HGroup(
Group(
Item('subject', style='simple',
show_label=True, resizable=True)),
Group(
Item('subject_session', style='simple',
label="Session", resizable=True),
visible_when='subject_session!=""'),
springy=True),
spring,
Group(
Item('t1_available', style='readonly', label='T1', resizable=True),
HGroup(
Item('dmri_available', style='readonly',
label='Diffusion', resizable=True),
Item('diffusion_imaging_model', label='Model',
resizable=True, enabled_when='dmri_available')),
Item('fmri_available', style='readonly',
label='BOLD', resizable=True),
label='Modalities'),
spring,
Group(
Item('anat_last_date_processed', label="Anatomical pipeline",
style='readonly', resizable=True,
enabled_when='t1_available'),
Item('dmri_last_date_processed', label="Diffusion pipeline",
style='readonly', resizable=True,
enabled_when='dmri_available'),
Item('fmri_last_date_processed', label="fMRI pipeline",
style='readonly', resizable=True,
enabled_when='fmri_available'),
label="Last date processed"),
spring,
Group(
Item('number_of_cores', resizable=True),
label='Processing configuration'),
'550',
spring,
springy=True)
traits_view = QtView(Include('dataset_view'))
create_view = View(
Item('creation_mode', style='custom'),
Group(
Group(
Item('base_directory', label='BIDS Dataset'),
visible_when='creation_mode=="Load BIDS dataset"'),
Group(
Item('install_datalad_dataset_via_ssh'),
visible_when='creation_mode=="Install Datalad/BIDS dataset"'),
Group(
Item('ssh_remote', label='Remote ssh server',
visible_when='install_datalad_dataset_via_ssh'),
Item('ssh_user', label='Remote username',
visible_when='install_datalad_dataset_via_ssh'),
Item('ssh_pwd', label='Remote password',
visible_when='install_datalad_dataset_via_ssh'),
Item('datalad_dataset_path',
label='Datalad/BIDS Dataset Path/URL to be installed'),
Item('base_directory', label='Installation directory'),
visible_when='creation_mode=="Install Datalad/BIDS dataset"'),
),
kind='livemodal',
title='Data creation: BIDS dataset selection',
# style_sheet=style_sheet,
width=modal_width,
buttons=['OK', 'Cancel'])
subject_view = View(
Group(
Item('subject', label='Selected Subject')
),
kind='modal',
title='Subject and session selection',
# style_sheet=style_sheet,
width=modal_width,
buttons=['OK', 'Cancel'])
subject_session_view = View(
Group(
Item('subject', style='readonly', label='Selected Subject'),
Item('subject_session', label='Selected Session'),
),
kind='modal',
title='Session selection',
# style_sheet=style_sheet,
width=modal_width,
buttons=['OK', 'Cancel'])
dmri_bids_acq_view = View(
Group(
Item('dmri_bids_acq', label='Selected model'),
),
kind='modal',
title='Selection of diffusion acquisition model',
# style_sheet=style_sheet,
width=modal_width,
buttons=['OK', 'Cancel'])
anat_warning_view = View(
Group(
Item('anat_warning_msg', style='readonly', show_label=False),
),
title='Warning : Anatomical T1w data',
kind='modal',
width=modal_width,
# style_sheet=style_sheet,
buttons=['OK', 'Cancel'])
anat_config_error_view = View(
Group(
Item('anat_config_error_msg', style='readonly', show_label=False),
),
title='Error',
kind='modal',
width=modal_width,
# style_sheet=style_sheet,
buttons=['OK', 'Cancel'])
dmri_warning_view = View(
Group(
Item('dmri_warning_msg', style='readonly', show_label=False),
),
title='Warning : Diffusion MRI data',
kind='modal',
width=modal_width,
# style_sheet=style_sheet,
buttons=['OK', 'Cancel'])
dmri_config_error_view = View(
Group(
Item('dmri_config_error_msg', style='readonly', show_label=False),
),
title='Error',
kind='modal',
width=modal_width,
# style_sheet=style_sheet,
buttons=['OK', 'Cancel'])
fmri_warning_view = View(
Group(
Item('fmri_warning_msg', style='readonly', show_label=False),
),
title='Warning : fMRI data',
kind='modal',
width=modal_width,
# style_sheet=style_sheet,
buttons=['OK', 'Cancel'])
fmri_config_error_view = View(
Group(
Item('fmri_config_error_msg', style='readonly', show_label=False),
),
title='Error',
kind='modal',
width=modal_width,
# style_sheet=style_sheet,
buttons=['OK', 'Cancel'])
open_view = View(
Item('creation_mode', label='Mode'),
Group(
Item('install_datalad_dataset_via_ssh'),
Item('ssh_remote', label='Remote ssh server',
visible_when='install_datalad_dataset_via_ssh'),
Item('ssh_user', label='Remote username',
visible_when='install_datalad_dataset_via_ssh'),
Item('ssh_pwd', label='Remote password',
visible_when='install_datalad_dataset_via_ssh'),
Item('datalad_dataset_path',
label='Datalad/BIDS Dataset Path/URL to be installed'),
Item('base_directory', label='Installation directory'),
visible_when='creation_mode=="Install Datalad BIDS dataset"'),
Group(
Item('base_directory', label='BIDS Dataset'),
visible_when='creation_mode=="Load BIDS dataset"'),
kind='livemodal',
title='BIDS Dataset Creation/Loading',
# style_sheet=style_sheet,
width=600,
height=250,
buttons=['OK', 'Cancel'])
anat_select_config_to_load = View(
Group(
Item('anat_config_to_load_msg', style='readonly', show_label=False),
Item('anat_config_to_load', style='custom', editor=EnumEditor(name='anat_available_config'),
show_label=False)
),
title='Select configuration for anatomical pipeline',
kind='modal',
width=modal_width,
# style_sheet=style_sheet,
buttons=['OK', 'Cancel'])
anat_custom_map_view = View(
Group(
Item('anat_custom_last_stage', editor=EnumEditor(name='anat_stage_names'), style='custom',
show_label=False),
),
title='Select until which stage to process the anatomical pipeline.',
kind='modal',
width=modal_width,
# style_sheet=style_sheet,
buttons=['OK', 'Cancel'])
diffusion_imaging_model_select_view = View(
Group(
Item('diffusion_imaging_model', label='Diffusion MRI modality'),
),
title='Please select diffusion MRI modality',
kind='modal',
width=modal_width,
buttons=['OK', 'Cancel'])
dmri_select_config_to_load = View(
Group(
Item('dmri_config_to_load_msg', style='readonly', show_label=False),
),
Item('dmri_config_to_load', style='custom', editor=EnumEditor(
name='dmri_available_config'), show_label=False),
title='Select configuration for diffusion pipeline',
kind='modal',
width=modal_width,
# style_sheet=style_sheet,
buttons=['OK', 'Cancel'])
dmri_custom_map_view = View(
Group(
Item('dmri_custom_last_stage', editor=EnumEditor(name='dmri_stage_names'), style='custom',
show_label=False),
),
title='Select until which stage to process the diffusion pipeline.',
kind='modal',
width=modal_width,
# style_sheet=style_sheet,
buttons=['OK', 'Cancel'])
fmri_select_config_to_load = View(
Group(
Item('fmri_config_to_load_msg', style='readonly', show_label=False),
),
Item('fmri_config_to_load', style='custom', editor=EnumEditor(
name='fmri_available_config'), show_label=False),
title='Select configuration for fMRI pipeline',
kind='modal',
width=modal_width,
# style_sheet=style_sheet,
buttons=['OK', 'Cancel'])
fmri_custom_map_view = View(
Group(
Item('fmri_custom_last_stage', editor=EnumEditor(name='fmri_stage_names'), style='custom',
show_label=False),
),
title='Select until which stage to process the fMRI pipeline.',
kind='modal',
width=modal_width,
# style_sheet=style_sheet,
buttons=['OK', 'Cancel'])
def _summary_view_button_fired(self):
self.configure_traits(view='pipeline_processing_summary_view')
class MultiSelectAdapter(TabularAdapter):
"""This adapter is used by both the left and right tables."""
# Titles and column names for each column of a table.
# In this example, each table has only one column.
columns = [('', 'myvalue')]
width = 100
# Magically named trait which gives the display text of the column named
# 'myvalue'. This is done using a Traits Property and its getter:
myvalue_text = Property
def _get_myvalue_text(self):
"""The getter for Property 'myvalue_text'.
It simply takes the value of the corresponding item in the list
being displayed in this table. A more complicated example could
format the item before displaying it.
"""
return 'sub-%s' % self.item
class CMP_BIDSAppWindow(HasTraits):
"""Class that defines the Window of the BIDS App Interface.
Attributes
----------
project_info : CMP_Project_Info
Instance of :class:`CMP_Project_Info` that represents the processing project
bids_root : traits.Directory
BIDS root dataset directory
output_dir : traits.Directory
Output directory
subjects : traits.List
List of subjects (in the form ``sub-XX``) present in the dataset
number_of_participants_processed_in_parallel : traits.Range
Number of participants / subjects to be processed in parallel that
takes values in the [1, # of CPUs - 1] range
number_threads_max : traits.Int
Maximal number of threads to be used by OpenMP programs
(4 by default)
number_of_threads : traits.Range
Number of threads to be used by OpenMP programs that takes values
in the [1, ``number_threads_max``] range
fs_file : traits.File
Path to Freesurfer license file
list_of_subjects_to_be_processed <List(Str)>
Selection of subjects to be processed from the ``subjects`` list
anat_config : traits.File
Configuration file for the anatomical MRI pipeline
dmri_config : traits.File
Configuration file for the diffusion MRI pipeline
fmri_config : traits.File
Configuration file for the functional MRI pipeline
run_anat_pipeline : traits.Bool
If True, run the anatomical pipeline
run_dmri_pipeline : traits.Bool
If True, run the diffusion pipeline
run_fmri_pipeline : traits.Bool
If True, run the functional pipeline
bidsapp_tag : traits.Enum
Selection of BIDS App version to use
data_provenance_tracking : traits.Bool
If set and if ``datalad_is_available`` is True run the BIDS App
using datalad (False by default)
datalad_update_environment : traits.Bool
If True and ``data_provenance_tracking`` is True, tell to datalad
to update the BIDS App container image if there was a previous
execution (True by default)
datalad_is_available : traits.Bool
Boolean used to store if datalad is available in the computing
environment (False by default)
check : traits.ui.Button
Button to check if all parameters are properly set for execution
of the BIDS App
start_bidsapp : traits.ui.Button
Button to run the BIDS App
traits_view : QtView
TraitsUI QtView that describes the content of the window
"""
project_info = Instance(CMP_Project_Info)
bids_root = Directory()
output_dir = Directory()
subjects = List(Str)
# multiproc_number_of_cores = Int(1)
number_of_participants_processed_in_parallel = Range(low=1,
high=multiprocessing.cpu_count()-1,
desc='Number of participants to be processed in parallel')
number_of_threads_max = Int(4)
number_of_threads = Range(low=1,
high='number_of_threads_max',
desc='Number of threads used by ANTs registration'
'and Freesurfer recon-all')
fs_license = File()
# fs_average = Directory(os.path.join(os.environ['FREESURFER_HOME'],'subjects','fsaverage'))
list_of_subjects_to_be_processed = List(Str)
list_of_processing_logfiles = List(File)
anat_config = File()
dmri_config = File()
fmri_config = File()
run_anat_pipeline = Bool(True)
run_dmri_pipeline = Bool(True)
run_fmri_pipeline = Bool(True)
dmri_inputs_checked = Bool(False)
fmri_inputs_checked = Bool(False)
settings_checked = Bool(False)
docker_running = Bool(False)
bidsapp_tag = Enum('{}'.format(__version__), [
'latest', '{}'.format(__version__)])
data_provenance_tracking = Bool(False)
datalad_update_environment = Bool(True)
datalad_is_available = Bool(False)
# check = Action(name='Check settings!',
# action='check_settings',
# image=get_icon(
# pkg_resources.resource_filename('resources',
# os.path.join('buttons', 'bidsapp-check-settings.png'))))
# start_bidsapp = Action(name='Start BIDS App!',
# action='start_bids_app',
# enabled_when='settings_checked==True and docker_running==False',
# image=get_icon(
# pkg_resources.resource_filename('resources',
# os.path.join('buttons', 'bidsapp-run.png'))))
update_selection = Button()
check = Button()
start_bidsapp = Button()
# stop_bidsapp = Action(name='Stop BIDS App!',action='stop_bids_app',enabled_when='handler.settings_checked and handler.docker_running')
traits_view = QtView(Group(
Group(
Group(
Item('bidsapp_tag', style='readonly', label='Tag'),
label='BIDS App Version'),
Group(
Item('bids_root', style='readonly', label='Input directory'),
Item('output_dir', style='simple', label='Output directory'),
label='BIDS dataset'),
Group(
HGroup(
UItem('subjects',
editor=TabularEditor(
show_titles=True,
selected='list_of_subjects_to_be_processed',
editable=False,
multi_select=True,
adapter=MultiSelectAdapter(columns=[('Available labels', 'myvalue')]))
),
UItem('list_of_subjects_to_be_processed',
editor=TabularEditor(
show_titles=True,
editable=False,
adapter=MultiSelectAdapter(columns=[('Labels to be processed', 'myvalue')]))
),
),
label='Participant labels to be processed'),
Group(Item('number_of_participants_processed_in_parallel',
label='Number of participants processed in parallel'),
Item('number_of_threads',
label='Number of threads used by ANTs and Freesurfer'),
label='Parallel processing and multithreading'),
Group(
Group(Item('anat_config', label='Configuration file', visible_when='run_anat_pipeline'),
label='Anatomical pipeline'),
Group(Item('run_dmri_pipeline', label='Run processing stages'),
Item('dmri_config', label='Configuration file',
visible_when='run_dmri_pipeline'),
label='Diffusion pipeline',
visible_when='dmri_inputs_checked==True'),
Group(Item('run_fmri_pipeline', label='Run processing stages'),
Item('fmri_config', label='Configuration file',
visible_when='run_fmri_pipeline'),
label='fMRI pipeline',
visible_when='fmri_inputs_checked==True'),
label='Configuration of processing pipelines'),
Group(
Item('fs_license', label='LICENSE'),
# Item('fs_average', label='FSaverage directory'),
label='Freesurfer configuration'),
orientation='vertical', springy=True),
Group(
Item('data_provenance_tracking', label='Use Datalad'),
Item('datalad_update_environment', visible_when='data_provenance_tracking',
label='Update the computing environment (if existing)'),
label='Data Provenance Tracking / Data Lineage',
enabled_when='datalad_is_available'),
spring,
HGroup(spring, Item('check', style='custom',
width=152, height=35, resizable=False,
label='', show_label=False,
style_sheet=return_button_style_sheet(
ImageResource(
pkg_resources.resource_filename(
'resources',
os.path.join('buttons', 'bidsapp-check-settings.png'))).absolute_path,
152)
),
spring,
Item('start_bidsapp', style='custom',
width=152, height=35, resizable=False,
label='', show_label=False,
style_sheet=return_button_style_sheet(
ImageResource(
pkg_resources.resource_filename(
'resources',
os.path.join('buttons', 'bidsapp-run.png'))).absolute_path,
152),
enabled_when='settings_checked==True and docker_running==False'),
spring,
show_labels=False, label=""),
orientation='vertical',
springy=True),
title='Connectome Mapper 3 BIDS App GUI',
# kind='modal',
handler=project.CMP_BIDSAppWindowHandler(),
# style_sheet=style_sheet,
buttons=[],
# buttons = [check,start_bidsapp],
# buttons = [process_anatomical,map_dmri_connectome,map_fmri_connectome],
# buttons = [preprocessing, map_connectome, map_custom],
width=0.5, height=0.8, scrollable=True, # , resizable=True
icon=get_icon('bidsapp.png')
)
log_view = QtView(Group(
Item('list_of_processing_logfiles'),
orientation='vertical', springy=True),
title='Connectome Mapper 3 BIDS App Progress',
# kind='modal',
# handler=project.CMP_BIDSAppWindowHandler(),
# style_sheet=style_sheet,
buttons=[],
# buttons = [check,start_bidsapp],
# buttons = [process_anatomical,map_dmri_connectome,map_fmri_connectome],
# buttons = [preprocessing, map_connectome, map_custom],
width=0.5, height=0.8, resizable=True, # , scrollable=True, resizable=True
icon=get_icon('bidsapp.png')
)
def __init__(self, project_info=None, bids_root='', subjects=None, list_of_subjects_to_be_processed=None,
anat_config='', dmri_config='', fmri_config=''):
"""Constructor of an :class:``CMP_BIDSAppWindow`` instance.
Parameters
----------
project_info : cmp.project.CMP_Project_Info
:class:`CMP_Project_Info` object (Default: None)
bids_root : traits.Directory
BIDS dataset root directory (Default: \'\')
subjects : List of string
List of subjects in the dataset (Default: None)
list_of_subjects_to_be_processed : List of string
List of subjects to be processed (Default: None)
anat_config : string
Path to anatomical pipeline configuration file (Default: \'\')
dmri_config : string
Path to diffusion pipeline configuration file (Default: \'\')
fmri_config : string
Path to functional pipeline configuration file (Default: \'\')
"""
if multiprocessing.cpu_count() < 4:
number_of_threads_max = multiprocessing.cpu_count()
self.project_info = project_info
self.bids_root = bids_root
try:
bids_layout = BIDSLayout(self.bids_root)
except Exception:
print("Exception : Raised at BIDSLayout")
sys.exit(1)
dmri_pipeline = DiffusionPipeline(project_info)
dmri_inputs_checked = dmri_pipeline.check_input(layout=bids_layout,
gui=False)
if dmri_inputs_checked is not None:
self.dmri_inputs_checked = dmri_inputs_checked
else:
self.dmri_inputs_checked = False
fmri_pipeline = fMRIPipeline(project_info)
fmri_inputs_checked = fmri_pipeline.check_input(layout=bids_layout,
gui=False,
debug=False)
if fmri_inputs_checked is not None:
self.fmri_inputs_checked = fmri_inputs_checked
else:
self.fmri_inputs_checked = False
# Initialize output directory to be /bids_dir/derivatives
self.output_dir = os.path.join(bids_root, 'derivatives')
self.subjects = subjects
# self.list_of_subjects_to_be_processed = list_of_subjects_to_be_processed
self.anat_config = anat_config
self.dmri_config = dmri_config
self.fmri_config = fmri_config
if 'FREESURFER_HOME' in os.environ:
self.fs_license = os.path.join(
os.environ['FREESURFER_HOME'], 'license.txt')
else:
print('Environment variable $FREESURFER_HOME not found')
self.fs_license = ''
print('Freesurfer license unset ({})'.format(self.fs_license))
self.datalad_is_available = project.is_tool('datalad')
self.on_trait_change(
self.update_run_dmri_pipeline, 'run_dmri_pipeline')
self.on_trait_change(
self.update_run_fmri_pipeline, 'run_fmri_pipeline')
self.on_trait_change(self.number_of_parallel_procs_updated,
'number_of_participants_processed_in_parallel')
self.on_trait_change(self.update_checksettings,
'list_of_subjects_to_be_processed')
self.on_trait_change(self.update_checksettings, 'anat_config')
self.on_trait_change(self.update_checksettings, 'run_dmri_pipeline')
self.on_trait_change(self.update_checksettings, 'dmri_config')
self.on_trait_change(self.update_checksettings, 'run_fmri_pipeline')
self.on_trait_change(self.update_checksettings, 'fmri_config')
self.on_trait_change(self.update_checksettings, 'fs_license')
# self.on_trait_change(self.update_checksettings, 'fs_average')
def number_of_parallel_procs_updated(self, new):
"""Callback function when ``number_of_parallel_procs`` is updated."""
number_of_threads_max = int((multiprocessing.cpu_count() - 1) / new)
if number_of_threads_max > 4:
self.number_of_threads_max = 4
else:
self.number_of_threads_max = number_of_threads_max
print('Set number of threads max to : {}'.format(self.number_of_threads_max))
def update_run_anat_pipeline(self, new):
"""Callback function when ``run_anat_pipeline`` is updated."""
if new is False:
print('At least anatomical pipeline should be run!')
self.run_anat_pipeline = True
def update_run_dmri_pipeline(self, new):
"""Callback function when ``run_dmri_pipeline`` is updated."""
self.run_anat_pipeline = True
def update_run_fmri_pipeline(self, new):
"""Callback function when ``run_fmri_pipeline`` is updated."""
self.run_anat_pipeline = True
def update_checksettings(self, new):
"""Function that reset ``settings_checked`` attribute to False."""
self.settings_checked = False
def _update_selection_fired(self):
"""Callback function when the list of selected subjects has been updated."""
self.configure_traits(view='select_subjects_to_be_processed_view')
def _check_fired(self):
"""Callback function when the Check Setting button is clicked."""
self.check_settings()
def _start_bidsapp_fired(self):
"""Callback function when the Run BIDS App button is clicked."""
self.start_bids_app()
def check_settings(self):
"""Checks if all the parameters of the BIDS App run are properly set before execution."""
self.settings_checked = True
if os.path.isdir(self.bids_root):
print("BIDS root directory : {}".format(self.bids_root))
else:
print("Error: BIDS root invalid!")
self.settings_checked = False
if os.path.exists(os.path.join(self.output_dir, 'cmp')):
print('Output directory (existing) : {}'.format(self.output_dir))
else:
os.makedirs(os.path.join(self.output_dir, 'cmp'))
print('Output directory (created) : {}'.format(self.output_dir))
if len(self.list_of_subjects_to_be_processed) > 0:
print("Participant labels to be processed : {}".format(
self.list_of_subjects_to_be_processed))
else:
print(
"Error: At least one participant label to be processed should selected!")
self.settings_checked = False
# if not self.list_of_subjects_to_be_processed.empty():
# print("List of subjects to be processed : {}".format(self.list_of_subjects_to_be_processed))
# else:
# print("Warning: List of subjects empty!")
if os.path.isfile(self.anat_config):
print("Anatomical configuration file : {}".format(self.anat_config))
else:
print("Error: Configuration file for anatomical pipeline not existing!")
self.settings_checked = False
if os.path.isfile(self.dmri_config):
print("Diffusion configuration file : {}".format(self.dmri_config))
else:
print("Warning: Configuration file for diffusion pipeline not existing!")