Skip to content

Library for interacting with ahab cloud API and Kubernetes systems. 🦑

License

Notifications You must be signed in to change notification settings

tuplexyz/ahab-lib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ahab - Library 🦑

Library for interacting with the ahab cloud API and Kubernetes system

Installation

## Python library from PyPI using pip
pip install ahab-lib

## CLI using pipx
pipx install git+https://github.com/tuplexyz/ahab-lib.git

Environment Variables

This library can use environment variables to avoid passing sensitive information in code. The following environment variables are used by this library:

  • AHAB_API_URL - The URL for the ahab cloud API
  • AHAB_API_KEY - Your API key for the ahab cloud API

You can retrieve these values using the following Azure CLI commands:

## On Unix
export AHAB_API_URL=https://$(az functionapp show --name func-ahab-dev-eastus-001 --resource-group rg-ahab-dev-eastus-001 --query defaultHostName -o tsv)
export AHAB_API_KEY=$(az functionapp keys list --name func-ahab-dev-eastus-001 --resource-group rg-ahab-dev-eastus-001 --query functionKeys -o tsv)

## On Windows
set AHAB_API_URL=https://$(az functionapp show --name func-ahab-dev-eastus-001 --resource-group rg-ahab-dev-eastus-001 --query defaultHostName -o tsv)
set AHAB_API_KEY=$(az functionapp keys list --name func-ahab-dev-eastus-001 --resource-group rg-ahab-dev-eastus-001 --query functionKeys -o tsv)

...changing the --name and --resource-group values to the names of your Function App and Resource Group, respectively.

CLI Usage

Submit Job

python3 ahab.py job submit --body='{"job_type": "rnaseq", "metadata": {"project": "project_001", "sample": "sample_001"}, "inputs": {"references": "/mnt/datalake/reference/rnaseq_1", "fastq_1": "/mnt/datalake/project_001/sample_001/rnaseq/file_1.fastq.gz", "fastq_2": "/mnt/datalake/project_001/sample_001/rnaseq/file_2.fastq.gz"}}'

Get Job

python3 ahab.py job get --job_type=rnaseq

Update Job

python3 ahab.py job update --id=fb273f3b-9665-4f9d-978c-9f6cb9f1cc19 --status=COMPLETE --body='{"outputs": {"bam": "/mnt/datalake/project_001/sample_001/rnaseq/file_1.bam", "bai": "/mnt/datalake/project_001/sample_001/rnaseq/file_1.bam.bai"}}'

Python Usage

Load in the library and get API information

from ahab.job import get_job, submit_job, update_job
import os, json

api_base_url = os.environ.get('AHAB_API_URL', '')
api_key = os.environ.get('AHAB_API_KEY', '')

Submit Job

body = {
    "job_type": "rnaseq",
    "metadata": {
        "project": "project_001",
        "sample": "sample_001"
    },
    "inputs": {
        "references": "/mnt/datalake/reference/rnaseq_1",
        "fastq_1": "/mnt/datalake/project_001/sample_001/rnaseq/file_1.fastq.gz",
        "fastq_2": "/mnt/datalake/project_001/sample_001/rnaseq/file_2.fastq.gz"
    }
}

response = submit_job(body = body, api_base_url = api_base_url, api_key = api_key)

# {'message': 'Job created successfully.', 'id': 'fb273f3b-9665-4f9d-978c-9f6cb9f1cc19', 'job_type': 'rnaseq'}

Get Job

job = get_job(job_type='rnaseq', api_base_url = api_base_url, api_key = api_key)

# {'id': 'fb273f3b-9665-4f9d-978c-9f6cb9f1cc19', 'job_type': 'rnaseq', 'current_status': 'STARTED', 'status_history': {'2024-04-29T17:10:18.552843': 'PENDING', '2024-04-29T17:11:15.582001': 'STARTED'}, 'metadata': {'project': 'project_001', 'sample': 'sample_001'}, 'inputs': {'references': '/mnt/datalake/reference/rnaseq_1', 'fastq_1': '/mnt/datalake/project_001/sample_001/rnaseq/file_1.fastq.gz', 'fastq_2': '/mnt/datalake/project_001/sample_001/rnaseq/file_2.fastq.gz'}}

Update Job

body = {
    "outputs": {
        "bam": "/mnt/datalake/project_001/sample_001/rnaseq/file_1.bam",
        "bai": "/mnt/datalake/project_001/sample_001/rnaseq/file_1.bam.bai"
    }
}

response = update_job(id = 'fb273f3b-9665-4f9d-978c-9f6cb9f1cc19', status = "COMPLETE", body = body, api_base_url = api_base_url, api_key = api_key)

# {'message': 'Job updated successfully.', 'id': 'fb273f3b-9665-4f9d-978c-9f6cb9f1cc19', 'status': 'COMPLETE'}