Retrieve individual UniProtKB entries by accession number.
GET https://rest.uniprot.org/uniprotkb/{accession}
use UniProtPHP\Http\HttpClientFactory;
use UniProtPHP\UniProt\UniProtEntry;
$httpClient = HttpClientFactory::create();
$entry = new UniProtEntry($httpClient);
$protein = $entry->get('P12345');The response includes rich protein information:
[
'primaryAccession' => 'P12345',
'uniProtkbId' => 'AATM_RABIT',
'organism' => [
'scientificName' => 'Oryctolagus cuniculus',
'commonName' => 'Rabbit',
'taxonId' => 9986
],
'proteinDescription' => [
'recommendedName' => [
'fullName' => ['value' => 'Aspartate aminotransferase, mitochondrial']
]
],
'sequence' => [
'value' => 'MALLHSARV...',
'length' => 430,
'molWeight' => 47409
],
'comments' => [...], // Function, catalytic activity, cofactors, etc.
'features' => [...], // Binding sites, modified residues, etc.
'references' => [...]
]$protein = $entry->get('P12345', 'json');
// Returns parsed PHP array$fasta = $entry->get('P12345', 'fasta');
echo $fasta['body'];
// Output:
// >sp|P12345|AATM_RABIT Aspartate aminotransferase, mitochondrial...
// MALLHSARVLSGVASAFHPGLAAAASARASSWWAHVEMGPPDPILGVTEAYKR...$xml = $entry->get('P12345', 'xml');
echo $xml['body'];$txt = $entry->get('P12345', 'txt');
echo $txt['body'];$gff = $entry->get('P12345', 'gff');
echo $gff['body'];Only fetch the fields you need to reduce bandwidth:
$data = $entry->getWithFields('P12345', [
'accession', // Primary accession
'protein_name', // Protein names
'organism_name', // Organism
'sequence', // Amino acid sequence
'cc_function', // Function comment
'ft_active_site', // Active site features
'xref_pdb' // PDB cross-references
]);Identification:
accession- Primary accessionid- Entry namegene_names- Gene namesorganism_name- Species nameorganism_id- Taxonomy ID
Sequence:
sequence- Amino acid sequencelength- Sequence lengthmass- Molecular weightfragment- Is fragment?
Function:
cc_function- Function descriptionec- EC numbercc_catalytic_activity- Catalytic activitycc_cofactor- Cofactor information
Structure:
ft_binding- Binding sitesft_active_site- Active siteft_domain- Protein domains
Cross-references:
xref_pdb- 3D structuresxref_interpro- InterPro domainsxref_kegg- KEGG pathways
See UniProt documentation for complete field list.
$results = $entry->getBatch([
'P12345',
'P00750',
'P05067'
]);
foreach ($results as $result) {
if (isset($result['error'])) {
echo "Error for {$result['accession']}: {$result['error']}\n";
} else {
echo $result['primaryAccession'] . "\n";
}
}if ($entry->exists('P12345')) {
$protein = $entry->get('P12345');
} else {
echo "Entry not found\n";
}use UniProtPHP\Exception\UniProtException;
try {
$protein = $entry->get('INVALID');
} catch (UniProtException $e) {
// Entry not found (404)
if ($e->getHttpStatus() === 404) {
echo "Protein not in UniProtKB\n";
}
// Other HTTP errors
else if ($e->getHttpStatus() >= 400) {
echo "Request error: " . $e->getDetailedMessage() . "\n";
}
// Network/transport errors
else {
echo "Connection error: " . $e->getMessage() . "\n";
}
}$data = $entry->getWithFields('P12345', ['cc_function']);
foreach ($data['comments'] as $comment) {
if ($comment['commentType'] === 'FUNCTION') {
echo $comment['texts'][0]['value'];
}
}$data = $entry->getWithFields('P12345', ['cc_subcellular_location']);
foreach ($data['comments'] as $comment) {
if ($comment['commentType'] === 'SUBCELLULAR LOCATION') {
foreach ($comment['subcellularLocations'] as $location) {
echo $location['location']['value'] . "\n";
}
}
}$data = $entry->getWithFields('P12345', ['go', 'go_id']);
foreach ($data['uniProtKBCrossReferences'] as $ref) {
if ($ref['database'] === 'GO') {
echo $ref['id'] . "\n";
}
}$data = $entry->getWithFields('P12345', ['xref_pdb']);
foreach ($data['uniProtKBCrossReferences'] as $ref) {
if ($ref['database'] === 'PDB') {
echo $ref['id'] . "\n";
}
}- Request only needed fields - Reduces response size
- Use batch operations - Combine multiple requests
- Cache results locally - Avoid re-fetching
- Check existence before fetching - Avoid 404 errors
- Handle errors gracefully - Continue with next entry on failure
- Max accessions per request: 1 (use batch retrieval for multiple)
- Max fields per request: No hard limit
- Response time: Typically < 1 second
- Rate limiting: No official limit, but be respectful
- Search documentation - Search entries
- ID Mapping documentation - Map identifiers
- Error Handling - Exception handling