import _ from 'lodash' ; import { Hotspot } from 'genome-nexus-ts-api-client' ; import { AggregatedHotspots , IHotspotIndex } from '../model/CancerHotspot' ; import { RemoteData } from '../model/RemoteData' ; import { Mutation } from '../model/Mutation' ; import { extractGenomicLocation , genomicLocationString , } from '../mutation/MutationUtils' ; export function groupCancerHotspotDataByPosition ( ptmData ) { return _ . groupBy ( ptmData , 'proteinPosStart' ) ; } export function indexHotspotsData ( hotspotData ) { if ( hotspotData . result ) { return indexHotspots ( hotspotData . result ) ; } else { return undefined ; } } export function indexHotspots ( hotspots ) { const index = { } ; hotspots . forEach ( ( aggregatedHotspots ) => { index [ genomicLocationString ( aggregatedHotspots . genomicLocation ) ] = aggregatedHotspots ; } ) ; return index ; } export function groupHotspotsByMutations ( mutationsByPosition , index , filter ? ) { const hotspotMap = { } ; _ . keys ( mutationsByPosition ) . forEach ( key => { const position = Number ( key ) ; const hotspots = filterHotspotsByMutations ( mutationsByPosition [ position ] , index , filter ) ; if ( hotspots . length > 0 ) { hotspotMap [ position ] = hotspots ; } } ) ; return hotspotMap ; } export function filterHotspotsByMutation ( mutation , index , filter ? ) { let hotspots = [ ] ; const genomicLocation = extractGenomicLocation ( mutation ) ; const aggregatedHotspots = genomicLocation ? index [ genomicLocationString ( genomicLocation ) ] : undefined ; if ( aggregatedHotspots ) { hotspots = aggregatedHotspots . hotspots ; } if ( filter ) { hotspots = hotspots . filter ( filter ) ; } return hotspots ; } export function filterHotspotsByMutations ( mutations , index , filter ? ) { let hotspots = [ ] ; mutations . forEach ( mutation => { hotspots = hotspots . concat ( filterHotspotsByMutation ( mutation , index , filter ) ) ; } ) ; return hotspots ; } export function filterLinearClusterHotspotsByMutations ( mutations , index ) { let hotspots = [ ] ; mutations . forEach ( mutation => { if ( mutation . mutationType && mutation . mutationType . toLowerCase ( ) . includes ( 'splice' ) ) { hotspots = hotspots . concat ( filterHotspotsByMutation ( mutation , index , ( hotspot ) => hotspot . type . toLowerCase ( ) . includes ( 'splice' ) ) ) ; } else { hotspots = hotspots . concat ( filterHotspotsByMutation ( mutation , index , ( hotspot ) => hotspot . type . toLowerCase ( ) . includes ( 'single' ) || hotspot . type . toLowerCase ( ) . includes ( 'indel' ) ) ) ; } } ) ; return hotspots ; } export function filter3dHotspotsByMutations ( mutations , index ) { return filterHotspotsByMutations ( mutations , index , ( hotspot ) => hotspot . type . toLowerCase ( ) . includes ( '3d' ) ) ; } export function isLinearClusterHotspot ( mutation , index ) { return filterLinearClusterHotspotsByMutations ( [ mutation ] , index ) . length > 0 ; } export function is3dHotspot ( mutation , index ) { return filter3dHotspotsByMutations ( [ mutation ] , index ) . length > 0 ; } export function isHotspot ( mutation , index , filter ? ) { return filterHotspotsByMutations ( [ mutation ] , index , filter ) . length > 0 ; } export function defaultHotspotFilter ( hotspot ) { const type = hotspot . type . toLowerCase ( ) ; return ( type . includes ( 'single' ) || type . includes ( 'indel' ) || type . includes ( '3d' ) || type . includes ( 'splice' ) ) ; }