Skip to content

Commit

Permalink
Merge pull request #85 from molgenis/feat/inheritance
Browse files Browse the repository at this point in the history
Feature: add inheritance filtering
  • Loading branch information
dennishendriksen authored Dec 7, 2020
2 parents cf1bcf9 + bce199b commit b529949
Show file tree
Hide file tree
Showing 12 changed files with 217 additions and 14 deletions.
34 changes: 32 additions & 2 deletions src/components/RecordTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,11 @@ export default Vue.extend({
'hasCapice',
'getAnnotation',
'isAnnotationEnabled',
'isRecordsContainPhenotypes'
'isRecordsContainPhenotypes',
'isSamplesContainInheritance',
'isSamplesContainDenovo'
]),
...mapState(['metadata', 'records', 'annotations', 'selectedSamplePhenotypes', 'filterRecordsByPhenotype']),
...mapState(['metadata', 'records', 'annotations', 'selectedSamplePhenotypes', 'filterRecordsByPhenotype', 'filterRecordsByInheritance', 'filterRecordsByDenovo']),
genomeAssembly(): string {
return this.metadata.htsFile.genomeAssembly;
},
Expand Down Expand Up @@ -356,6 +358,12 @@ export default Vue.extend({
if (this.isRecordsContainPhenotypes && this.hasSamplePhenotypes() && this.filterRecordsByPhenotype) {
queries.push(this.createSamplePhenotypesQuery());
}
if (this.isSamplesContainInheritance && this.filterRecordsByInheritance) {
queries.push(this.createSampleInheritanceQuery());
}
if (this.isSamplesContainDenovo && this.filterRecordsByDenovo) {
queries.push(this.createSampleDenovoQuery());
}
// todo: translate ctx filter param to query
let query: Query | ComposedQuery | undefined;
Expand All @@ -378,6 +386,20 @@ export default Vue.extend({
args: ['het', 'hom_a', 'part']
};
},
createSampleInheritanceQuery(): Query {
return {
selector: ['s', this.sample.index, 'f', 'VIM'],
operator: '==',
args:1
};
},
createSampleDenovoQuery(): Query {
return {
selector: ['s', this.sample.index, 'f', 'VID'],
operator:'==',
args:1
};
},
hasSamplePhenotypes(): boolean {
return this.selectedSamplePhenotypes !== null && this.selectedSamplePhenotypes.page.totalElements > 0;
},
Expand Down Expand Up @@ -484,6 +506,14 @@ export default Vue.extend({
'$store.state.filterRecordsByPhenotype'() {
this.page.currentPage = 1;
(this.$refs.table as BTable).refresh();
},
'$store.state.filterRecordsByInheritance'() {
this.page.currentPage = 1;
(this.$refs.table as BTable).refresh();
},
'$store.state.filterRecordsByDenovo'() {
this.page.currentPage = 1;
(this.$refs.table as BTable).refresh();
}
}
});
Expand Down
34 changes: 24 additions & 10 deletions src/components/RecordTableControls.vue
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
<template>
<b-form-checkbox
v-if="isRecordsContainPhenotypes"
:checked="filterRecordsByPhenotype"
@change="this.setFilterRecordsByPhenotype"
>{{ $t('matchPhenotype') }}</b-form-checkbox
>
<div>
<b-form-checkbox
v-if="isRecordsContainPhenotypes"
:checked="filterRecordsByPhenotype"
@change="this.setFilterRecordsByPhenotype"
>{{ $t('matchPhenotype') }}
</b-form-checkbox>
<b-form-checkbox
v-if="isSamplesContainInheritance"
:checked="filterRecordsByInheritance"
@change="this.setFilterRecordsByInheritance"
>{{ $t('matchInheritance') }}
</b-form-checkbox>
<b-form-checkbox
v-if="isSamplesContainDenovo"
:checked="filterRecordsByDenovo"
@change="this.setFilterRecordsByDenovo"
>{{ $t('matchDenovo') }}
</b-form-checkbox>
</div>
</template>

<script lang="ts">
import Vue from 'vue';
import { mapActions, mapGetters, mapState } from 'vuex';
import {mapActions, mapGetters, mapState} from 'vuex';
export default Vue.extend({
computed: {
...mapGetters(['isRecordsContainPhenotypes']),
...mapState(['filterRecordsByPhenotype'])
...mapGetters(['isRecordsContainPhenotypes', 'isSamplesContainInheritance', 'isSamplesContainDenovo']),
...mapState(['filterRecordsByPhenotype', 'filterRecordsByInheritance', 'filterRecordsByDenovo'])
},
methods: {
...mapActions(['setFilterRecordsByPhenotype'])
...mapActions(['setFilterRecordsByPhenotype', 'setFilterRecordsByInheritance', 'setFilterRecordsByDenovo'])
}
});
</script>
4 changes: 3 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,7 @@
"open": "Open...",
"save": "Save...",
"exit": "Exit",
"matchPhenotype": "Only display records that match sample phenotype(s)"
"matchPhenotype": "Only display records that match sample phenotype(s)",
"matchInheritance": "Only display records that match inheritance",
"matchDenovo": "Only display records that are denovo"
}
6 changes: 6 additions & 0 deletions src/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ export default {
},
setFilterRecordsByPhenotype({ commit }: ActionContext<State, State>, value: boolean) {
commit('setFilterRecordsByPhenotype', value);
},
setFilterRecordsByInheritance({ commit }: ActionContext<State, State>, value: boolean) {
commit('setFilterRecordsByInheritance', value);
},
setFilterRecordsByDenovo({ commit }: ActionContext<State, State>, value: boolean) {
commit('setFilterRecordsByDenovo', value);
}
};

