Download the PHP package saurabhgayali/uniprot-php without Composer
On this page you can find all versions of the php package saurabhgayali/uniprot-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download saurabhgayali/uniprot-php
More information about saurabhgayali/uniprot-php
Files in saurabhgayali/uniprot-php
Package uniprot-php
Short Description Production-ready PHP library for UniProt REST API with zero dependencies. Includes entry retrieval, advanced search with pagination, and ID mapping.
License MIT
Homepage https://github.com/saurabhgayali/UniprotPHPClass
Informations about the package uniprot-php
UniProt PHP Library
A production-ready PHP library for programmatic access to the UniProt REST API.
Status: Complete, tested, ready for production use.
License: LICENSE.md for full terms.
Features
- ✅ Single Entry Retrieval - Fetch individual protein entries by accession
- ✅ Advanced Search - Complex queries with full pagination support
- ✅ ID Mapping - Map identifiers between databases with async job model
- ✅ Dual Transport - Automatic fallback from cURL to PHP streams
- ✅ No Dependencies - Pure PHP, no external packages required
- ✅ PHP 7.4+ - Works on shared hosting
- ✅ Strict Types - Full type hints throughout
- ✅ Comprehensive Errors - Detailed exception information
- ✅ Fully Documented - Complete API documentation and examples
Quick Start
Installation
No installation required! Just clone or download into your project:
Usage
Single Entry Retrieval
Search with Pagination
Automatic Pagination (Get All Results)
The library automatically handles cursor-based pagination. You can retrieve all results no matter how large:
How it works:
- First request fetches results 1-500
- Library extracts cursor from response's
Linkheader - Next request fetches results 501-1000
- Process repeats automatically until all results retrieved
- No manual pagination needed—just iterate!
Manual Pagination (User-Friendly Display)
For web interfaces, use manual pagination with custom offset control. Select 10, 20, or 50 results per page:
getPaginatedResults() Features:
- Configurable page sizes: 10, 20, or 50 results per page
- Automatic page link generation - Function generates all pagination links, no manual work needed
- Automatic offset calculation and page numbering
- Returns total pages and results metadata
- Previous/Next page offset navigation
- Jump-to-page links for all pages (via
pageLinksarray) - Perfect for web UI pagination
- ⚡ Optimized Pagination: Only fetches the required 500-result batch, not all results. Makes 1 API call for total count + 1 call for the specific batch. Shows correct totals (e.g., "50 of 22,400") without fetching all 22,400 results.
Developers only need to:
- Call the function with query and offset
- Display the results using the returned data
- Create UI for pagination buttons using
pageLinksarray
The function handles all the heavy lifting: counting results, calculating pages, generating links, and determining navigation.
Note: See PAGINATION_OPTIMIZATION.md for detailed performance metrics showing 95% reduction in API calls and 99.8% reduction in memory usage.
ID Mapping
Examples
Three standalone CLI examples are provided to demonstrate library usage:
Running Examples from Command Line
All examples include error handling and work with both cURL and stream transports:
What Each Example Shows:
| Example | File | Demonstrates |
|---|---|---|
| Entry Retrieval | get_entry.php | Single and batch retrieval, field selection, format options |
| Search Pagination | search_entries.php | Complex queries, automatic pagination, batch processing |
| ID Mapping | map_ids.php | Job submission, polling, result retrieval |
Example Code Structure:
- Single autoloader include:
require_once 'src/autoload.php' - Full error handling with
UniProtException - Strict type declarations for safety
- Clear output with progress indicators
Documentation
- Overview - Full documentation
- Single Entry Retrieval - Fetch entries
- Search with Pagination - Advanced search
- ID Mapping - Map identifiers
- Pagination - Cursor-based pagination
- Error Handling - Exception handling
- Shared Hosting - Hosting compatibility
Testing
Quick Server for Testing
Serve the test pages locally using PHP's built-in web server:
Then open http://localhost:8880 in your browser.
Console Output:
Access these interactive test interfaces (from web/ folder):
- Dashboard: http://localhost:8880/index.php
- Entry Retrieval: http://localhost:8880/entry_test.php
- Search: http://localhost:8880/search_test.php
- Async Search: http://localhost:8880/search_async.html
- ID Mapping: http://localhost:8880/mapping_test.php
Each page includes:
- ✅ Pre-filled example values
- ✅ Collapsible PHP code examples
- ✅ Live API requests
- ✅ Formatted response output
Note: Web folder files (web/index.php, web/*_test.php, web/search_async.html, web/search_api.php) are for local development only and are excluded from the GitHub repository (see .gitignore). They are not required for production use.
Test Files
Run the following from tests/ folder:
Tests verify:
- Entry retrieval
- Search pagination
- ID mapping workflow
- Error handling
Architecture
Key Design Decisions
- Interface-based HTTP clients - Supports multiple transports
- Automatic transport selection - Chooses best available (cURL → Streams)
- Iterator-based pagination - Natural foreach support for search results
- Async-aware ID mapping - Built-in polling mechanism
- Structured exceptions - Detailed error information including HTTP status
- No external dependencies - Works anywhere PHP 7.4+ runs
- Strict type hints - Full type safety throughout
System Requirements
- PHP 7.4 or higher
- Either cURL extension OR stream context support (default)
- Outbound HTTPS access to UniProt API
- JSON extension (standard)
Performance
- Transport: Optimized cURL when available, streams as fallback
- Pagination: Cursor-based for efficient large result sets
- Caching: Cache locally when appropriate
- Batching: Support for efficient batch operations
Error Handling
All errors throw UniProtException with:
- Human-readable message
- HTTP status code
- API error code and message
- Full response body for debugging
- Error type helpers (isClientError, isServerError, isTransportError)
Shared Hosting Compatibility
This library is optimized for shared hosting:
- ✅ No external dependencies
- ✅ Works without cURL (falls back to streams)
- ✅ Reasonable memory footprint
- ✅ Handles restricted outbound access
- ✅ Configurable timeouts
- ✅ No permanent file writes required
See Shared Hosting Guide for details.
API Compliance
This library strictly follows the official UniProt REST API:
- Single entry:
/uniprotkb/{accession} - Search:
/uniprotkb/search - ID Mapping:
/idmapping/run,/idmapping/status/{jobId},/idmapping/results/{jobId}
All endpoints and response structures match official documentation.
Limitations
- Single entry retrieval is one accession at a time (use batch for multiple)
- Search API limits individual requests to max 500 results per page (automatic cursor-based pagination retrieves unlimited total results)
- ID mapping limited to 100,000 IDs per job
- No support for compressed responses (API handles transparently)
Future Enhancements
Potential additions:
- BLAST support
- Sequence alignment support
- Peptide search support
- Additional export formats
- Advanced filtering options
- Result caching layer
Contributing
This is a complete, production-ready library with:
- Full API coverage
- Comprehensive documentation
- Working examples
- Automated tests
- Error handling
All core functionality is implemented and tested.
License
This project is dual-licensed:
- Library Code: MIT License - See LICENSE.md
- UniProt Data Access: Creative Commons Attribution (CC BY 4.0) - UniProt Terms of Use
When using this library, you agree to comply with both licenses. The MIT License applies to the PHP code, while UniProt's CC BY 4.0 license applies to the data accessed through the API.
Related Resources
Support
For issues or questions:
- Check documentation
- Review examples
- See error handling guide
- Run smoke tests:
php tests/basic_smoke_tests.php
Built for production. No TODOs. No placeholders. Complete implementation.