@@ -10,21 +10,24 @@ import {
1010 isSessionModelWithWidgets ,
1111} from '@jbrowse/core/util'
1212import { type LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'
13- import SkipNextRoundedIcon from '@mui/icons-material/SkipNextRounded'
14- import SkipPreviousRoundedIcon from '@mui/icons-material/SkipPreviousRounded'
1513import { alpha } from '@mui/material'
1614
1715import { type OntologyRecord } from '../../OntologyManager'
1816import { MergeExons , MergeTranscripts , SplitExon } from '../../components'
19- import { type ApolloSessionModel } from '../../session'
2017import {
2118 type MousePosition ,
2219 type MousePositionWithFeature ,
2320 containsSelectedFeature ,
21+ getAdjacentExons ,
2422 getMinAndMaxPx ,
2523 getOverlappingEdge ,
24+ getStreamIcon ,
25+ isCDSFeature ,
26+ isExonFeature ,
2627 isMousePositionWithFeature ,
28+ isTranscriptFeature ,
2729 navToFeatureCenter ,
30+ selectFeatureAndOpenWidget ,
2831} from '../../util'
2932import { getRelatedFeatures } from '../../util/annotationFeatureUtils'
3033import { type LinearApolloDisplay } from '../stateModel'
@@ -696,45 +699,6 @@ function getRowForFeature(
696699 return
697700}
698701
699- function selectFeatureAndOpenWidget (
700- stateModel : LinearApolloDisplayMouseEvents ,
701- feature : AnnotationFeature ,
702- ) {
703- if ( stateModel . apolloDragging ) {
704- return
705- }
706- stateModel . setSelectedFeature ( feature )
707- const { session } = stateModel
708- const { apolloDataStore } = session
709- const { featureTypeOntology } = apolloDataStore . ontologyManager
710- if ( ! featureTypeOntology ) {
711- throw new Error ( 'featureTypeOntology is undefined' )
712- }
713-
714- let containsCDSOrExon = false
715- for ( const [ , child ] of feature . children ?? [ ] ) {
716- if (
717- featureTypeOntology . isTypeOf ( child . type , 'CDS' ) ||
718- featureTypeOntology . isTypeOf ( child . type , 'exon' )
719- ) {
720- containsCDSOrExon = true
721- break
722- }
723- }
724- if (
725- ( featureTypeOntology . isTypeOf ( feature . type , 'transcript' ) ||
726- featureTypeOntology . isTypeOf ( feature . type , 'pseudogenic_transcript' ) ) &&
727- containsCDSOrExon
728- ) {
729- stateModel . showFeatureDetailsWidget ( feature , [
730- 'ApolloTranscriptDetails' ,
731- 'apolloTranscriptDetails' ,
732- ] )
733- } else {
734- stateModel . showFeatureDetailsWidget ( feature )
735- }
736- }
737-
738702function onMouseDown (
739703 stateModel : LinearApolloDisplay ,
740704 currentMousePosition : MousePositionWithFeature ,
@@ -859,131 +823,6 @@ function getDraggableFeatureInfo(
859823 return
860824}
861825
862- function isTranscriptFeature (
863- feature : AnnotationFeature ,
864- session : ApolloSessionModel ,
865- ) : boolean {
866- const { featureTypeOntology } = session . apolloDataStore . ontologyManager
867- if ( ! featureTypeOntology ) {
868- throw new Error ( 'featureTypeOntology is undefined' )
869- }
870- return (
871- featureTypeOntology . isTypeOf ( feature . type , 'transcript' ) ||
872- featureTypeOntology . isTypeOf ( feature . type , 'pseudogenic_transcript' )
873- )
874- }
875-
876- function isExonFeature (
877- feature : AnnotationFeature ,
878- session : ApolloSessionModel ,
879- ) : boolean {
880- const { featureTypeOntology } = session . apolloDataStore . ontologyManager
881- if ( ! featureTypeOntology ) {
882- throw new Error ( 'featureTypeOntology is undefined' )
883- }
884- return featureTypeOntology . isTypeOf ( feature . type , 'exon' )
885- }
886-
887- function isCDSFeature (
888- feature : AnnotationFeature ,
889- session : ApolloSessionModel ,
890- ) : boolean {
891- const { featureTypeOntology } = session . apolloDataStore . ontologyManager
892- if ( ! featureTypeOntology ) {
893- throw new Error ( 'featureTypeOntology is undefined' )
894- }
895- return featureTypeOntology . isTypeOf ( feature . type , 'CDS' )
896- }
897-
898- interface AdjacentExons {
899- upstream : AnnotationFeature | undefined
900- downstream : AnnotationFeature | undefined
901- }
902-
903- function getAdjacentExons (
904- currentExon : AnnotationFeature ,
905- display : LinearApolloDisplayMouseEvents ,
906- mousePosition : MousePositionWithFeature ,
907- session : ApolloSessionModel ,
908- ) : AdjacentExons {
909- const lgv = getContainingView (
910- display as BaseDisplayModel ,
911- ) as unknown as LinearGenomeViewModel
912-
913- // Genomic coords of current view
914- const viewGenomicLeft = mousePosition . bp - lgv . bpPerPx * mousePosition . x
915- const viewGenomicRight = viewGenomicLeft + lgv . coarseTotalBp
916- if ( ! currentExon . parent ) {
917- return { upstream : undefined , downstream : undefined }
918- }
919- const transcript = currentExon . parent
920- if ( ! transcript . children ) {
921- throw new Error ( `Error getting children of ${ transcript . _id } ` )
922- }
923- const { featureTypeOntology } = session . apolloDataStore . ontologyManager
924- if ( ! featureTypeOntology ) {
925- throw new Error ( 'featureTypeOntology is undefined' )
926- }
927-
928- let exons = [ ]
929- for ( const [ , child ] of transcript . children ) {
930- if ( featureTypeOntology . isTypeOf ( child . type , 'exon' ) ) {
931- exons . push ( child )
932- }
933- }
934- const adjacentExons : AdjacentExons = {
935- upstream : undefined ,
936- downstream : undefined ,
937- }
938- exons = exons . sort ( ( a , b ) => ( a . min < b . min ? - 1 : 1 ) )
939- for ( const exon of exons ) {
940- if ( exon . min > viewGenomicRight ) {
941- adjacentExons . downstream = exon
942- break
943- }
944- }
945- exons = exons . sort ( ( a , b ) => ( a . min > b . min ? - 1 : 1 ) )
946- for ( const exon of exons ) {
947- if ( exon . max < viewGenomicLeft ) {
948- adjacentExons . upstream = exon
949- break
950- }
951- }
952- if ( transcript . strand === - 1 ) {
953- const newUpstream = adjacentExons . downstream
954- adjacentExons . downstream = adjacentExons . upstream
955- adjacentExons . upstream = newUpstream
956- }
957- return adjacentExons
958- }
959-
960- function getStreamIcon (
961- strand : 1 | - 1 | undefined ,
962- isUpstream : boolean ,
963- isFlipped : boolean | undefined ,
964- ) {
965- // This is the icon you would use for strand=1, downstream, straight
966- // (non-flipped) view
967- let icon = SkipNextRoundedIcon
968-
969- if ( strand === - 1 ) {
970- icon = SkipPreviousRoundedIcon
971- }
972- if ( isUpstream ) {
973- icon =
974- icon === SkipPreviousRoundedIcon
975- ? SkipNextRoundedIcon
976- : SkipPreviousRoundedIcon
977- }
978- if ( isFlipped ) {
979- icon =
980- icon === SkipPreviousRoundedIcon
981- ? SkipNextRoundedIcon
982- : SkipPreviousRoundedIcon
983- }
984- return icon
985- }
986-
987826function getContextMenuItems (
988827 display : LinearApolloDisplayMouseEvents ,
989828 mousePosition : MousePositionWithFeature ,
0 commit comments