Filter Widgets

Five new classes are defined the beginning of gui.py. Four of them are used to define the widgets that control filter parameters:

  • BlockSizeFilterWidget is an integer range slider to specify minimum and maximum block sizes
  • BlockLengthFilterWidget is another integer range slider, for block lengths
  • CoverageFilterWidget is a single-value integer slider
  • SupportFilterWidget is a checkbox that is either on or off

The initialization methods for each widget defines the widget's name (which will be displayed above the widget when it is shown in the GUI) and sets its initial values.

Initialization methods are also passed a reference to a SNPFilter object that has the code that will do the actual filtering before a chromosome is displayed. When a filter widget is updated (e.g. when the user moves a slider) a "callback function" is activated. The function will record the new setting in the SNPFilter so it is used the next time the filter is called.

The fifth class, called FilterBox, is a type of widget called a "layout". It provides a way to collect all the filter widgets in a single location and provides a common interface to all the filters.

FilterBox

Bases: Column

A FilterBox is a column layout that has labels and an instance of each of the filter widgets.

in the order they will be displayed.

Parameters:
  • f –

    the filter object with the method that does the filtering (passed to the constructors for each filter widget)

Source code in src/xo/gui.py
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
def __init__(self, snp_filter):
    '''
    The `__init__` method instantiates the widgets that will
    filter SNPs and puts them in the Column
    in the order they will be displayed.

    Arguments:
      f:  the filter object with the method that does the filtering (passed to
          the constructors for each filter widget)
    '''
    super(FilterBox, self).__init__()

    self._widgets = []
    for cls in [BlockSizeFilterWidget, BlockLengthFilterWidget, CoverageFilterWidget, SupportFilterWidget]:
        w = cls(snp_filter)
        self._widgets.append(w)
        self.append(w)

widgets()

Return a list of filter widgets.

Source code in src/xo/gui.py
275
276
277
278
279
def widgets(self):
    '''
    Return a list of filter widgets.
    '''
    return self._widgets

BlockSizeFilterWidget

Bases: IntRangeSlider

Use an integer range slider to provide settings for the filter based on the count of the number of SNPs in a block.

Source code in src/xo/gui.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def __init__(self, f):
    '''
    Arguments:
      f:  the SNPFilter object that will do the filtering.
    '''
    c = Config()
    super(BlockSizeFilterWidget,self).__init__(
        name = 'Block Size (#SNPs)',
        start = c.filter_block_size[0],
        end = c.filter_block_size[1]
    )
    self.value = (self.start, self.end)
    self.tags = ['size', 1]
    self.filter = f

filter_cb()

Callback activated when the slider changes. Saves the new slider settings in the filter object.

Source code in src/xo/gui.py
53
54
55
56
57
58
def filter_cb(self):
    '''
    Callback activated when the slider changes.  Saves the new
    slider settings in the filter object.
    '''
    self.filter.size_range = self.value

BlockLengthFilterWidget

Bases: IntRangeSlider

Use an integer range slider to provide settings for the filter based on length of a block, defined as the number of bases between the first and last SNP.

Source code in src/xo/gui.py
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
def __init__(self, f):
    '''
    Arguments:
      f:  the SNPFilter object that will do the filtering.
    '''
    c = Config()
    super(BlockLengthFilterWidget,self).__init__(
        name = 'Block Length (bp)',
        start = c.filter_block_length[0],
        end = c.filter_block_length[1],
        step = 100,
    )
    self.value = (self.start, self.end)
    self.tags = ['length', 1]     
    self.filter = f

filter_cb()

Callback activated when the slider changes. Saves the new slider settings in the filter object.

Source code in src/xo/gui.py
84
85
86
87
88
89
def filter_cb(self):
    '''
    Callback activated when the slider changes.  Saves the new
    slider settings in the filter object.
    '''
    self.filter.length_range = self.value

CoverageFilterWidget

Bases: IntSlider

Use an integer slider to display the coverage cutoff value.

Source code in src/xo/gui.py
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
def __init__(self, f):
    '''
    Arguments:
      f:  the filter object with the method that does the filtering
    '''
    super(CoverageFilterWidget,self).__init__(
        name = 'Minimum Coverage',
        start = 0,
        end = 10,
    )
    self.value = self.start
    self.tags = ['coverage', 0]
    self.filter = f

filter_cb()

Callback activated when the slider changes. Saves the new slider settings in the filter object.

Source code in src/xo/gui.py
111
112
113
114
115
116
def filter_cb(self):
    '''
    Callback activated when the slider changes.  Saves the new
    slider settings in the filter object.
    '''
    self.filter.coverage = self.value

SupportFilterWidget

Bases: Checkbox

Use a checkbox to tell the filter to keep SNPs if the base genome column matches the HMM state column.

Source code in src/xo/gui.py
125
126
127
128
129
130
131
132
133
134
def __init__(self, f):
    '''
    Arguments:
      f:  the filter object with the method that does the filtering
    '''
    super(SupportFilterWidget,self).__init__(
        name = 'Genome Match',
    )
    self.tags = ['match', 0]
    self.filter = f

filter_cb()

Callback activated when the slider changes. Saves the new slider settings in the filter object.

Source code in src/xo/gui.py
136
137
138
139
140
141
def filter_cb(self):
    '''
    Callback activated when the slider changes.  Saves the new
    slider settings in the filter object.
    '''
    self.filter.matched = self.value