Code
import requests
import urllib3
urllib3.disable_warnings()
def fetch_uniprot_data(uniprot_id):
= f"https://rest.uniprot.org/uniprotkb/{uniprot_id}.json"
url = requests.get(url, verify=False) # Disable SSL verification
response # Raise an error for bad status codes
response.raise_for_status() return response.json()
def display_uniprot_data(data):
= data.get('primaryAccession', 'N/A')
primary_accession = data.get('proteinDescription', {}).get('recommendedName', {}).get('fullName', {}).get('value', 'N/A')
protein_name = data.get('gene', [{'geneName': {'value': 'N/A'}}])[0]['geneName']['value']
gene_name = data.get('organism', {}).get('scientificName', 'N/A')
organism
= next((comment for comment in data.get('comments', []) if comment['commentType'] == "FUNCTION"), None)
function_comment = function_comment['texts'][0]['value'] if function_comment else 'N/A'
function
# 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
= "P02730"
uniprot_id = fetch_uniprot_data(uniprot_id)
data display_uniprot_data(data)
UniProt ID: P02730
Protein Name: Band 3 anion transport protein
Organism: Homo sapiens
Function: Functions both as a transporter that mediates electroneutral anion exchange across the cell membrane and as a structural protein (PubMed:10926824, PubMed:14734552, PubMed:1538405, PubMed:16227998, PubMed:20151848, PubMed:24121512, PubMed:28387307, PubMed:35835865). Component of the ankyrin-1 complex of the erythrocyte membrane; required for normal flexibility and stability of the erythrocyte membrane and for normal erythrocyte shape via the interactions of its cytoplasmic domain with cytoskeletal proteins, glycolytic enzymes, and hemoglobin (PubMed:1538405, PubMed:20151848, PubMed:35835865). Functions as a transporter that mediates the 1:1 exchange of inorganic anions across the erythrocyte membrane. Mediates chloride-bicarbonate exchange in the kidney, and is required for normal acidification of the urine (PubMed:10926824, PubMed:14734552, PubMed:16227998, PubMed:24121512, PubMed:28387307)