'Populate self with drums from the given quantized NoteSequence object.
A drum track is extracted from the given quantized sequence starting at time
step `start_step`. `start_step` can be used to drive extraction of multiple
drum tracks from the same quantized sequence. The end step of the extracted
drum track will be stored in `self._end_step`.
0 velocity notes are ignored. The drum extraction is ended when there are
no drums for a time stretch of `gap_bars` in bars (measures) of music. The
number of time steps per bar is computed from the time signature in
`quantized_sequence`.
Each drum event is a Python frozenset of simultaneous (after quantization)
drum "pitches", or an empty frozenset to indicate no drums are played.
Args:
quantized_sequence: A quantized NoteSequence instance.
search_start_step: Start searching for drums at this time step. Assumed to
be the beginning of a bar.
gap_bars: If this many bars or more follow a non-empty drum event, the
drum track is ended.
pad_end: If True, the end of the drums will be padded with empty events so
that it will end at a bar boundary.
ignore_is_drum: Whether accept notes where `is_drum` is False.
Raises:
NonIntegerStepsPerBarException: If `quantized_sequence`\'s bar length
(derived from its time signature) is not an integer number of time
steps.'

def from_quantized_sequence(self, quantized_sequence, search_start_step=0, gap_bars=1, pad_end=False, ignore_is_drum=False):

    sequences_lib.assert_is_relative_quantized_sequence(quantized_sequence)
    self._reset()
    steps_per_bar_float = sequences_lib.steps_per_bar_in_quantized_sequence(quantized_sequence)
    if ((steps_per_bar_float % 1) != 0):
        raise events_lib.NonIntegerStepsPerBarException(('There    are    %f    timesteps    per    bar.    Time    signature:    %d/%d' % (steps_per_bar_float, quantized_sequence.time_signatures[0].numerator, quantized_sequence.time_signatures[0].denominator)))
    self._steps_per_bar = steps_per_bar = int(steps_per_bar_float)
    self._steps_per_quarter = quantized_sequence.quantization_info.steps_per_quarter
    all_notes = [note for note in quantized_sequence.notes if ((note.is_drum or ignore_is_drum) and note.velocity and (note.quantized_start_step >= search_start_step))]
    grouped_notes = collections.defaultdict(list)
    for note in all_notes:
        grouped_notes[note.quantized_start_step].append(note)
    notes = sorted(grouped_notes.items(), key=operator.itemgetter(0))
    if (not notes):
        return
    gap_start_index = 0
    track_start_step = (notes[0][0] - ((notes[0][0] - search_start_step) % steps_per_bar))
    for (start, group) in notes:
        start_index = (start - track_start_step)
        pitches = frozenset((note.pitch for note in group))
        note_distance = (start_index - gap_start_index)
        if (len(self) and (note_distance >= (gap_bars * steps_per_bar))):
            break
        self.set_length((start_index + 1))
        self._events[start_index] = pitches
        gap_start_index = (start_index + 1)
    if (not self._events):
        return
    self._start_step = track_start_step
    length = len(self)
    if pad_end:
        length += ((- len(self)) % steps_per_bar)
    self.set_length(length)
