Skip to content

Commit

Permalink
can sort as pairs when view as pairs, sort as single reads otherwise (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonGen authored Jul 4, 2023
1 parent 2b5b2fe commit 38b2acf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion js/bam/alignmentContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions js/bam/bamAlignmentRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion js/bam/bamTrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 38b2acf

Please sign in to comment.