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

Make feature searching use backend driver #252

Merged
merged 2 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
BaseTextSearchArgs,
} from '@jbrowse/core/data_adapters/BaseAdapter'
import BaseResult from '@jbrowse/core/TextSearch/BaseResults'
import { UriLocation } from '@jbrowse/core/util'
import { getFetcher } from '@jbrowse/core/util/io'

export class ApolloTextSearchAdapter
extends BaseAdapter
Expand All @@ -24,19 +22,6 @@ export class ApolloTextSearchAdapter
return readConfObject(this.config, 'assemblyNames')
}

async searchFeatures(term: string) {
const assemblies = this.assemblyNames.join(',')
const url = new URL('features/searchFeatures', this.baseURL)
const searchParams = new URLSearchParams({ assemblies, term })
url.search = searchParams.toString()
const uri = url.toString()

const location: UriLocation = { locationType: 'UriLocation', uri }
const fetch = getFetcher(location, this.pluginManager)
const response = await fetch(uri)
return response.json()
}

mapBaseResult(
features: {
refSeq: any // eslint-disable-line @typescript-eslint/no-explicit-any
Expand All @@ -56,9 +41,20 @@ export class ApolloTextSearchAdapter
}

async searchIndex(args: BaseTextSearchArgs): Promise<BaseResult[]> {
const results = []
for (const assemblyName of this.assemblyNames) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const session = this.pluginManager?.rootModel?.session as any
const backendDriver =
session?.apolloDataStore.getBackendDriver(assemblyName)
const r = await backendDriver.searchFeatures(args.queryString, [
assemblyName,
])
results.push(...r)
}

const query = args.queryString
const features = await this.searchFeatures(query)
return this.mapBaseResult(features, query)
return this.mapBaseResult(results, query)
}

// eslint-disable-next-line @typescript-eslint/no-empty-function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ export abstract class BackendDriver {
change: Change,
opts: SubmitOpts,
): Promise<ValidationResultSet>

abstract searchFeatures(
term: string,
assemblies: string[],
): Promise<AnnotationFeatureSnapshot[]>
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,31 @@ export class CollaborationServerDriver extends BackendDriver {
return customFetch(info, init)
}

async searchFeatures(term: string, assemblies: string[]) {
const internetAccount = this.clientStore.getInternetAccount(
assemblies[0],
) as ApolloInternetAccount
const { baseURL } = internetAccount

const url = new URL('features/searchFeatures', baseURL)
const searchParams = new URLSearchParams({
assemblies: assemblies.join(','),
term,
})
url.search = searchParams.toString()
const uri = url.toString()

const response = await this.fetch(internetAccount, uri)
if (!response.ok) {
const errorMessage = await createFetchErrorMessage(
response,
'searchFeatures failed',
)
throw new Error(errorMessage)
}
return response.json() as Promise<AnnotationFeatureSnapshot[]>
}

/**
* Call backend endpoint to get features by criteria
* @param region - Searchable region containing refSeq, start and end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,11 @@ export class InMemoryFileDriver extends BackendDriver {
) {
return new ValidationResultSet()
}

async searchFeatures(
_term: string,
_assemblies: string[],
): Promise<AnnotationFeatureSnapshot[]> {
return []
}
}