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 = "P49146"
data = fetch_uniprot_data(uniprot_id)
display_uniprot_data(data)UniProt ID: P49146
Protein Name: Neuropeptide Y receptor type 2
Organism: Homo sapiens
Function: Receptor for neuropeptide Y and peptide YY. The rank order of affinity of this receptor for pancreatic polypeptides is PYY > NPY > PYY (3-36) > NPY (2-36) > [Ile-31, Gln-34] PP > [Leu-31, Pro-34] NPY > PP, [Pro-34] PYY and NPY free acid