def mask_to_range(mask):
	"""converts a boolean mask into a range string,
	e.g. [True,True,True,False,True] -> '1-3,5'"""
	rangespec = []
	i = 0
	while i < len(mask):
		if not mask[i]:
			i = i+1
			continue
		j = i+1
		while j < len(mask) and mask[j]:
			j = j+1
		j = j-1

		if i != j:
			rangespec.append('%i-%i' % (i+1,j+1))
		else:
			rangespec.append('%i' % (i+1))
		i = j+1

	return ','.join(rangespec)