@@ -74,6 +74,9 @@ def get_normalisation(normtype, normcol, normfile):
74
74
return (norm_check , normcol , normfile )
75
75
76
76
def clear_last_input ():
77
+ """
78
+ removes last added set of input specs from global input dict
79
+ """
77
80
added_samples = len (input ['samplecolumns' ][- 1 ])
78
81
print ('clearing wrong input..' )
79
82
print ('number of added samples: {}' .format (added_samples ))
@@ -201,7 +204,7 @@ def check_input():
201
204
202
205
return True
203
206
204
- def check_input_data (input ):
207
+ def check_input_data ():
205
208
"""
206
209
check if input data is valid and matches input specs
207
210
"""
@@ -243,15 +246,16 @@ def check_input_data(input):
243
246
clear_last_input ()
244
247
return False
245
248
246
- # check if samplecolumns exist and check sample length
249
+ # check if samplecolumns exist
250
+ dataset_columns = list (data .columns )
247
251
for col_pair in samplecolumns :
248
- if not col_pair [0 ] in data . columns :
252
+ if not col_pair [0 ] in dataset_columns :
249
253
warn_msg = "start column header not in dataset: {}. check input" .format (col_pair [0 ])
250
254
input_status_var .set (warn_msg )
251
255
messagebox .showwarning ("input error" ,warn_msg )
252
256
clear_last_input ()
253
257
return False
254
- if not col_pair [1 ] in data . columns :
258
+ if not col_pair [1 ] in dataset_columns :
255
259
warn_msg = "end column header not in dataset: {}. check input" .format (col_pair [1 ])
256
260
input_status_var .set (warn_msg )
257
261
messagebox .showwarning ("input error" ,warn_msg )
@@ -263,15 +267,13 @@ def check_input_data(input):
263
267
sample_data = data .loc [:,col_pair [0 ]:col_pair [1 ]]
264
268
except Exception as error :
265
269
warn_msg = "sample could not be extracted from data. error: {}" .format (error )
266
- "please check input"
267
270
input_status_var .set ("problem extracting sample from data. check input" )
268
271
messagebox .showwarning ("input error" ,warn_msg )
269
272
clear_last_input ()
270
273
return False
271
274
272
275
if sample_data .shape [1 ] < 2 :
273
276
warn_msg = "found sample with 0 or 1 columns: {}:{}. " .format (col_pair [0 ],col_pair [1 ])
274
- "Please check input"
275
277
input_status_var .set (warn_msg )
276
278
messagebox .showwarning ("input error" , warn_msg )
277
279
clear_last_input ()
@@ -280,12 +282,13 @@ def check_input_data(input):
280
282
# check for nan values in sample
281
283
if sample_data .isnull ().values .any ():
282
284
warn_msg = "sample contains missing (nan) values: {}:{}. " .format (col_pair [0 ],col_pair [1 ])
283
- "please check input"
284
285
input_status_var .set (warn_msg )
285
286
messagebox .showwarning ("input error" , warn_msg )
286
287
clear_last_input ()
287
288
return False
288
289
290
+ # store columns of each dataset to check outputspecs
291
+ input ['dataset_columns' ].append (dataset_columns )
289
292
return True
290
293
291
294
def check_output ():
@@ -346,6 +349,42 @@ def check_output():
346
349
347
350
return True
348
351
352
+ def check_output_data ():
353
+ """
354
+ checks if output data is valid
355
+ """
356
+ input_columnsets = input ['dataset_columns' ]
357
+ normcol = input ['normcol' ]
358
+ normfile = input ['normfile' ]
359
+ gseacol = input ['GSEA_rank_column' ]
360
+
361
+ # check normcol
362
+ if normcol :
363
+ for dataset in input_columnsets :
364
+ if not normcol in dataset :
365
+ warn_msg = "normalisation column header not present in one of the input datasets!"
366
+ status_var .set (warn_msg )
367
+ messagebox .showwarning ("input error" ,warn_msg )
368
+ return False
369
+ # check gsea_col
370
+ if gseacol :
371
+ for dataset in input_columnsets :
372
+ if not gseacol in dataset :
373
+ warn_msg = "gsea column header not present in one of the input datasets!"
374
+ status_var .set (warn_msg )
375
+ messagebox .showwarning ("input error" ,warn_msg )
376
+ return False
377
+
378
+ # check normfile
379
+ if normfile :
380
+ if not os .path .isfile (normfile ):
381
+ warn_msg = "normfile does not exist! check input."
382
+ status_var .set (warn_msg )
383
+ messagebox .showwarning ("input error" ,warn_msg )
384
+ return False
385
+
386
+ return True
387
+
349
388
def print_input ():
350
389
"""prints out global input variables to stdout"""
351
390
print ("file name: " , input ['filename' ])
@@ -388,6 +427,8 @@ def run_analysis():
388
427
389
428
def back_to_input_handler (event = None ):
390
429
"""clears input and goes back to first GUI frame"""
430
+ # clear dataset columns when re-entering input
431
+ input ['dataset_columns' ] = []
391
432
clear_input_vars ()
392
433
first_input_frame ()
393
434
@@ -427,7 +468,13 @@ def save_proceed_handler(event = None):
427
468
"""
428
469
if check_input ():
429
470
save_input_settings ()
430
- if check_input_data (input ):
471
+ if check_input_data ():
472
+ if len (input ['samplenames' ]) < 2 :
473
+ warn_msg = ('only 1 sample specified! need at least two samples for alignment. '
474
+ 'add another sample from this file or add another file' )
475
+ status_var .set (warn_msg )
476
+ messagebox .showwarning ("input error" ,warn_msg )
477
+ return
431
478
print_input ()
432
479
output_frame = tk .Frame (root )
433
480
output_frame .grid (row = 0 , column = 0 , sticky = "news" )
@@ -443,7 +490,7 @@ def append_proceed_handler(event = None):
443
490
"""
444
491
if check_input ():
445
492
append_extra_input ()
446
- if check_input_data (input ):
493
+ if check_input_data ():
447
494
print_input ()
448
495
output_frame = tk .Frame (root )
449
496
output_frame .grid (row = 0 , column = 0 , sticky = "news" )
@@ -459,7 +506,7 @@ def save_extra_input_handler(event = None):
459
506
"""
460
507
if check_input ():
461
508
save_input_settings ()
462
- if check_input_data (input ):
509
+ if check_input_data ():
463
510
clear_input_vars ()
464
511
extra_frame = tk .Frame (root )
465
512
extra_frame .grid (row = 0 , column = 0 , sticky = "news" )
@@ -476,7 +523,7 @@ def append_extra_input_handler(event = None):
476
523
"""
477
524
if check_input ():
478
525
append_extra_input ()
479
- if check_input_data (input ):
526
+ if check_input_data ():
480
527
clear_input_vars ()
481
528
extra_frame = tk .Frame (root )
482
529
extra_frame .grid (row = 0 , column = 0 , sticky = "news" )
@@ -499,14 +546,15 @@ def save_output_and_run_handler(event = None):
499
546
root .update_idletasks ()
500
547
return
501
548
502
- status_var .set ("Running analysis. This might take a while..." )
503
- root .update_idletasks () # ensures the status label gets updated in a timely fashion
504
549
save_output_settings ()
505
- print_input ()
506
- print_output ()
507
- analysis_thread = threading .Thread (target = run_analysis )
508
- analysis_thread .daemon = True
509
- analysis_thread .start ()
550
+ if check_output_data ():
551
+ status_var .set ("Running analysis. This might take a while..." )
552
+ root .update_idletasks () # ensures the status label gets updated in a timely fashion
553
+ print_input ()
554
+ print_output ()
555
+ analysis_thread = threading .Thread (target = run_analysis )
556
+ analysis_thread .daemon = True
557
+ analysis_thread .start ()
510
558
511
559
# ---------- GUI WIDGET CREATING FUNCTIONS ---------- #
512
560
def input_frame (master ):
@@ -527,7 +575,7 @@ def input_frame(master):
527
575
get_file_button .grid (row = 1 , column = 4 , padx = 4 , sticky = tk .W )
528
576
529
577
# choose filetype dropdown menu
530
- file_type_dropdown = ttk .OptionMenu (master , file_type ,"excel " ,"excel" , "csv del ';' dec ','" ,
578
+ file_type_dropdown = ttk .OptionMenu (master , file_type ,"csv del ',' dec '.' " ,"excel" , "csv del ';' dec ','" ,
531
579
"csv del ',' dec '.'" , "tsv del '\\ t' dec ','" ,
532
580
"tsv del '\\ t' dec '.'" )
533
581
file_type_dropdown .grid (row = 1 , column = 5 , sticky = tk .EW )
@@ -701,7 +749,6 @@ def first_input_frame():
701
749
#root.resizable(0,0) # prevents window from being resized
702
750
703
751
# try to set application icon (does not work on all platforms)
704
-
705
752
try :
706
753
root .iconbitmap (os .path .join (os .getcwd (),'copal/static/Copal.ico' ))
707
754
except Exception as e :
@@ -730,6 +777,9 @@ def first_input_frame():
730
777
731
778
# initialize global dictionary containing input for analysis
732
779
input = {}
780
+ # create empty list. to enter column-list of each dataset into.
781
+ # used to check if output frame specs match input data
782
+ input ['dataset_columns' ] = []
733
783
734
784
# set variable default values
735
785
file_type .set ("excel" )
0 commit comments