Skip to content

Instantly share code, notes, and snippets.

@andrewyatz
Created November 8, 2024 15:39
Show Gist options
  • Save andrewyatz/e457d42b4bb05b346cd17a87474fe8da to your computer and use it in GitHub Desktop.
Save andrewyatz/e457d42b4bb05b346cd17a87474fe8da to your computer and use it in GitHub Desktop.
Collection of utilities to work with Ensembl's GraphQL service
# Requires you to install gql
from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport
from pprint import pp
server="https://beta.ensembl.org/data/graphql"
transport = AIOHTTPTransport(url=server)
# Create a GraphQL client using the defined transport
async with Client(
transport=transport,
fetch_schema_from_transport=True,
) as session:
# Provide a GraphQL query
query = gql(
"""
query getAssembly($accession: String!) {
genomes(by_keyword: { assembly_accession_id: $accession}) {
genome_id
assembly_accession
scientific_name
release_number
release_date
taxon_id
parlance_name
is_reference
assembly {
name
accession_id
regions {
name
length
sequence {
checksum
}
}
}
}
}
"""
)
params = { "accession" : "GCA_000001405.29" }
# Execute the query on the transport
result = await session.execute(query, variable_values=params)
pp(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment