R/convert.to.one.based.R

Defines functions convert.to.one.based

Documented in convert.to.one.based

#' convert.to.one.based
#'
#' @description 
#' 	Convert zero-based region in format chr:start-end to 1-based
#'
#' @param id string in format chr:start-end
#'
#' @return one-converted ID
#'
#' @export convert.to.one.based
convert.to.one.based <- function(id) {

	# split region and sanity check
	components <- get.components(id);
	if( components$start == components$end ) {
		stop('Start and end are equal. Are you sure the input is zero-based?');
	}

	# add 1 to start to make 1-based
	components$start <- components$start + 1;

	# re-assemble ID
	one.based.id <- paste0(components$chr, ':', format(components$start, scientific = FALSE), '-', format(components$end, scientific = FALSE));

	return(one.based.id);
}

Try the chicane package in your browser

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

chicane documentation built on Nov. 7, 2021, 1:07 a.m.