comparison general.py @ 56:ca61007a60fa draft

"planemo upload for repository https://github.com/rolfverberg/galaxytools commit fc9b26da497e467c28b0adf3f94422b4cb61f59c"
author rv43
date Tue, 02 Aug 2022 19:52:47 +0000
parents 26f99fdd8d61
children 98a83f03d91b
comparison
equal deleted inserted replaced
55:bead50a4eadc 56:ca61007a60fa
332 print(f'{s}{v_range}{default_string}: ') 332 print(f'{s}{v_range}{default_string}: ')
333 try: 333 try:
334 i = input() 334 i = input()
335 if isinstance(i, str) and not len(i): 335 if isinstance(i, str) and not len(i):
336 v = default 336 v = default
337 print(f'{v}')
337 else: 338 else:
338 v = literal_eval(i) 339 v = literal_eval(i)
339 if inset and v not in inset: 340 if inset and v not in inset:
340 raise ValueError(f'{v} not part of the set {inset}') 341 raise ValueError(f'{v} not part of the set {inset}')
341 except (ValueError, TypeError, SyntaxError, MemoryError, RecursionError): 342 except (ValueError, TypeError, SyntaxError, MemoryError, RecursionError):
387 print(f'{s}{v_range}{default_string}: ') 388 print(f'{s}{v_range}{default_string}: ')
388 try: 389 try:
389 i = input() 390 i = input()
390 if isinstance(i, str) and not len(i): 391 if isinstance(i, str) and not len(i):
391 v = default 392 v = default
393 print(f'{v}')
392 else: 394 else:
393 v = literal_eval(i) 395 v = literal_eval(i)
394 except (ValueError, TypeError, SyntaxError, MemoryError, RecursionError): 396 except (ValueError, TypeError, SyntaxError, MemoryError, RecursionError):
395 v = None 397 v = None
396 except: 398 except:
458 else: 460 else:
459 print(f'{s}{default_string}: ') 461 print(f'{s}{default_string}: ')
460 i = input() 462 i = input()
461 if isinstance(i, str) and not len(i): 463 if isinstance(i, str) and not len(i):
462 i = default 464 i = default
465 print(f'{i}')
463 if i is not None and i.lower() in 'yes': 466 if i is not None and i.lower() in 'yes':
464 v = True 467 v = True
465 elif i is not None and i.lower() in 'no': 468 elif i is not None and i.lower() in 'no':
466 v = False 469 v = False
467 else: 470 else:
485 print(f'Choose one of the following items (1, {len(items)}){default_string}:') 488 print(f'Choose one of the following items (1, {len(items)}){default_string}:')
486 else: 489 else:
487 print(f'{header} (1, {len(items)}){default_string}:') 490 print(f'{header} (1, {len(items)}){default_string}:')
488 for i, choice in enumerate(items): 491 for i, choice in enumerate(items):
489 print(f' {i+1}: {choice}') 492 print(f' {i+1}: {choice}')
490 choice = input() 493 try:
491 if isinstance(choice, str) and not len(choice): 494 choice = input()
492 choice = items.index(default) 495 if isinstance(choice, str) and not len(choice):
493 else: 496 choice = items.index(default)
494 choice = literal_eval(choice) 497 print(f'{choice+1}')
495 if isinstance(choice, int) and 1 <= choice <= len(items): 498 else:
496 choice -= 1 499 choice = literal_eval(choice)
497 else: 500 if isinstance(choice, int) and 1 <= choice <= len(items):
498 print(f'Illegal choice, enter a number between 1 and {len(items)}') 501 choice -= 1
499 choice = input_menu(items, default) 502 else:
503 raise ValueError
504 except (ValueError, TypeError, SyntaxError, MemoryError, RecursionError):
505 choice = None
506 except:
507 print('Unexpected error')
508 raise
509 if choice is None:
510 print(f'Illegal choice, enter a number between 1 and {len(items)}')
511 choice = input_menu(items, default)
500 return choice 512 return choice
501 513
502 def create_mask(x, bounds=None, reverse_mask=False, current_mask=None): 514 def create_mask(x, bounds=None, reverse_mask=False, current_mask=None):
503 # bounds is a pair of number in the same units a x 515 # bounds is a pair of number in the same units a x
504 if not isinstance(x, (tuple, list, np.ndarray)) or not len(x): 516 if not isinstance(x, (tuple, list, np.ndarray)) or not len(x):
523 if not True in mask: 535 if not True in mask:
524 logging.warning('Entire data array is masked') 536 logging.warning('Entire data array is masked')
525 return mask 537 return mask
526 538
527 def draw_mask_1d(ydata, xdata=None, current_index_ranges=None, current_mask=None, 539 def draw_mask_1d(ydata, xdata=None, current_index_ranges=None, current_mask=None,
528 select_mask=True, num_index_ranges_max=None, title=None, legend=None): 540 select_mask=True, num_index_ranges_max=None, title=None, legend=None, test_mode=False):
529 def draw_selections(ax): 541 def draw_selections(ax):
530 ax.clear() 542 ax.clear()
531 ax.set_title(title) 543 ax.set_title(title)
532 ax.legend([legend]) 544 ax.legend([legend])
533 ax.plot(xdata, ydata, 'k') 545 ax.plot(xdata, ydata, 'k')
677 for i in range(1, len(current_include)): 689 for i in range(1, len(current_include)):
678 current_exclude.append((current_include[i-1][1]+1, current_include[i][0]-1)) 690 current_exclude.append((current_include[i-1][1]+1, current_include[i][0]-1))
679 if current_include[-1][1] < num_data-1: 691 if current_include[-1][1] < num_data-1:
680 current_exclude.append((current_include[-1][1]+1, num_data-1)) 692 current_exclude.append((current_include[-1][1]+1, num_data-1))
681 693
682 # Set up matplotlib figure 694 if not test_mode:
683 plt.close('all') 695
684 fig, ax = plt.subplots() 696 # Set up matplotlib figure
685 plt.subplots_adjust(bottom=0.2) 697 plt.close('all')
686 draw_selections(ax) 698 fig, ax = plt.subplots()
687 699 plt.subplots_adjust(bottom=0.2)
688 # Set up event handling for click-and-drag range selection 700 draw_selections(ax)
689 cid_click = fig.canvas.mpl_connect('button_press_event', onclick) 701
690 cid_release = fig.canvas.mpl_connect('button_release_event', onrelease) 702 # Set up event handling for click-and-drag range selection
691 703 cid_click = fig.canvas.mpl_connect('button_press_event', onclick)
692 # Set up confirm / clear range selection buttons 704 cid_release = fig.canvas.mpl_connect('button_release_event', onrelease)
693 confirm_b = Button(plt.axes([0.75, 0.05, 0.15, 0.075]), 'Confirm') 705
694 clear_b = Button(plt.axes([0.59, 0.05, 0.15, 0.075]), 'Clear') 706 # Set up confirm / clear range selection buttons
695 cid_confirm = confirm_b.on_clicked(confirm_selection) 707 confirm_b = Button(plt.axes([0.75, 0.05, 0.15, 0.075]), 'Confirm')
696 cid_clear = clear_b.on_clicked(clear_last_selection) 708 clear_b = Button(plt.axes([0.59, 0.05, 0.15, 0.075]), 'Clear')
697 709 cid_confirm = confirm_b.on_clicked(confirm_selection)
698 # Show figure 710 cid_clear = clear_b.on_clicked(clear_last_selection)
699 plt.show(block=True) 711
700 712 # Show figure
701 # Disconnect callbacks when figure is closed 713 plt.show(block=True)
702 fig.canvas.mpl_disconnect(cid_click) 714
703 fig.canvas.mpl_disconnect(cid_release) 715 # Disconnect callbacks when figure is closed
704 confirm_b.disconnect(cid_confirm) 716 fig.canvas.mpl_disconnect(cid_click)
705 clear_b.disconnect(cid_clear) 717 fig.canvas.mpl_disconnect(cid_release)
718 confirm_b.disconnect(cid_confirm)
719 clear_b.disconnect(cid_clear)
706 720
707 # Swap selection depending on select_mask 721 # Swap selection depending on select_mask
708 if not select_mask: 722 if not select_mask:
709 selected_index_ranges, unselected_index_ranges = unselected_index_ranges, \ 723 selected_index_ranges, unselected_index_ranges = unselected_index_ranges, \
710 selected_index_ranges 724 selected_index_ranges