Skip to content
Open
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
15 changes: 4 additions & 11 deletions src/routers/datatypeRouters/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,16 @@ const autocompleteFormat = z.object({
uri: z.string()
})

// currently supports: gene, protein, and disease
// currently supports genes only
async function autocompleteQuery (input: paramsFormatType): Promise<any[]> {
const term = (input.term as string).toUpperCase()

const query = `
LET genes = (FOR gene in genes
FOR gene in genes
FILTER STARTS_WITH(gene.name, "${term}")
RETURN { type: "gene", term: gene.name, uri: CONCAT("/genes/", gene._key) })

LET proteins = (FOR protein in proteins
FILTER STARTS_WITH(protein.name, "${term}") OR (protein.uniprot_names[0] != null AND STARTS_WITH(protein.uniprot_names[0], "${term}"))
RETURN { type: "protein", term: protein.name, uri: CONCAT("/proteins/", protein._key) })

FOR result IN UNION_DISTINCT(genes, proteins)
SORT LENGTH(result.term) ASC
SORT LENGTH(gene.name) ASC
LIMIT ${input.page as number * PAGE_SIZE}, ${PAGE_SIZE}
RETURN result
RETURN { type: "gene", term: gene.name, uri: CONCAT("/genes/", gene._key) }
`
const results = await ((await db.query(query)).all())
return results
Expand Down
4 changes: 2 additions & 2 deletions src/routers/datatypeRouters/descriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ export const descriptions = {
The limit parameter controls the page size and can not exceed 100. <br> \
Pagination is 0-based.',

autocomplete: 'Autocomplete names for genes and proteins based on prefix search.<br> \
Example: term = TP53, <br> \
autocomplete: 'Autocomplete names for genes based on prefix search.<br> \
Example: term = ATF2, <br> \
Pagination is 0-based.',

complex: 'Retrieve complexes.<br> \
Expand Down