Expand Down
26 changes: 26 additions & 0 deletions src/store/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,31 @@ export default {
}
}
return hasPhenotypeAssociations;
},
/**
* Returns whether records contain inheritance matching information.
*/
isSamplesContainInheritance: (state: State): boolean => {
let hasSampleInheritance;
if (state.metadata === null) {
hasSampleInheritance = false;
} else {
const vimFormat = state.metadata.records.format.find(item => item.id === 'VIM');
hasSampleInheritance = vimFormat !== undefined
}
return hasSampleInheritance;
},
/**
* Returns whether records contain denovo information.
*/
isSamplesContainDenovo: (state: State): boolean => {
let hasSampleInheritance;
if (state.metadata === null) {
hasSampleInheritance = false;
} else {
const vimFormat = state.metadata.records.format.find(item => item.id === 'VID');
hasSampleInheritance = vimFormat !== undefined
}
return hasSampleInheritance;
}
};
6 changes: 6 additions & 0 deletions src/store/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,11 @@ export default {
},
setFilterRecordsByPhenotype(state: State, value: boolean) {
state.filterRecordsByPhenotype = value;
},
setFilterRecordsByInheritance(state: State, value: boolean) {
state.filterRecordsByInheritance = value;
},
setFilterRecordsByDenovo(state: State, value: boolean) {
state.filterRecordsByDenovo = value;
}
};
2 changes: 2 additions & 0 deletions src/store/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const state: State = {
selectedSamplePhenotypes: null,
records: null,
filterRecordsByPhenotype: true,
filterRecordsByInheritance: false,
filterRecordsByDenovo: false,
annotations: null
};

