Viral AI Docs | Python Library

Python Library

DNAstack provides a Python client library called dnastack-client-library. This can be used to interact with DNAstack using Python scripts and Jupyter Notebook.

Prerequisite

  • Python 3.9 or newer
  • Optional: pip 21.3 or newer
    • This is only required for ARM-based CPU.

Installation

The library can be installed using pip.

1
pip3 install dnastack-client-library=3.0.56a1648737133

Setup

Accessing DNAstack services is done by the CollectionServiceClient object.

To initialize, do the following

1
2
3
4
5
6
7
# Import the dnastack-client-library library
from dnastack import CollectionServiceClient
from dnastack.configuration import ServiceEndpoint

# Create the client
api_url = 'https://viral.ai/api/'
client = CollectionServiceClient.make(ServiceEndpoint(adapter_type="collections", url=api_url))

Usage

List Collections
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Import the dnastack-client-library library
from dnastack import CollectionServiceClient
from dnastack.configuration import ServiceEndpoint

# Create the client
api_url = 'https://viral.ai/api/'
client = CollectionServiceClient.make(ServiceEndpoint(adapter_type="collections", url=api_url))

# Get a list of collections
collections = client.list_collections()
List Collection Tables
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Import the dnastack-client-library library
from dnastack import CollectionServiceClient
from dnastack.configuration import ServiceEndpoint

# Create the client
api_url = 'https://viral.ai/api/'
client = CollectionServiceClient.make(ServiceEndpoint(adapter_type="collections", url=api_url))

# Get the Data Connect client for a specific collection
collection_name = 'ncbi-sra'
data_connect_client = client.get_data_connect_client(collection_name)

# Get a list of tables in a collection
tables = data_connect_client.list_tables()
Query a Collection
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# Import the dnastack-client-library library
from dnastack import CollectionServiceClient
from dnastack.configuration import ServiceEndpoint

# Create the client
api_url = 'https://viral.ai/api/'
client = CollectionServiceClient.make(ServiceEndpoint(adapter_type="collections", url=api_url))

# Get the Data Connect client for a specific collection
collection_name = 'ncbi-sra'
data_connect_client = client.get_data_connect_client(collection_name)

# Query the collection
query = 'SELECT * FROM collections.ncbi_sra.variants LIMIT 20'
data = data_connect_client.query(query)