A comprehensive Python client for the Undiagnosed Diseases Network (UDN) Gateway API. This project provides easy-to-use tools for accessing and downloading data from the UDN Gateway.
The project is organized as a proper Python package:
udn_aws_to_dnanexus_copy/
├── udn_gateway/ # Main package
│ ├── __init__.py # Package initialization
│ ├── client.py # API client implementation
│ ├── cli.py # Command-line interface
│ └── utils.py # Utility functions
├── tests/ # Test suite
│ ├── __init__.py # Test package initialization
│ ├── test_sequencing.py # Sequencing data structure tests
│ ├── test_cli.py # CLI functionality tests
│ └── run_tests.py # Test runner
├── udn_gateway_cli.py # Main CLI entry point
├── setup.py # Package installation
├── requirements.txt # Dependencies
└── README.md # This file
- Complete API Coverage: All UDN Gateway API endpoints are supported
- Enhanced Error Handling: Comprehensive error handling with detailed error messages
- File Download Management: Automated file downloading with progress tracking
- Backward Compatibility: Enhanced scripts maintain compatibility with existing workflows
- Command Line Interface: Easy-to-use CLI for common operations
- Logging: Detailed logging for debugging and monitoring
# Install the package in development mode
pip install -e .
# Or install directly from the repository
pip install .The project includes a comprehensive test suite to ensure functionality works correctly:
# Run all tests
python tests/run_tests.py
# Run specific test categories
python tests/run_tests.py sequencing
python tests/run_tests.py cli
# Run individual test files
python tests/test_sequencing.py
python tests/test_cli.py- sequencing: Tests API data structure parsing and file detection
- cli: Tests command-line interface functionality and flags
- Python 3.6 or higher
requestslibrarycurlcommand-line tool (for file downloads)
- Clone this repository:
git clone <repository-url>
cd udn_aws_to_dnanexus_copy- Install required Python packages:
pip install requests- Get your API token from the UDN Gateway and save it to a file (e.g.,
token.txt)
# Download all files for a participant (new simplified way)
python udn_gateway_cli.py -a token.txt -u UDN970218 --all
# Download all files for a participant (legacy way)
python udn_gateway_cli.py -a token.txt -u UDN970218 --download
# Download only .gvcf.gz files
python udn_gateway_cli.py -a token.txt -u UDN970218 --download --gvcf
# Download only .vcf.gz files
python udn_gateway_cli.py -a token.txt -u UDN970218 --download --vcf
# Download files to a specific directory
python udn_gateway_cli.py -a token.txt -u UDN970218 --all -o /path/to/output
# List all available participants
python udn_gateway_cli.py -a token.txt --list-participants
# Get participant information only
python udn_gateway_cli.py -a token.txt -u UDN970218 --info-only# Download files for a participant (new package structure)
python udn_gateway_cli.py -a token.txt -u UDN970218 --downloadfrom udn_gateway import UDNGatewayClient
# Initialize client
client = UDNGatewayClient("your_api_token_here")
# Get all participants
participants = client.get_participants()
# Get participant details
details = client.get_participant_details("UDN970218")
# Download all files for a participant
downloaded_files = client.download_all_participant_files("UDN970218", "/output/directory")The CLI provides a comprehensive interface with the following options:
python udn_gateway_cli.py [OPTIONS]-a, --api_token_file: API token file (required)-u, --udn_id: UDN participant ID to download data-o, --output_dir: Output directory for downloaded files (default: current directory)--file-types: File types to download (comma-separated: sequencing_file,medical_record,etc.)--list-participants: List all available participants--info-only: Only get participant information, don't download files--all: Download all available files for the participant (new simplified way)--download: Download files for the participant (legacy way, must be explicitly set)--gvcf: Only download files ending with .gvcf.gz (must be used with --download)--vcf: Only download files ending with .vcf.gz (must be used with --download)--verbose: Enable verbose logging
# Download all files for a participant (new simplified way)
python udn_gateway_cli.py -a token.txt -u UDN970218 --all
# Download all files for a participant (legacy way)
python udn_gateway_cli.py -a token.txt -u UDN970218 --download
# Download only .gvcf.gz files
python udn_gateway_cli.py -a token.txt -u UDN970218 --download --gvcf
# Download only .vcf.gz files
python udn_gateway_cli.py -a token.txt -u UDN970218 --download --vcf
# Download only sequencing files
python udn_gateway_cli.py -a token.txt -u UDN970218 --all --file-types sequencing_file
# Download files to a specific directory
python udn_gateway_cli.py -a token.txt -u UDN970218 --all -o /path/to/output
# List all available participants
python udn_gateway_cli.py -a token.txt --list-participants
# Get participant information only
python udn_gateway_cli.py -a token.txt -u UDN970218 --info-only
# Enable verbose logging
python udn_gateway_cli.py -a token.txt -u UDN970218 --all --verboseThe UDNGatewayClient class provides methods for all available API endpoints:
# Get all applications
applications = client.get_applications()
# Get applications with specific status
accepted_apps = client.get_applications(filter_status="accepted")
# Get application details
app_details = client.get_application_details(application_id=123)
# Get application attachment details
attachment = client.get_application_attachment_details(123, "letter", 456)# Get all participants
participants = client.get_participants()
# Get participant details
details = client.get_participant_details("UDN970218")
# Get participant family
family = client.get_participant_family("UDN970218")
# Get sequencing requests
sequencing = client.get_participant_sequencing_requests("UDN970218")
# Get PhenoTips data
phenotips = client.get_participant_phenotips("UDN970218")# Get all available files for a participant
files = client.get_participant_files_for_download("UDN970218")
# Download a single file
file_path = client.download_file(download_link, filename, output_dir)
# Download all files for a participant
downloaded_files = client.download_all_participant_files("UDN970218", "/output/directory")# Get clinical sites
sites = client.get_clinical_sites()
# Get ethnicities
ethnicities = client.get_ethnicities()
# Get languages
languages = client.get_languages()
# Get races
races = client.get_races()
# Get relations
relations = client.get_relations()
# Get sexes
sexes = client.get_sexes()
# Get symptom categories
categories = client.get_symptom_categories()# Get sequencing cores
cores = client.get_sequencing_cores()
# Get sequencing requests
requests = client.get_sequencing_requests()
# Get specific sequencing request
request = client.get_sequencing_request_by_id(123)The client supports all available UDN Gateway API endpoints:
GET /applications- Get applications listGET /applications/{id}- Get application detailsGET /applications/{id}/attachments/{type}/{attachmentId}- Get attachment detailsGET /applications/{id}/review/attachments/{type}/{attachmentId}- Get review attachment details
GET /participants- Get participants listGET /participants/{participantId}- Get participant detailsGET /participants/{participantId}/family- Get participant familyGET /participants/{participantId}/sequencing- Get sequencing requestsGET /participants/{participantId}/sequencing/files/{id}- Get sequencing file detailsGET /participants/{participantId}/sequencing/reports/{id}- Get sequencing report detailsGET /participants/{participantId}/medicalrecords/{id}- Get medical record detailsGET /participants/{participantId}/consentdocuments/{id}- Get consent document detailsGET /participants/{participantId}/wrapupdocuments/{id}- Get wrap-up document detailsGET /participants/{participantId}/phenotips- Get PhenoTips dataGET /participants/{participantId}/phenotips/suggestedgenepanels- Get suggested gene panelsGET /participants/{participantId}/modelorganism- Get model organism requests
GET /clinicalsites- Get clinical sitesGET /ethnicities- Get ethnicitiesGET /genderidentities- Get gender identitiesGET /languages- Get languagesGET /races- Get racesGET /relations- Get relationsGET /sexes- Get sexesGET /symptomcategories- Get symptom categories
GET /sequencing/cores- Get sequencing coresGET /sequencing/requests- Get sequencing requestsGET /sequencing/requests/{id}- Get sequencing request details
GET /families/{familyId}- Get family details
The client provides comprehensive error handling:
from src.udn_api_client import UDNGatewayClient, UDNGatewayAPIError
try:
client = UDNGatewayClient("your_token")
participants = client.get_participants()
except UDNGatewayAPIError as e:
print(f"API Error: {e}")
except Exception as e:
print(f"Unexpected error: {e}")Common error codes:
400 Bad Request: Invalid request parameters401 Unauthorized: Invalid or missing API token403 Forbidden: Insufficient permissions404 Not Found: Resource not found
The client uses Python's logging module for detailed output:
import logging
# Set logging level
logging.basicConfig(level=logging.INFO)
# Use the client
client = UDNGatewayClient("your_token")The enhanced script is compatible with the existing Nextflow workflow:
process bwa_mem {
container "gvcn/request_udn_files:v0.0.4"
cpus 12
tag "Download UDN gateway data for $udn_id"
input:
val udn_id
val proband_id
val relative_status
path api_token_file
output:
tuple val(meta), path("*.bwa.bam"), emit: bwa_bam
script:
"""
python /home/bin/request_udn_files_enhanced.py -a ${api_token_file} -u ${udn_id}
"""
}Store your API token in a text file:
your_api_token_here
You can also set the API token as an environment variable:
export UDN_API_TOKEN="your_api_token_here"-
Authentication Errors
- Verify your API token is correct
- Check that the token file exists and is readable
- Ensure the token hasn't expired
-
Permission Errors
- Contact UDN Gateway support for access to specific endpoints
- Verify your account has the necessary permissions
-
Download Failures
- Check that
curlis installed and accessible - Verify you have write permissions to the output directory
- Check network connectivity
- Check that
-
File Not Found Errors
- Verify the participant ID is correct
- Check that the participant has available files
- Ensure the file IDs are valid
Enable verbose logging for detailed output:
python src/request_udn_files_enhanced.py -a token.txt -u UDN970218 --verbose- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For issues related to:
- API access and permissions: Contact UDN Gateway support
- Client functionality: Open an issue in this repository
- Documentation: Submit a pull request with improvements
- Added
--allparameter for simplified downloading of all available files - Enhanced CLI usability with more intuitive download options
- Maintained backward compatibility with existing
--downloadparameter
- Added comprehensive UDN Gateway API client
- Enhanced error handling and logging
- Added support for all API endpoints
- Improved file download functionality
- Added command-line interface
- Maintained backward compatibility
- Initial release with basic file download functionality