Expand Down
2 changes: 2 additions & 0 deletions src/types/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ export type State = {
selectedSamplePhenotypes: PagedItems<Phenotype> | null;
records: PagedItems<Record> | null;
filterRecordsByPhenotype: boolean;
filterRecordsByInheritance: boolean;
filterRecordsByDenovo: boolean;
annotations: Annotations | null;
};
2 changes: 1 addition & 1 deletion src/views/Samples.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default Vue.extend({
components: { SampleNavigation, SampleReport },
computed: {
...mapGetters(['samples', 'getSampleById']),
...mapState(['selectedSample', 'selectedSamplePhenotypes'])
...mapState(['selectedSample', 'selectedSamplePhenotypes', 'selectedSampleInheritance', 'selectedSampleDenovo'])
},
methods: {
...mapActions(['loadMetadata', 'loadSamples', 'selectSample']),
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/store/actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,17 @@ test('set filter records by phenotype', async done => {
expect(commit).toHaveBeenCalledWith('setFilterRecordsByPhenotype', true);
done();
});

test('set filter records by inheritance', async done => {
const commit = jest.fn() as Commit;
actions.setFilterRecordsByInheritance({ commit } as ActionContext<State, State>, true);
expect(commit).toHaveBeenCalledWith('setFilterRecordsByInheritance', true);
done();
});

test('set filter records by denovo status', async done => {
const commit = jest.fn() as Commit;
actions.setFilterRecordsByDenovo({ commit } as ActionContext<State, State>, true);
expect(commit).toHaveBeenCalledWith('setFilterRecordsByDenovo', true);
done();
});
89 changes: 89 additions & 0 deletions tests/unit/store/getters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { State } from '@/types/State';
import { GenomeBrowserDb } from '@/types/GenomeBrowserDb';
import { mock } from 'ts-mockito';
import {
FormatMetadata,
HtsFileMetadata,
InfoMetadata,
Metadata,
Expand Down Expand Up @@ -403,3 +404,91 @@ test('whether records contain phenotype associations without VEP', () => {
};
expect(getters.isRecordsContainPhenotypes(testState)).toEqual(false);
});

test('whether records contain inheritance matching information. true.', () => {
const formatMetadata = mock<FormatMetadata>();
formatMetadata.id = 'VIM';

const recordsMetadata = mock<RecordsMetadata>();
recordsMetadata.format = [formatMetadata];

const metadata = mock<Metadata>();
metadata.records = recordsMetadata;

const testState: State = {
...initialState,
metadata: metadata
};
expect(getters.isSamplesContainInheritance(testState)).toEqual(true);
});

test('whether records contain inheritance matching information. false.', () => {
const formatMetadata = mock<FormatMetadata>();
formatMetadata.id = 'OTHER';

const recordsMetadata = mock<RecordsMetadata>();
recordsMetadata.format = [formatMetadata];

const metadata = mock<Metadata>();
metadata.records = recordsMetadata;

const testState: State = {
...initialState,
metadata: metadata
};
expect(getters.isSamplesContainInheritance(testState)).toEqual(false);
});

test('whether records contain inheritance matching information. null.', () => {
const metadata =null;

const testState: State = {
...initialState,
metadata: metadata
};
expect(getters.isSamplesContainInheritance(testState)).toEqual(false);
});

test('whether records contain denovo information. true.', () => {
const formatMetadata = mock<FormatMetadata>();
formatMetadata.id = 'VID';

const recordsMetadata = mock<RecordsMetadata>();
recordsMetadata.format = [formatMetadata];

const metadata = mock<Metadata>();
metadata.records = recordsMetadata;

const testState: State = {
...initialState,
metadata: metadata
};
expect(getters.isSamplesContainDenovo(testState)).toEqual(true);
});

test('whether records contain denovo information. false.', () => {
const formatMetadata = mock<FormatMetadata>();
formatMetadata.id = 'OTHER';

const recordsMetadata = mock<RecordsMetadata>();
recordsMetadata.format = [formatMetadata];

const metadata = mock<Metadata>();
metadata.records = recordsMetadata;

const testState: State = {
...initialState,
metadata: metadata
};
expect(getters.isSamplesContainDenovo(testState)).toEqual(false);
});

test('whether records contain denovo information. null.', () => {
const metadata =null;

const testState: State = {
...initialState,
metadata: metadata
};
expect(getters.isSamplesContainDenovo(testState)).toEqual(false);
});
12 changes: 12 additions & 0 deletions tests/unit/store/mutations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,15 @@ test('set filter records by phenotype', () => {
mutations.setFilterRecordsByPhenotype(testState, false);
expect(testState.filterRecordsByPhenotype).toBe(false);
});

test('set filter records by inheritance', () => {
const testState: State = { ...initialState };
mutations.setFilterRecordsByInheritance(testState, false);
expect(testState.filterRecordsByInheritance).toBe(false);
});

test('set filter records by denovo', () => {
const testState: State = { ...initialState };
mutations.setFilterRecordsByDenovo(testState, false);
expect(testState.filterRecordsByDenovo).toBe(false);
});

0 comments on commit b529949

Please sign in to comment.