# TODO: Add comment
# 
# Author: E.Korsching Oct 10, 2013
###############################################################################


order.chr <- function(x){
	# rename chr label  and  generate correct order for chromosomes, 1..5..10..22..X
	# x: data.frame (!) (stringsAsFactors=F !)
	#   with 1. column chromosome (character) and 2. column position (numeric/integer)
	# return order vector
	tmpA <- c("chr1","chr2","chr3","chr4","chr5","chr6","chr7","chr8","chr9")
	tmpB <- c("chr01","chr02","chr03","chr04","chr05","chr06","chr07","chr08","chr09")
	tmp.len <- length(tmpA)
	for(i in 1:tmp.len){
		tmp1 <- x[,1]==tmpA[i]
		if(sum(tmp1)>0){		# check if term was found  else skip
			x[tmp1, 1] <- tmpB[i]
		}
	}
	tmp.order <- order(x[,1],x[,2])
	return(tmp.order)
}


#order.chr(x=data.frame(c("chr1","chr1","chr10","chr2","chr10","chr2","chr11","chr1","chr11"),c(2,1,10,5,9,6,11,3,12),stringsAsFactors=F))


