Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Programmatic Access to the Alignment Server
import time
import requests
FINISHED = set(['succeeded', 'failed'])
# Some large and slow requests may fail because of the retry limit in requests.
# Set the retry higher for these cases.
# 3 seconds is a pretty good wait most requests should be done in < 10 seconds.
def fetch(*args, **kwargs):
response = requests.get(*args, **kwargs)
response.raise_for_status()
data = response.json()
while data['status'] not in FINISHED:
time.sleep(3)
response = requests.get(*args, **kwargs)
data = response.json()
return response
# Returned content type may be set by changing the accept
headers = {'Accept': 'application/json'}
# Access variations for one nucleotide
response = fetch("http://rna.bgsu.edu/r3d-2-msa",
params={'units': '2AW7|1|A|A|887'}, headers=headers)
data = response.json()
# Access variations while omitting the base letter
response = fetch("http://rna.bgsu.edu/r3d-2-msa",
params={'units': '2AW7|1|A||887'}, headers=headers)
data = response.json()
# Access variations for a range of nucleotides
# We can also use a format parameter to set the returned content type
response = fetch("http://rna.bgsu.edu/r3d-2-msa",
params={'units': '2AW7|1|A|A|887:2AW7|1|A|A|895', 'format': 'json'})
data = response.json()
# Access variations for multiple ranges
response = fetch("http://rna.bgsu.edu/r3d-2-msa",
params={'units': '2AW7|1|A|A|887:2AW7|1|A|A|895,2AW7|1|A|G|200:2AW7|1|A|C|210', 'format': 'json'})
data = response.json()
# It is possible to have up to 5 ranges in the list of ranges
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.