Package: ncbi.datasets.metadata

Utilities to work with NCBI Datasets metadata

This package has utility functions to help you work with data report metadata files from NCBI Datasets data packages.

For example, given a gene object, you can easily print some of its fields:

from typing import List

from ncbi.datasets.openapi import ApiClient as DatasetsApiClient
from ncbi.datasets.openapi import ApiException as DatasetsApiException
from ncbi.datasets import GeneApi as DatasetsGeneApi
from ncbi.datasets.openapi.models import V1GeneMatch


def print_gene_information(gene_record: V1GeneMatch):
    # print query value that returned this specific gene
    print("query", gene_record.query)

    # print any errors that occured while executing the above query, e.g. invalid identifier
    if gene_record.warnings:
        print(gene_record.warnings)
    if gene_record.errors:
        print(gene_record.errors)

    # print gene metadata fields
    if gene_record.gene:
        # use returned gene structure
        print(gene_record.gene.taxname)
        # another option is to convert gene_record to python dictionary and get fields that way:
        gene_dictionary = gene_record.gene.to_dict()
        print(gene_dictionary["symbol"])


# Provide gene ids as a list of integers
gene_ids: List[int] = [2, 3, 9, 10, 11, 12, 13, 14, 15, 16]

with DatasetsApiClient() as api_client:
    gene_api = DatasetsGeneApi(api_client)
    try:
        # Retrieve gene metadata for the list of gene ids
        gene_reply = gene_api.gene_metadata_by_id(gene_ids)
        for gene in gene_reply.genes:
            print_gene_information(gene)
    except DatasetsApiException as e:
        print(f"Exception when calling GeneApi: {e}\n")

Module: ncbi.datasets.metadata.gene

Utility functions for working and reporting on gene data reports.

Module: ncbi.datasets.metadata.genome

Utility functions for working and reporting on assembly data descriptors.

Generated March 21, 2023