Skip to content

Instantly share code, notes, and snippets.

@Stfort52
Created May 10, 2024 07:25
Show Gist options
  • Save Stfort52/b7cafecf00d4ebf2152e4a4e993711d5 to your computer and use it in GitHub Desktop.
Save Stfort52/b7cafecf00d4ebf2152e4a4e993711d5 to your computer and use it in GitHub Desktop.
Simple uniprot interface, not suitable for real querying
def ens2seq(ensembl_id: str) -> str:
"""Converts ensembl gene id to protein sequence
@ensembl_id: str, ensembl gene id
"""
uri = f"https://rest.uniprot.org/uniprotkb/stream?"
query = f"({ensembl_id}) AND (reviewed:true)"
params = {
"compressed": "false",
"format": "fasta",
"query": query
}
response = requests.get(uri, params=params)
fasta = response.text
if fasta == "":
return ""
fasta = fasta.split("\n", 1)[1]
return fasta.replace("\n", "")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment