44/* eslint-disable @typescript-eslint/no-unsafe-call */
55/* eslint-disable @typescript-eslint/no-unsafe-return */
66import type { AnnotationFeatureSnapshot } from '@apollo-annotation/mst'
7- import type { Assembly } from '@jbrowse/core/assemblyManager/assembly'
87import type {
98 DisplayType ,
109 PluggableElementType ,
@@ -14,11 +13,14 @@ import {
1413 getContainingView ,
1514 getSession ,
1615} from '@jbrowse/core/util'
16+ import type { Feature } from '@jbrowse/core/util/simpleFeature'
1717import type { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'
1818import AddIcon from '@mui/icons-material/Add'
1919import ObjectID from 'bson-objectid'
2020
21+ import { CollaborationServerDriver } from '../BackendDrivers'
2122import { CreateApolloAnnotation } from '../components/CreateApolloAnnotation'
23+ import type { ApolloSessionModel } from '../session'
2224
2325function parseCigar ( cigar : string ) : [ string , number ] [ ] {
2426 const regex = / ( \d + ) ( [ M I D N S H P X = ] ) / g
@@ -44,7 +46,7 @@ export function annotationFromPileup(pluggableElement: PluggableElementType) {
4446 return lgv . dynamicBlocks . contentBlocks [ 0 ]
4547 } ,
4648 getAssembly ( ) {
47- const firstRegion = self . getFirstRegion ( )
49+ const firstRegion = this . getFirstRegion ( )
4850 const session = getSession ( self )
4951 const { assemblyManager } = session
5052 const { assemblyName } = firstRegion
@@ -54,35 +56,13 @@ export function annotationFromPileup(pluggableElement: PluggableElementType) {
5456 }
5557 return assembly
5658 } ,
57- getRefSeqId ( assembly : Assembly ) {
58- const firstRegion = self . getFirstRegion ( )
59- const { refName } = firstRegion
60- const { refNameAliases } = assembly
61- if ( ! refNameAliases ) {
62- throw new Error ( `Could not find aliases for ${ assembly . name } ` )
63- }
64- const newRefNames = [ ...Object . entries ( refNameAliases ) ]
65- . filter ( ( [ id , refName ] ) => id !== refName )
66- . map ( ( [ id , refName ] ) => ( {
67- _id : id ,
68- name : refName ,
69- } ) )
70- const refSeqId = newRefNames . find ( ( item ) => item . name === refName ) ?. _id
71- if ( ! refSeqId ) {
72- throw new Error ( `Could not find refSeqId named ${ refName } ` )
73- }
74- return refSeqId
75- } ,
76- getAnnotationFeature ( ) {
77- const feature = self . contextMenuFeature
78- const assembly = self . getAssembly ( )
79- const refSeqId = self . getRefSeqId ( assembly )
80- const start : number = feature . get ( 'start' )
81- const end : number = feature . get ( 'end' )
82- const strand = feature . get ( 'strand' )
83- const name = feature . get ( 'name' )
59+ getAnnotationFeature ( jbrowseFeature : Feature , refSeqId : string ) {
60+ const start : number = jbrowseFeature . get ( 'start' )
61+ const end : number = jbrowseFeature . get ( 'end' )
62+ const strand = jbrowseFeature . get ( 'strand' ) as 1 | - 1 | undefined
63+ const name = jbrowseFeature . get ( 'name' ) as string | undefined
8464
85- const cigarData : string = feature . get ( 'CIGAR' )
65+ const cigarData = jbrowseFeature . get ( 'CIGAR' ) as string
8666 const ops = parseCigar ( cigarData )
8767 let position = start
8868 let currentExonStart : number | undefined
@@ -151,9 +131,10 @@ export function annotationFromPileup(pluggableElement: PluggableElementType) {
151131 max : end ,
152132 type : 'mRNA' ,
153133 strand,
154- attributes : {
155- name : [ name ] ,
156- } ,
134+ }
135+ if ( name ) {
136+ newFeature . attributes = { }
137+ newFeature . attributes . gff_name = [ name ]
157138 }
158139 if ( exons . length === 0 ) {
159140 return newFeature
@@ -183,16 +164,32 @@ export function annotationFromPileup(pluggableElement: PluggableElementType) {
183164 const session = getSession ( self )
184165 const assembly = self . getAssembly ( )
185166 const region = self . getFirstRegion ( )
186- const feature = self . contextMenuFeature
187- if ( ! feature ) {
167+ const jbrowseFeature = self . contextMenuFeature
168+ if ( ! jbrowseFeature ) {
188169 return superContextMenuItems ( )
189170 }
190171 return [
191172 ...superContextMenuItems ( ) ,
192173 {
193174 label : 'Create Apollo annotation' ,
194175 icon : AddIcon ,
195- onClick : ( ) => {
176+ onClick : async ( ) => {
177+ const backendDriver = (
178+ session as unknown as ApolloSessionModel
179+ ) . apolloDataStore . getBackendDriver ( region . assemblyName )
180+ let refSeqId = region . refName
181+ if ( backendDriver instanceof CollaborationServerDriver ) {
182+ const backendRefSeqId = await backendDriver . getRefSeqId (
183+ region . assemblyName ,
184+ region . refName ,
185+ )
186+ if ( ! backendRefSeqId ) {
187+ throw new Error (
188+ `Could not find refSeq for "${ region . refName } "` ,
189+ )
190+ }
191+ refSeqId = backendRefSeqId
192+ }
196193 ; ( session as unknown as AbstractSessionModel ) . queueDialog (
197194 ( doneCallback ) => [
198195 CreateApolloAnnotation ,
@@ -201,9 +198,12 @@ export function annotationFromPileup(pluggableElement: PluggableElementType) {
201198 handleClose : ( ) => {
202199 doneCallback ( )
203200 } ,
204- annotationFeature : self . getAnnotationFeature ( assembly ) ,
201+ annotationFeature : self . getAnnotationFeature (
202+ jbrowseFeature ,
203+ refSeqId ,
204+ ) ,
205205 assembly,
206- refSeqId : self . getRefSeqId ( assembly ) ,
206+ refSeqId,
207207 region,
208208 } ,
209209 ] ,
0 commit comments