hg19 as reference produce bad ordered bams

hg19 as reference produce bad ordered bam starting chr10,chr11,chr,12…etc and then chr1,chr2,etc

This is true and annoying at times, but not easy to change. Question is: what specific problem is it causing you and can we find a workaround?

Have you tried the tool “bedtools SortBED”?

https://usegalaxy.org/root?tool_id=toolshed.g2.bx.psu.edu/repos/iuc/bedtools/bedtools_sortbed/2.29.2

Regarding the cause I think the proper term is called “lexicographic order”. So what happens is that the sorting algorithm compares the first number in the string (ie 1, 2 etc) and then the second (0, 1, 2 or nothing for number 1-9). But I don’t know the specifics of different alignment tools and what they use for sorting.