From 38b2acfc0be6b26be3d66a26cd5e7d900ec64aa2 Mon Sep 17 00:00:00 2001 From: wilsonGen <103169735+wilsonGen@users.noreply.github.com> Date: Tue, 4 Jul 2023 13:13:06 +0800 Subject: [PATCH] can sort as pairs when view as pairs, sort as single reads otherwise (#1659) --- js/bam/alignmentContainer.js | 2 +- js/bam/bamAlignmentRow.js | 12 ++++++------ js/bam/bamTrack.js | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/js/bam/alignmentContainer.js b/js/bam/alignmentContainer.js index d15bdd6a4..b45f1a2a9 100644 --- a/js/bam/alignmentContainer.js +++ b/js/bam/alignmentContainer.js @@ -160,7 +160,7 @@ class AlignmentContainer { const newRows = [] const undefinedRow = [] for (let row of this.packedAlignmentRows) { - const alignment = row.findAlignment(options.position) + const alignment = row.findAlignment(options.position, options.sortAsPairs) if (undefined !== alignment) { newRows.push(row) } else { diff --git a/js/bam/bamAlignmentRow.js b/js/bam/bamAlignmentRow.js index c06801d2a..868664353 100644 --- a/js/bam/bamAlignmentRow.js +++ b/js/bam/bamAlignmentRow.js @@ -23,7 +23,7 @@ * THE SOFTWARE. */ -import {StringUtils} from "../../node_modules/igv-utils/src/index.js" +import { StringUtils } from "../../node_modules/igv-utils/src/index.js" const isString = StringUtils.isString const hashCode = StringUtils.hashCode @@ -36,17 +36,17 @@ class BamAlignmentRow { this.score = undefined } - findAlignment(genomicLocation) { + findAlignment(genomicLocation, sortAsPairs = false) { const alignmentContains = (a, genomicLocation) => { - return genomicLocation >= a.start && genomicLocation < a.start + a.lengthOnRef + return genomicLocation >= a.start && genomicLocation < a.start + (sortAsPairs ? a.fragmentLength : a.lengthOnRef) } // find single alignment that overlaps sort location let centerAlignment for (let i = 0; i < this.alignments.length; i++) { const a = this.alignments[i] - if (genomicLocation >= a.start && genomicLocation < a.start + a.lengthOnRef) { + if (genomicLocation >= a.start && genomicLocation < a.start + (sortAsPairs ? a.fragmentLength : a.lengthOnRef)) { if (a.paired) { if (a.firstAlignment && alignmentContains(a.firstAlignment, genomicLocation)) { centerAlignment = a.firstAlignment @@ -64,11 +64,11 @@ class BamAlignmentRow { } - getSortValue({position, option, tag}, alignmentContainer) { + getSortValue({ position, option, tag, sortAsPairs }, alignmentContainer) { if (!option) option = "BASE" - const alignment = this.findAlignment(position) + const alignment = this.findAlignment(position, sortAsPairs) if (undefined === alignment) { // This condition should never occur return Number.MAX_VALUE } diff --git a/js/bam/bamTrack.js b/js/bam/bamTrack.js index 06cabaa90..a5397bab0 100644 --- a/js/bam/bamTrack.js +++ b/js/bam/bamTrack.js @@ -1240,7 +1240,8 @@ class AlignmentTrack { chr: viewport.referenceFrame.chr, position: Math.floor(clickState.genomicLocation), option: option, - direction: direction + direction: direction, + sortAsPairs: viewport.trackView.track.viewAsPairs } this.parent.sortObject = newSortObject viewport.cachedFeatures.sortRows(newSortObject)