GenMap-Comparator icon indicating copy to clipboard operation
GenMap-Comparator copied to clipboard

sort chrom names in natural order

Open timflutre opened this issue 8 years ago • 1 comments

More info about "natural sort order" here.

This can be done via the mixedsortfunction in the gtools R package.

timflutre avatar Oct 05 '17 09:10 timflutre

The online comparator is currently down, but here is a quick example:

map <- structure(list(chr = c("chr1", "chr1", "chr1", "chr2", "chr2",
 "chr2", "chr10", "chr10", "chr10"), mrk = c("loc1", "loc2", "loc3",
 "loc4", "loc5", "loc6", "loc7", "loc8", "loc9"), dist = c(2,
 4, 7, 1, 5, 12, 2, 5, 6)), .Names = c("chr", "mrk", "dist"), row.names = c(NA,
 -9L), class = "data.frame")

With built-in sort, chr10is before chr2:

map[order(map$chr),]
     chr  mrk dist
 1  chr1 loc1    2
 2  chr1 loc2    4
 3  chr1 loc3    7
 7 chr10 loc7    2
 8 chr10 loc8    5
 9 chr10 loc9    6
 4  chr2 loc4    1
 5  chr2 loc5    5
 6  chr2 loc6   12

With gtools' mixedsort, chr10is after chr2:

map[gtools::mixedorder(map$chr),]
     chr  mrk dist
 1  chr1 loc1    2
 2  chr1 loc2    4
 3  chr1 loc3    7
 4  chr2 loc4    1
 5  chr2 loc5    5
 6  chr2 loc6   12
 7 chr10 loc7    2
 8 chr10 loc8    5
 9 chr10 loc9    6

timflutre avatar Oct 13 '17 07:10 timflutre