import {z} from 'zod' export type V2VirusTableField = 'unspecified' | 'nucleotide_accession' | 'species_tax_id' | 'species_name' | 'genus' | 'family' | 'nucleotide_length' | 'isolate_name' | 'sequence_type' | 'nuc_completeness' | 'geo_location' | 'us_state' | 'host_name' | 'host_tax_id' | 'collection_date' | 'bioproject' | 'biosample' | 'polyprotein_name' | 'protein_name' | 'protein_accession' | 'protein_synonym' | 'cds_span'; export type V2ViralSequenceType = 'GENOME' | 'CDS' | 'PROTEIN' | 'NONE'; export type V2VirusDatasetReportType = 'DATASET_REPORT' | 'ANNOTATION' | 'BIOSAMPLE_REPORT'; export type V2TableFormat = 'tsv' | 'csv' | 'jsonl'; export type V2Sars2ProteinDatasetRequest = {proteins?: Array | undefined, refseq_only?: boolean | undefined, annotated_only?: boolean | undefined, released_since?: string | undefined, updated_since?: string | undefined, host?: string | undefined, pangolin_classification?: string | undefined, geo_location?: string | undefined, usa_state?: string | undefined, complete_only?: boolean | undefined, table_fields?: Array | undefined, include_sequence?: Array | undefined, aux_report?: Array | undefined, format?: V2TableFormat | undefined}; export type CreateApiVirusTaxonSars2ProteinArgs = {body: V2Sars2ProteinDatasetRequest}; export type CreateApiVirusTaxonSars2ProteinOptions = {baseUrl?: string | undefined, ApiKeyAuthHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const v2DownloadSummaryHydrated = z.object({estimated_file_size_mb: z.number().int().optional(), url: z.string().optional(), cli_download_command_line: z.string().optional()}); export const v2DownloadSummaryDehydrated = z.object({estimated_file_size_mb: z.number().int().optional(), url: z.string().optional(), cli_download_command_line: z.string().optional(), cli_rehydrate_command_line: z.string().optional()}); export const v2reportsErrorAssemblyErrorCode = z.enum(["UNKNOWN_ASSEMBLY_ERROR_CODE", "INVALID_BIOPROJECT_IDS", "NO_ASSEMBLIES_FOR_BIOPROJECTS", "INVALID_TAXON", "MISSING_SEARCH_FIELD", "INVALID_BIOSAMPLE_IDS", "NO_ASSEMBLIES_FOR_BIOSAMPLE_IDS", "NO_ASSEMBLIES_FOR_ASSEMBLY_NAMES", "INVALID_WGS_ACCESSIONS", "NO_ASSEMBLIES_FOR_WGS_ACCESSIONS"]); export const v2reportsErrorGeneErrorCode = z.enum(["UNKNOWN_GENE_ERROR_CODE", "INCOMPLETE_LOOKUP_SYMBOL", "INVALID_TAXON_GENE_ARGUMENT"]); export const v2reportsErrorOrganelleErrorCode = z.enum(["UNKNOWN_ORGANELLE_ERROR_CODE", "INVALID_ORGANELLE_TAXON", "NO_ORGANELLES_FOR_ACCESSION"]); export const v2reportsErrorVirusErrorCode = z.literal("UNKNOWN_VIRUS_ERROR_CODE"); export const v2reportsErrorTaxonomyErrorCode = z.enum(["UNKNOWN_TAXONOMY_ERROR_CODE", "INVALID_TAXONOMY_TAXON"]); export const v2reportsErrorSequenceErrorCode = z.enum(["UNKNOWN_SEQUENCE_ERROR_CODE", "INVALID_SEQUENCE_ACCESSION"]); export const v2reportsError = z.object({assembly_error_code: v2reportsErrorAssemblyErrorCode.optional(), gene_error_code: v2reportsErrorGeneErrorCode.optional(), organelle_error_code: v2reportsErrorOrganelleErrorCode.optional(), virus_error_code: v2reportsErrorVirusErrorCode.optional(), taxonomy_error_code: v2reportsErrorTaxonomyErrorCode.optional(), sequence_error_code: v2reportsErrorSequenceErrorCode.optional(), reason: z.string().optional(), message: z.string().optional(), invalid_identifiers: z.array(z.string()).optional()}); export const v2reportsWarningGeneWarningCode = z.enum(["UNKNOWN_GENE_WARNING_CODE", "ACCESSION_VERSION_MISMATCH", "REPLACED_GENE_ID", "DISCONTINUED_GENE_ID", "UNRECOGNIZED_GENE_ID", "UNRECOGNIZED_GENE_SYMBOL", "UNRECOGNIZED_ACCESSION", "UNRECOGNIZED_TAX_TOKEN", "NO_GENE_ANNOTATION_FOUND", "ABOVE_SPECIES_TAXON"]); export const v2reportsWarningReplacedId = z.object({requested: z.string().optional(), returned: z.string().optional()}); export const v2reportsWarning = z.object({gene_warning_code: v2reportsWarningGeneWarningCode.optional(), reason: z.string().optional(), message: z.string().optional(), replaced_id: v2reportsWarningReplacedId.optional(), unrecognized_identifier: z.string().optional()}); export const v2reportsMessage = z.object({error: v2reportsError.optional(), warning: v2reportsWarning.optional()}); export const v2DownloadSummaryFileSummary = z.object({file_count: z.number().int().optional(), size_mb: z.number().optional()}); export const v2DownloadSummaryAvailableFiles = z.object({all_genomic_fasta: v2DownloadSummaryFileSummary.optional(), genome_gff: v2DownloadSummaryFileSummary.optional(), genome_gbff: v2DownloadSummaryFileSummary.optional(), rna_fasta: v2DownloadSummaryFileSummary.optional(), prot_fasta: v2DownloadSummaryFileSummary.optional(), genome_gtf: v2DownloadSummaryFileSummary.optional(), cds_fasta: v2DownloadSummaryFileSummary.optional(), sequence_report: v2DownloadSummaryFileSummary.optional(), annotation_report: v2DownloadSummaryFileSummary.optional()}); export const v2DownloadSummary = z.object({record_count: z.number().int().optional(), assembly_count: z.number().int().optional(), resource_updated_on: z.string().optional(), hydrated: v2DownloadSummaryHydrated.optional(), dehydrated: v2DownloadSummaryDehydrated.optional(), errors: z.array(v2reportsError).optional(), messages: z.array(v2reportsMessage).optional(), available_files: v2DownloadSummaryAvailableFiles.optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get a download summary of a SARS-CoV-2 protein data package by protein name * * POST /virus/taxon/sars2/protein */ export const createApiVirusTaxonSars2Protein = async (args: CreateApiVirusTaxonSars2ProteinArgs, options?: CreateApiVirusTaxonSars2ProteinOptions) => { const {baseUrl = "https://api.ncbi.nlm.nih.gov/datasets/v2", fetch: fetchFn = fetch, ApiKeyAuthHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuthHeader !== undefined) headers.set("api-key", ApiKeyAuthHeader) const url = `${baseUrl.replace(/\/+$/, '')}/virus/taxon/sars2/protein${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(v2DownloadSummary, await res.json()) };