R/utils.R

Defines functions is_white validate_input subset_gp recycle_gp validate_gpar

Documented in is_white

validate_gpar = function(gp, default) {
	for(nm in names(default)) {
		if(length(gp[[nm]]) == 0) {
			gp[[nm]] = default[[nm]]
		}
	}
	return(gp)
}

recycle_gp = function(gp, n = 1) {
	g = lapply(gp, function(x) {
		if(length(x) == 1 && n > 1) {
			rep(x, n)
		} else {
			x
		}
	})
	class(g) = "gpar"
	return(g)
}

subset_gp = function(gp, i = 1) {
	g = lapply(gp, function(x) {
		x[i]
	})
	class(g) = "gpar"
	return(g)
}

validate_input = function(object, ir, x1, x2) {
	if(!is.null(ir)) {
    	if(!inherits(ir, "IRanges")) {
    		stop("It seems you want to specify positions by one or two numeric vectors, specify them with argument names. (`x1 = ..., x2 = ...`)")
    	}
    }

    if(is.null(ir)) {
        if(is.null(x1) || is.null(x2)) {
            stop("You should either specify `ir`, or `x1` and `x2`.")
        } else {
            x1 = hc_offset(object, x1)
            x2 = hc_offset(object, x2)
            ir = IRanges(start = round(zoom(object, x1)),
                         end = round(zoom(object, x2)))
        }
    } else {
        ir = IRanges(hc_offset(object, start(ir)),
                     hc_offset(object, end(ir)))
        ir = IRanges(start = zoom(object, start(ir)),
                     end = zoom(object, end(ir)))
    }
    return(ir)
}

# == title
# Whether the color is white
#
# == param
# -r Red channel.
# -g Green channel.
# -b Blue channel.
# -maxColorValue 1 or 255.
#
is_white = function(r, g, b, maxColorValue = 1) {
	r == maxColorValue & g == maxColorValue & b == maxColorValue
}

Try the HilbertCurve package in your browser

Any scripts or data that you put into this service are public.

HilbertCurve documentation built on Nov. 8, 2020, 8:05 p.m.