Skip to content

Commit

Permalink
Refactor annotations filter module into smaller methods
Browse files Browse the repository at this point in the history
  • Loading branch information
eweitz committed Sep 3, 2018
1 parent 03ce150 commit ea33d74
Showing 1 changed file with 48 additions and 32 deletions.
80 changes: 48 additions & 32 deletions src/js/annotations/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,12 @@ function restoreDefaultTracks() {
ideo.drawAnnots(ideo.processAnnotData(ideo.rawAnnots));
}

/**
* Adds or removes tracks from the displayed list of tracks.
* Only works when raw annotations are dense.
*
* @param trackIndexes Array of indexes of tracks to display
*/
function updateDisplayedTracks(trackIndexes) {
var displayedRawAnnotsByChr, displayedAnnots, i, j, rawAnnots, annots, annot,
trackIndex,
ideo = this,
annotsByChr = ideo.rawAnnots.annots;
function getDisplayedRawAnnotsByChr(annotsByChr, trackIndexes) {
var annot, displayedRawAnnotsByChr, annots, i, displayedAnnots, j,
trackIndex;

displayedRawAnnotsByChr = [];

ideo.config.numAnnotTracks = trackIndexes.length;

// Filter displayed tracks by selected track indexes
for (i = 0; i < annotsByChr.length; i++) {
annots = annotsByChr[i];
Expand All @@ -45,6 +35,25 @@ function updateDisplayedTracks(trackIndexes) {
displayedRawAnnotsByChr.push({chr: annots.chr, annots: displayedAnnots});
}

return displayedRawAnnotsByChr;
}

/**
* Adds or removes tracks from the displayed list of tracks.
* Only works when raw annotations are dense.
*
* @param trackIndexes Array of indexes of tracks to display
*/
function updateDisplayedTracks(trackIndexes) {
var displayedRawAnnotsByChr, displayedAnnots, rawAnnots, trackIndex,
ideo = this,
annotsByChr = ideo.rawAnnots.annots;

ideo.config.numAnnotTracks = trackIndexes.length;

displayedRawAnnotsByChr =
getDisplayedRawAnnotsByChr(annotsByChr, trackIndexes);

rawAnnots = {keys: ideo.rawAnnots.keys, annots: displayedRawAnnotsByChr};

displayedAnnots = ideo.processAnnotData(rawAnnots);
Expand All @@ -57,26 +66,12 @@ function updateDisplayedTracks(trackIndexes) {
return displayedAnnots;
}

function setOriginalTrackIndexes(rawAnnots) {
var keys, annotsByChr, annots, annot, i, j, trackIndexOriginal,
setAnnotsByChr, setAnnots, numAvailTracks;

keys = rawAnnots.keys;

// If this method is unnecessary, pass through
if (
keys.length < 4 ||
keys[3] !== 'trackIndex' ||
keys[4] === 'trackIndexOriginal'
) {
return rawAnnots;
}
function getSetAnnotsByChr(annotsByChr, ideo) {
var i, j, annots, annot, setAnnots, trackIndexOriginal, numAvailTracks,
setAnnotsByChr = [];

numAvailTracks = 1;

annotsByChr = rawAnnots.annots;
setAnnotsByChr = [];

for (i = 0; i < annotsByChr.length; i++) {
annots = annotsByChr[i];
setAnnots = [];
Expand All @@ -92,11 +87,32 @@ function setOriginalTrackIndexes(rawAnnots) {
setAnnotsByChr.push({chr: annots.chr, annots: setAnnots});
}

ideo.numAvailTracks = numAvailTracks;

return setAnnotsByChr;
}

function setOriginalTrackIndexes(rawAnnots) {
var keys, annotsByChr, setAnnotsByChr,
ideo = this;

keys = rawAnnots.keys;

// If this method is unnecessary, pass through
if (
keys.length < 4 ||
keys[3] !== 'trackIndex' ||
keys[4] === 'trackIndexOriginal'
) {
return rawAnnots;
}

annotsByChr = rawAnnots.annots;
setAnnotsByChr = getSetAnnotsByChr(annotsByChr, ideo);

keys.splice(4, 0, 'trackIndexOriginal');
rawAnnots = {keys: keys, annots: setAnnotsByChr};

this.numAvailTracks = numAvailTracks;

return rawAnnots;
}

Expand Down

0 comments on commit ea33d74

Please sign in to comment.