Skip to content

Commit

Permalink
Moved query track removal code from micro-tracks service to micro-tra…
Browse files Browse the repository at this point in the history
…cks effects and updated it to fit the Observable paradigm. Also removed the deprecated merge tracks method from the micro-tracks service that used to be called in conjunction with the query track removal code.
  • Loading branch information
alancleary committed Oct 21, 2019
1 parent 46a02c9 commit 612d983
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 33 deletions.
34 changes: 4 additions & 30 deletions client/src/app/gene/services/micro-tracks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@ export class MicroTracksService extends HttpService {
matched: String(params.matched),
query: families,
};
return this._makeRequest<{tracks: Track[]}>(serverID, 'microSearch', body).pipe(
map(({tracks}) => {
return tracks;
}),
catchError((error) => throwError(error)),
);
return this._makeRequest<{tracks: Track[]}>(serverID, 'microSearch', body)
.pipe(
map(({tracks}) => tracks),
catchError((error) => throwError(error)));
}

updateParams(params: QueryParams): void {
Expand Down Expand Up @@ -99,28 +97,4 @@ export class MicroTracksService extends HttpService {
select(fromMicroTracks.getAlignedMicroTrackCluster(id))
);
}

// merges all the groups in the given array into a single group
private _mergeTracks(toMerge: Group[]): Group {
const merged: Group = Object.assign({}, toMerge[0]);
//merged.genes = toMerge[0].genes.slice();
//const seen = new Set(merged.genes.map((g) => g.id));
//for (let i = 1; i < toMerge.length; i++) {
// for (const g of toMerge[i].genes) {
// if (!seen.has(g.id)) {
// seen.add(g.id);
// merged.genes.push(g);
// }
// }
//}
return merged;
}

// removes the query from given MicroTracks if present
//private _removeQuery(query: Group, tracks: MicroTracks): void {
//const genes = new Set(query.genes.map((g) => g.id));
//tracks.groups = tracks.groups.filter((group) => {
// return !group.genes.some((g) => genes.has(g.id));
//});
//}
}
21 changes: 18 additions & 3 deletions client/src/app/gene/store/effects/micro-tracks.effects.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// Angular
import { Injectable } from '@angular/core';
// store
import { Action, Store } from '@ngrx/store';
import { Store } from '@ngrx/store';
import * as fromRoot from '@gcv/gene/store/reducers';
import * as fromMicroTracks from '@gcv/gene/store/selectors/micro-tracks/';
import * as fromRouter from '@gcv/gene/store/selectors/router/';
import { Effect, Actions, ofType } from '@ngrx/effects';
import { combineLatest, of } from 'rxjs';
import { catchError, map, switchMap, withLatestFrom } from 'rxjs/operators';
import * as microTracksActions from '@gcv/gene/store/actions/micro-tracks.actions';
import * as searchQueryTrackActions from '@gcv/gene/store/actions/search-query-track.actions';
// app
import { Track } from '@gcv/gene/models';
import { ClusterMixin } from '@gcv/gene/models/mixins';
Expand All @@ -22,6 +21,16 @@ export class MicroTracksEffects {
private microTracksService: MicroTracksService,
private store: Store<fromRoot.State>) { }

// private

// returns true if any of the tracks overlap with the given track
private _tracksOverlap(track: Track, tracks: Track[]): boolean {
const genes = new Set(track.genes);
return tracks.some((t) => t.genes.some((g) => genes.has(g)));
}

// public

// clear the store every time new parameters are emitted and search for tracks
@Effect()
clearTracks$ = this.store.select(fromRouter.getMicroQueryParams).pipe(
Expand Down Expand Up @@ -71,7 +80,12 @@ export class MicroTracksEffects {
miroTracksSearch$ = this.actions$.pipe(
ofType(microTracksActions.SEARCH),
map((action: microTracksActions.Search) => action.payload),
switchMap(({cluster, families, source, params}) => {
withLatestFrom(
this.store.select(fromMicroTracks.getClusteredSelectedMicroTracks)),
switchMap(([{cluster, families, source, params}, clusteredTracks]) => {
const clusterTracks = clusteredTracks.filter((t: ClusterMixin) => {
return t.cluster === cluster;
});
const mixin = (track: Track): (Track | ClusterMixin) => {
track.source = source;
const t = Object.create(track);
Expand All @@ -81,6 +95,7 @@ export class MicroTracksEffects {
return this.microTracksService.microTracksSearch(families, params, source)
.pipe(
map((tracks) => {
tracks = tracks.filter((t) => !this._tracksOverlap(t, clusterTracks as Track[]));
const payload = {cluster, source, tracks: tracks.map(mixin)};
return new microTracksActions.SearchSuccess(payload);
}),
Expand Down

0 comments on commit 612d983

Please sign in to comment.