Skip to content

Commit

Permalink
Fix pileup sorting when using string tag (#1750)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Mar 1, 2021
1 parent 83d1261 commit d59bbfa
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions plugins/alignments/src/PileupRenderer/sortUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,19 @@ export const sortFeature = (

case 'tag': {
const tag = sortedBy.tag as string
featuresInCenterLine.sort((a, b) => {
return isCram
? (b.get('tags')[tag] || 0) - (a.get('tags')[tag] || 0)
: (b.get(tag) || 0) - (a.get(tag) || 0)
})
const getTag = (f: Feature, t: string) => {
return isCram ? f.get('tags')[t] : f.get(t)
}
const isString = typeof getTag(featuresInCenterLine[0], tag) === 'string'
if (isString) {
featuresInCenterLine.sort((a, b) =>
getTag(b, tag).localeCompare(getTag(a, tag)),
)
} else {
featuresInCenterLine.sort(
(a, b) => (getTag(b, tag) || 0) - (getTag(a, tag) || 0),
)
}
break
}

Expand Down

0 comments on commit d59bbfa

Please sign in to comment.