Unverified Commit 16c42b78 authored by Ridwan Amode's avatar Ridwan Amode Committed by GitHub
Browse files

Add transcript filter functionality to entity viewer (#465)

* ENSWBSITES-888: Filter transcript functionality and writing test for the functionality of filtering by so_term
parent 6bfc11aa
Pipeline #137491 passed with stages
in 8 minutes and 37 seconds
...@@ -25,6 +25,8 @@ import { ...@@ -25,6 +25,8 @@ import {
defaultSort defaultSort
} from 'src/content/app/entity-viewer/shared/helpers/transcripts-sorter'; } from 'src/content/app/entity-viewer/shared/helpers/transcripts-sorter';
import { filterTranscriptsBySOTerm } from 'src/content/app/entity-viewer/shared/helpers/transcripts-filter';
import { import {
getExpandedTranscriptIds, getExpandedTranscriptIds,
getExpandedTranscriptDownloadIds, getExpandedTranscriptDownloadIds,
...@@ -93,6 +95,9 @@ const DefaultTranscriptslist = (props: Props) => { ...@@ -93,6 +95,9 @@ const DefaultTranscriptslist = (props: Props) => {
const sortingFunction = transcriptSortingFunctions[sortingRule]; const sortingFunction = transcriptSortingFunctions[sortingRule];
const sortedTranscripts = sortingFunction(gene.transcripts) as Transcript[]; const sortedTranscripts = sortingFunction(gene.transcripts) as Transcript[];
const filteredTranscripts = Object.values(filters).some(Boolean)
? (filterTranscriptsBySOTerm(sortedTranscripts, filters) as Transcript[])
: sortedTranscripts;
const [isFilterOpen, setFilterOpen] = useState(false); const [isFilterOpen, setFilterOpen] = useState(false);
...@@ -101,7 +106,7 @@ const DefaultTranscriptslist = (props: Props) => { ...@@ -101,7 +106,7 @@ const DefaultTranscriptslist = (props: Props) => {
// Expand the first transcript by default // Expand the first transcript by default
if (!hasExpandedTranscripts) { if (!hasExpandedTranscripts) {
dispatch(toggleTranscriptInfo(sortedTranscripts[0].stable_id)); dispatch(toggleTranscriptInfo(filteredTranscripts[0].stable_id));
} }
}, []); }, []);
...@@ -129,7 +134,7 @@ const DefaultTranscriptslist = (props: Props) => { ...@@ -129,7 +134,7 @@ const DefaultTranscriptslist = (props: Props) => {
<TranscriptsFilter <TranscriptsFilter
label={filterLabel} label={filterLabel}
toggleFilter={toggleFilter} toggleFilter={toggleFilter}
transcripts={sortedTranscripts} transcripts={filteredTranscripts}
/> />
)} )}
<div className={styles.row}> <div className={styles.row}>
...@@ -144,7 +149,7 @@ const DefaultTranscriptslist = (props: Props) => { ...@@ -144,7 +149,7 @@ const DefaultTranscriptslist = (props: Props) => {
</div> </div>
<div className={styles.content}> <div className={styles.content}>
<StripedBackground {...props} /> <StripedBackground {...props} />
{sortedTranscripts.map((transcript, index) => { {filteredTranscripts.map((transcript, index) => {
const expandTranscript = expandedTranscriptIds.includes( const expandTranscript = expandedTranscriptIds.includes(
transcript.stable_id transcript.stable_id
); );
......
import { filterTranscriptsBySOTerm } from '../transcripts-filter';
import { createTranscript } from 'tests/fixtures/entity-viewer/transcript';
/* Creating filters with different filter set to true/false */
const proteinCodingFilters = {
protein_coding: true,
retained_intron: false,
processed_transcript: false,
nonsense_mediated_decay: false
};
/* Creating dummy transcripts with different different so_term to test so_term filtering */
/* note that the so_term can be any string matching the filters object above */
const createProteinCodingTranscript = () => {
const transcript = createTranscript();
transcript.so_term = 'protein_coding';
return transcript;
};
const createProcessedTranscript = () => {
const transcript = createTranscript();
transcript.so_term = 'processed_transcript';
return transcript;
};
const createRetainedIntronTranscript = () => {
const transcript = createTranscript();
transcript.so_term = 'retained_intron';
return transcript;
};
const createNonsenseMediatedDecayTranscript = () => {
const transcript = createTranscript();
transcript.so_term = 'nonsense_mediated_decay';
return transcript;
};
const ProteinCodingTranscript = createProteinCodingTranscript();
const ProcessedTranscript = createProcessedTranscript();
const RetainedIntronTranscript = createRetainedIntronTranscript();
const NonsenseMediatedDecayTranscript = createNonsenseMediatedDecayTranscript();
describe('filterTranscriptsBySOTerm', () => {
it('filters transcripts by so_term correctly', () => {
const Transcripts = [
ProteinCodingTranscript,
ProcessedTranscript,
RetainedIntronTranscript,
NonsenseMediatedDecayTranscript
];
const expectedTranscripts = [ProteinCodingTranscript];
const filteredTranscripts = filterTranscriptsBySOTerm(
Transcripts,
proteinCodingFilters
);
expect(filteredTranscripts).toEqual(expectedTranscripts);
});
});
import { Filters } from 'src/content/app/entity-viewer/state/gene-view/transcripts/geneViewTranscriptsSlice';
import { FullTranscript } from 'src/shared/types/thoas/transcript';
type TranscriptSOTerm = Pick<FullTranscript, 'so_term'>;
export function filterTranscriptsBySOTerm(
transcripts: TranscriptSOTerm[],
filters: Filters
) {
const soTerms = Object.keys(filters).filter((key) => filters[key]);
const filteredTranscripts = transcripts.filter((transcript) => {
return soTerms.includes(transcript.so_term);
});
return filteredTranscripts;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment