Created
December 3, 2013 20:05
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
def main(): | |
exampleTaxonomy = "mmusculus_gene_ensembl" | |
exampleGene = "ENSMUSG00000086981" | |
urlTemplate = \ | |
'''http://ensembl.org/biomart/martservice?query=''' \ | |
'''<?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>''' \ | |
'''</Query>''' | |
exampleURL = urlTemplate % (exampleTaxonomy, exampleGene) | |
req = requests.get(exampleURL, stream=True) | |
for line in req.iter_lines(): | |
print line | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment