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

feat: LitVar for SeqVars (#421) #136

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
70 changes: 70 additions & 0 deletions src/api/litvar/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { urlConfig } from '../../lib/urlConfig'
import type { SearchResult } from './types'

/**
* Client for the LitVar API.
*/
export class LitVarClient {
/** API base URL to use in this client instance. */
private apiBaseUrl: string

/**
* @param apiBaseUrl
* API base to the backend, excluding trailing `/`.
* The default is declared in '@/lib/urlConfig`.
*/
constructor(apiBaseUrl?: string) {
if (apiBaseUrl !== undefined || urlConfig.baseUrlLitVar !== undefined) {
// @ts-ignore
this.apiBaseUrl = apiBaseUrl ?? urlConfig.baseUrlLitVar
} else {
throw new Error('Configuration error: API base URL not configured')
}
}

/**
* Perform search for the given HGNC symbol.
*
* @param hgncSymbol HGNC symbol to search for.
* @returns Promise for the search results.
* @throws Error if the search fails.
*/
async performSearch(seqVar: string): Promise<{ [key: string]: SearchResult }> {
const url = `${this.apiBaseUrl}/${seqVar}`
const searchRes = await fetch(url, {
method: 'GET'
})
if (!searchRes.ok) {
throw new Error(`Error running LitVar search: ${searchRes.statusText}`)
}
const searchData = await searchRes.json()

// Then, extract PMID list and retrieve biocjson for the PMIDs
// const pmids: string[] = searchData!.results!.map((doc: any) => doc.pmid)
// const exportRes = await fetch(
// `${this.apiBaseUrl}/publications/export/biocjson` + `?pmids=${pmids.join(',')}`
// )
// if (!exportRes.ok) {
// throw new Error(`Error running LitVar export: ${exportRes.statusText}`)
// }
// const exportDataText = await exportRes.text()
// const exportDataLines = exportDataText.split(/\n/)

// // Zip search results and exports into searchResults
// const searchaResults: { [key: string]: SearchResult } = {}
// for (const searchDataRecord of searchData.results) {
// searchResults[searchDataRecord.pmid] = {
// searchResult: searchDataRecord,
// abstract: undefined
// }
// }
// for (const exportDataLine of exportDataLines) {
// if (exportDataLine) {
// const exportData = JSON.parse(exportDataLine)
// searchResults[exportData.pmid].abstract = exportData
// }
// }

return searchData
}
}
2 changes: 2 additions & 0 deletions src/api/litvar/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './client'
export * from './types'
2 changes: 2 additions & 0 deletions src/api/litvar/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/** Interface for search result entry plus PubMed abstract. */
export interface SearchResult {}
Loading
Loading