Skip to content

Commit

Permalink
feat: fetch sidecar Auspice JSON if .root_sequence is not on the tree
Browse files Browse the repository at this point in the history
Followup of #1455

If `.root_sequence` is not available on Auspice JSON, let's attempt to fetch ref sequence from sidecar Auspice JSON. For that let's GET from the same URL, but with `Accept: application/vnd.nextstrain.dataset.root-sequence+json` header.
  • Loading branch information
ivan-aksamentov committed May 30, 2024
1 parent 9a172d1 commit 8495372
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/nextclade-web/src/io/fetchSingleDatasetAuspice.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import { isEmpty } from 'lodash'
import { attrStrMaybe, AuspiceTree, Dataset } from 'src/types'
import { removeTrailingSlash } from 'src/io/url'
import { axiosFetch } from 'src/io/axiosFetch'
import { axiosFetch, axiosFetchOrUndefined } from 'src/io/axiosFetch'

export async function fetchSingleDatasetAuspice(datasetJsonUrl_: string) {
const datasetJsonUrl = removeTrailingSlash(datasetJsonUrl_)

const auspiceJson = await axiosFetch<AuspiceTree>(datasetJsonUrl, {
headers: { Accept: 'application/json, text/plain, */*' },
})

if (isEmpty(auspiceJson.root_sequence)) {
const sidecar = await axiosFetchOrUndefined<Record<string, string>>(datasetJsonUrl, {
headers: { Accept: 'application/vnd.nextstrain.dataset.root-sequence+json' },
})
if (!isEmpty(sidecar)) {
auspiceJson.root_sequence = sidecar
}
}

const pathogen = auspiceJson.meta.extensions?.nextclade?.pathogen

const name =
Expand Down

0 comments on commit 8495372

Please sign in to comment.