def apply_selection(selection, dataset): """Apply a given selection to a dataset, modifying it inplace. Returns the original dataset. """ for seq in walk(dataset, SequenceType): # apply only relevant selections conditions = [ condition for condition in selection if re.match( '%s\.[^\.]+(<=|<|>=|>|=|!=)' % re.escape(seq.id), condition)] for condition in conditions: id1, op, id2 = parse_selection(condition, dataset) seq.data = seq[op(id1, id2)].data return dataset
def apply_selection(selection, dataset): """Apply a given selection to a dataset, modifying it inplace. Returns the original dataset. """ for seq in walk(dataset, SequenceType): # apply only relevant selections conditions = [ condition for condition in selection if re.match('%s\.[^\.]+(<=|<|>=|>|=|!=)' % re.escape(seq.id), condition) ] for condition in conditions: id1, op, id2 = parse_selection(condition, dataset) seq.data = seq[op(id1, id2)].data return dataset
def test_inverted(self): """Test an inverted selection.""" id1, op, id2 = parse_selection("1<sequence.byte", VerySimpleSequence) self.assertEqual(id1, 1) self.assertIs(op, operator.lt) self.assertIs(id2, VerySimpleSequence.sequence.byte)
def test_simple(self): """Test a simple selection.""" id1, op, id2 = parse_selection("sequence.byte>1", VerySimpleSequence) self.assertIs(id1, VerySimpleSequence.sequence.byte) self.assertIs(op, operator.gt) self.assertEqual(id2, 1)