Skip to main content

Python client for refget

Project description

Refget

Run pytests

User-facing documentation is hosted at refgenie.org/refget.

In this repository you will find:

  1. /refget: The refget Python package, which provides a Python interface to both remote and local use of the refget protocol. It has clients and functions for both refget sequences and refget sequence collections (seqcol).
  2. /seqcolapi: Sequence collections API software, a FastAPI wrapper built on top of the refget package. It provides a bare-bones Sequence Collections API service.
  3. actions (in .github/workflows): GitHub Actions for demo server instance
  4. /deployment: Server configurations for demo instances and public deployed instances.
  5. /test_fasta and /test_api: Dummy data and a compliance test, to test external implementations of the Refget Sequence Collections API.
  6. /frontend: a React seqcolapi front-end.

Testing

Local unit tests of refget package

  • pytest to test refget package, local unit tests

Compliance testing of Sequence Collections API

Under /test_api are compliance tests for a service implementing the sequence collections API. This will test your collection and comparison endpoints to make sure the comparison function is working.

  • pytest test_api to tests API compliance
  • pytest test_api --api_root http://127.0.0.1:8100 to customize the API root URL to test
  1. Load the fasta files from the test_fasta folder into your API database.
  2. Run pytest test_api --api_root <API_URL>, pointing to your URL to test

For example, this will test a remote server instance:

pytest test_api --api_root https://seqcolapi.databio.org

Development and deployment

Setting up a database connection

First populate environment variables to configure a database connection. Choose one of these:

source deployment/local_demo/local_demo.env # local demo (see below to create the database using docker)
source deployment/seqcolapi.databio.org/production.env # connect to production database

If you're using the local_demo, then use docker to create a local postgres database like this:

docker run --rm --name refget-postgres -p 127.0.0.1:5432:5432 \
  -e POSTGRES_PASSWORD \
  -e POSTGRES_USER \
  -e POSTGRES_DB \
  -e POSTGRES_HOST \
  postgres:17.0

If you need to load test data into your server, then you have to install gtars, a Python package for computing GA4GH digests. You can load test data like this:

python load_demo_data.py
# refget add-fasta path/to/fasta.fa  # This could be a way in the future...
# python load_pangenome_reference.py ../seqcolapi/analysis/data/demo.csv test_fasta  # loads an entire pangenome

Running the seqcolapi API backend

Run the demo seqcolapi service like this:

uvicorn seqcolapi.main:app --reload --port 8100

Running with docker

To build the docker file, from the root of this repository:

First you build the general-purpose image

docker build -f deployment/dockerhub/Dockerfile -t databio/seqcolapi seqcolapi

Next you build the wrapped image (this just wraps the config into the app):

docker build -f deployment/seqcolapi.databio.org/Dockerfile -t seqcolapi.databio.org deployment/seqcolapi.databio.org

To run in a container:

source deployment/seqcolapi.databio.org/production.env
docker run --rm -p 8000:80 --name seqcolapi \
  --env "POSTGRES_USER" \
  --env "POSTGRES_DB" \
  --env "POSTGRES_PASSWORD" \
  --env "POSTGRES_HOST" \
  seqcolapi.databio.org

Alternative: Mount the config

Instead of building a bundle with the config, you could just mount it into the base image:

docker run --rm -p 8000:8000 --name sccon \
  --env "POSTGRES_PASSWORD" \
  --volume $CODE/seqcolapi.databio.org/config/seqcolapi.yaml:/config.yaml \
  seqcolapi 

Deploying container to dockerhub

Use github action in this repo which deploys on release, or through manual dispatch.

Running the frontend

Local client with local server

cd frontend
npm i
VITE_API_BASE="http://localhost:8100" npm run dev

Local client with production server

cd frontend
npm i
VITE_API_BASE="https://seqcolapi.databio.org" npm run dev

Deploy to AWS ECS

  • Test locally first, using 1. native test; 2. local docker test.

Deploying

To upgrade the software:

Use config file located in /servers/seqcolapi.databio.org. This will use the image in docker.io://databio/seqcolapi, github repo: refgenie/seqcolapi as base, bundle it with the above config, and deploy to the shefflab ECS.

  1. Ensure the refget package master branch is as you want it.
  2. Deploy the updated secqolapi app to dockerhub (using manual dispatch, or deploy on github release).
  3. Finally, deploy the instance with manual dispatch using the included GitHub action.

Developer notes

Models

The objects and attributes are represented as SQLModel objects in refget/models.py. To add a new attribute:

  1. create a new model. This will create a table for that model, etc.
  2. change the function that creates the objects, to populate the new attribute.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

refget-0.7.0.tar.gz (27.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

refget-0.7.0-py3-none-any.whl (26.0 kB view details)

Uploaded Python 3

File details

Details for the file refget-0.7.0.tar.gz.

File metadata

  • Download URL: refget-0.7.0.tar.gz
  • Upload date:
  • Size: 27.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for refget-0.7.0.tar.gz
Algorithm Hash digest
SHA256 26e6b466ecdd82fc140ed12c5ede7a7f2824f3322212f42173632f982ca6f271
MD5 4373d7451d3d90a9c072facf959d69f6
BLAKE2b-256 a7b4ae8c4e20d9d0162b110bbdca44841bc338960d1c42b2cfdd8dce34846553

See more details on using hashes here.

Provenance

The following attestation bundles were made for refget-0.7.0.tar.gz:

Publisher: python-publish.yml on refgenie/refget

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file refget-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: refget-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 26.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for refget-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3affd6e3647a0eb83b0cb865874c2e6da45f3f6e6b51c721e6fe49d8bad8d1ca
MD5 8a716f2770e76d41c193d863d4513afc
BLAKE2b-256 979eb5eec030beb8c8e0b2bba72b45529c9d389c86eba6fa38a8c827c305a52b

See more details on using hashes here.

Provenance

The following attestation bundles were made for refget-0.7.0-py3-none-any.whl:

Publisher: python-publish.yml on refgenie/refget

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page