Code
import requests
import urllib3
urllib3.disable_warnings()
def fetch_uniprot_data(uniprot_id):
url = f"https://rest.uniprot.org/uniprotkb/{uniprot_id}.json"
response = requests.get(url, verify=False) # Disable SSL verification
response.raise_for_status() # Raise an error for bad status codes
return response.json()
def display_uniprot_data(data):
primary_accession = data.get('primaryAccession', 'N/A')
protein_name = data.get('proteinDescription', {}).get('recommendedName', {}).get('fullName', {}).get('value', 'N/A')
gene_name = data.get('gene', [{'geneName': {'value': 'N/A'}}])[0]['geneName']['value']
organism = data.get('organism', {}).get('scientificName', 'N/A')
function_comment = next((comment for comment in data.get('comments', []) if comment['commentType'] == "FUNCTION"), None)
function = function_comment['texts'][0]['value'] if function_comment else 'N/A'
# Printing the data
print(f"UniProt ID: {primary_accession}")
print(f"Protein Name: {protein_name}")
print(f"Organism: {organism}")
print(f"Function: {function}")
# Replace this with the UniProt ID you want to fetch
uniprot_id = "Q8NHL6"
data = fetch_uniprot_data(uniprot_id)
display_uniprot_data(data)UniProt ID: Q8NHL6
Protein Name: Leukocyte immunoglobulin-like receptor subfamily B member 1
Organism: Homo sapiens
Function: Receptor for class I MHC antigens. Recognizes a broad spectrum of HLA-A, HLA-B, HLA-C, HLA-G and HLA-F alleles (PubMed:16455647, PubMed:28636952). Receptor for H301/UL18, a human cytomegalovirus class I MHC homolog. Ligand binding results in inhibitory signals and down-regulation of the immune response. Engagement of LILRB1 present on natural killer cells or T-cells by class I MHC molecules protects the target cells from lysis. Interaction with HLA-B or HLA-E leads to inhibition of FCER1A signaling and serotonin release. Inhibits FCGR1A-mediated phosphorylation of cellular proteins and mobilization of intracellular calcium ions (PubMed:11907092, PubMed:9285411, PubMed:9842885). Recognizes HLA-G in complex with B2M/beta-2 microglobulin and a nonamer self-peptide (PubMed:16455647). Upon interaction with peptide-bound HLA-G-B2M complex, triggers secretion of growth-promoting factors by decidual NK cells (PubMed:19304799, PubMed:29262349). Reprograms B cells toward an immune suppressive phenotype (PubMed:24453251)