Skip to content

Instantly share code, notes, and snippets.

Created December 3, 2013 20:05
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save keithshep/7776579 to your computer and use it in GitHub Desktop.
A small example for how to create XML queries for biomart using python
import requests
def main():
exampleTaxonomy = "mmusculus_gene_ensembl"
exampleGene = "ENSMUSG00000086981"
urlTemplate = \
'''''' \
'''<?xml version="1.0" encoding="UTF-8"?>''' \
'''<!DOCTYPE Query>''' \
'''<Query virtualSchemaName="default" formatter="CSV" header="0" uniqueRows="0" count="" datasetConfigVersion="0.6">''' \
'''<Dataset name="%s" interface="default"><Filter name="ensembl_gene_id" value="%s"/>''' \
'''<Attribute name="ensembl_gene_id"/><Attribute name="ensembl_transcript_id"/>''' \
'''<Attribute name="transcript_start"/><Attribute name="transcript_end"/>''' \
'''<Attribute name="exon_chrom_start"/><Attribute name="exon_chrom_end"/>''' \
'''</Dataset>''' \
exampleURL = urlTemplate % (exampleTaxonomy, exampleGene)
req = requests.get(exampleURL, stream=True)
for line in req.iter_lines():
print line
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment