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 = "P02730"
data = fetch_uniprot_data(uniprot_id)
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)