diff --git a/client/src/app/gene/services/micro-tracks.service.ts b/client/src/app/gene/services/micro-tracks.service.ts index 62968280..afe4fb4b 100644 --- a/client/src/app/gene/services/micro-tracks.service.ts +++ b/client/src/app/gene/services/micro-tracks.service.ts @@ -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 { @@ -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)); - //}); - //} } diff --git a/client/src/app/gene/store/effects/micro-tracks.effects.ts b/client/src/app/gene/store/effects/micro-tracks.effects.ts index 34c35341..3e0308f0 100644 --- a/client/src/app/gene/store/effects/micro-tracks.effects.ts +++ b/client/src/app/gene/store/effects/micro-tracks.effects.ts @@ -1,7 +1,7 @@ // 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/'; @@ -9,7 +9,6 @@ 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'; @@ -22,6 +21,16 @@ export class MicroTracksEffects { private microTracksService: MicroTracksService, private store: Store) { } + // 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( @@ -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); @@ -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); }),