cac8c67d46544187d0fb28cf78060d9d2cb97a5d angie Tue Feb 5 14:09:20 2019 -0800 Update chrSlNameCmpWithAltRandom to handle _fix and _hap sequence names. refs #18855 note-70 diff --git src/hg/lib/hdb.c src/hg/lib/hdb.c index 2138bca..6b3a27b 100644 --- src/hg/lib/hdb.c +++ src/hg/lib/hdb.c @@ -5236,55 +5236,63 @@ return -1; else return strcmp(str1, str2); } int chrSlNameCmp(const void *el1, const void *el2) /* Compare chromosome names by number, then suffix. el1 and el2 must be * slName **s (as passed in by slSort) whose names match the regex * "chr([0-9]+|[A-Za-z0-9]+)(_[A-Za-z0-9_]+)?". */ { struct slName *sln1 = *(struct slName **)el1; struct slName *sln2 = *(struct slName **)el2; return chrNameCmp(sln1->name, sln2->name); } +static boolean isAltFixRandom(char *str) +/* Return TRUE if str ends with _alt, _fix or _random or contains "_hap". */ +{ +return (endsWith(str, "_alt") || endsWith(str, "_fix") || endsWith(str, "_random") || + stringIn("_hap", str)); + +} + int chrNameCmpWithAltRandom(char *str1, char *str2) /* Compare chromosome or linkage group names str1 and str2 * to achieve this order: * chr1 .. chr22 * chrX * chrY * chrM - * chr1_{alt, random} .. chr22_{alt, random} + * chr1_{alt,fix,hap*,random} .. chr22_{alt,fix,hap*,random} * chrUns */ { int num1 = 0, num2 = 0; int match1 = 0, match2 = 0; char suffix1[512], suffix2[512]; /* put chrUn at the bottom */ if (startsWith("chrUn", str1) && !startsWith("chrUn", str2)) return 1; if (!startsWith("chrUn", str1) && startsWith("chrUn", str2)) return -1; /* if it is _alt or _random then it goes at the end */ -if ( (endsWith(str1, "_alt")||endsWith(str1, "_random")) && !(endsWith(str2, "_alt") || endsWith(str2, "_random"))) +if (isAltFixRandom(str1) && !isAltFixRandom(str2)) return 1; -if (!(endsWith(str1, "_alt")||endsWith(str1, "_random")) && (endsWith(str2, "_alt") || endsWith(str2, "_random"))) +if (!isAltFixRandom(str1) && isAltFixRandom(str2)) return -1; /* get past "chr" or "Group" prefix: */ if (startsWith("chr", str1)) str1 += 3; else if (startsWith("Group", str1)) str1 += 5; else return -1; if (startsWith("chr", str2)) str2 += 3; else if (startsWith("Group", str2)) str2 += 5; else return 1; @@ -5328,32 +5336,32 @@ else if (sameString(str1, "M") && !sameString(str2, "M")) return 1; else if (!sameString(str1, "M") && sameString(str2, "M")) return -1; else return strcmp(str1, str2); } int chrSlNameCmpWithAltRandom(const void *el1, const void *el2) /* Compare chromosome or linkage group names str1 and str2 * to achieve this order: * chr1 .. chr22 * chrX * chrY * chrM - * chr1_{alt, random} .. chr22_{alt, random} - * chrUns + * chr1_{alt,fix,hap*,random} .. chr22_{alt,fix,hap*,random} + * chrUn* */ { struct slName *sln1 = *(struct slName **)el1; struct slName *sln2 = *(struct slName **)el2; return chrNameCmpWithAltRandom(sln1->name, sln2->name); } int bedCmpExtendedChr(const void *va, const void *vb) /* Compare to sort based on chrom,chromStart. Use extended * chrom name comparison, that strip prefixes and does numeric compare */ { const struct bed *a = *((struct bed **)va); const struct bed *b = *((struct bed **)vb); int dif; dif = chrNameCmp(a->chrom, b->chrom);