Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy feature from evidence track #447

Open
garrettjstevens opened this issue Sep 24, 2024 · 1 comment · May be fixed by #473
Open

Copy feature from evidence track #447

garrettjstevens opened this issue Sep 24, 2024 · 1 comment · May be fixed by #473
Assignees

Comments

@garrettjstevens
Copy link
Contributor

Given a JBrowse FeatureTrack such as this:

image

Add an entry the right-click menu so that part or all of the feature can by copied to Apollo.

The two top priority copy actions are:

  • Copy whole gene to Apollo
  • Copy a transcript to an existing gene in Apollo

Other copy actions may be implemented on further discussion.

@garrettjstevens
Copy link
Contributor Author

We can use the feature we already have that creates an Apollo feature from a JBrowse alignment feature as a template for this.

In packages/jbrowse-plugin-apollo/src/index.ts, add to an extension point like this:

pluginManager.addToExtensionPoint(
  'Core-extendPluggableElement',
  annotationFromJBrowseFeature,
)

Then the annotationFromJBrowseFeature function would look something like this:

export function annotationFromJBrowseFeature(pluggableElement: PluggableElementBase) {
  if (pluggableElement.name !== 'BasicFeatureDisplay') {
    return pluggableElement
  }
  const { stateModel } = pluggableElement as DisplayType
  const newStateModel = stateModel
    .views((self) => ({

      async createFeature() {
        const feature = self.contextMenuFeature
        // create the feature...
        const change = new AddFeatureChange({
          changedIds: [newFeature._id],
          typeName: 'AddFeatureChange',
          assembly: assemblyId,
          addedFeature: newFeature,
        })
        const session = getSession(self)
        await (
          session as unknown as ApolloSessionModel
        ).apolloDataStore.changeManager.submit(change)
        session.notify('Annotation added successfully', 'success')
      },
    }))
    .views((self) => {
      const superContextMenuItems = self.contextMenuItems
      return {
        contextMenuItems() {
          const feature = self.contextMenuFeature
          if (!feature) {
            return superContextMenuItems()
          }
          return [
            ...superContextMenuItems(),
            {
              label: 'Create Apollo annotation',
              icon: AddIcon,
              onClick: self.createFeature,
            },
          ]
        },
      }
    })
  ;(pluggableElement as DisplayType).stateModel = newStateModel
  return pluggableElement
}

If you need to create a dialog instead of immediately copying the feature, the onClick can be changed to call session.queueDialog, see packages/jbrowse-plugin-apollo/src/ApolloInternetAccount/addMenuItems.ts for examples.

Let's start with a "Copy whole feature to Apollo" menu item that doesn't need a dialog. Once this works, we can figure out what a "Copy subfeature to Apollo" dialog might look like, but in general it should list all the subfeature in the JBrowse feature and ask which one(s) to copy, and ask for a destination gene in Apollo (or have a option to add them to a new gene?). The destination genes can be any in the Apollo track that overlap the coordinates of the JBrowse feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

2 participants