Code Monkey home page Code Monkey logo

biomart's Introduction

============= Biomart 0.9.2

Python API that consumes the biomart webservice.

What it will do:

  • Show all databases of a biomart server
  • Show all datasets of a biomart database
  • Show attributes and filters of a biomart dataset
  • Run your query formatted as a Python dict and return the Biomart response as TSV format.

What it won't do:

  • Process and return the results as JSON,XML,etc.

Usage

Import Biomart module

from biomart import BiomartServer

Connect to a Biomart Server

server = BiomartServer( "http://www.biomart.org/biomart" )
  
# if you are behind a proxy
import os
server.http_proxy = os.environ.get('http_proxy', 'http://my_http_proxy.org')

# set verbose to True to get some messages
server.verbose = True

Interact with the biomart server

# show server databases
server.show_databases() # uses pprint behind the scenes

# show server datasets
server.show_datasets() # uses pprint behind the scenes

# use the 'uniprot' dataset
uniprot = server.datasets['uniprot']

# show all available filters and attributes of the 'uniprot' dataset
uniprot.show_filters()  # uses pprint
uniprot.show_attributes()  # uses pprint

Run a search

# run a search with the default attributes - equivalent to hitting "Results" on the web interface.
# this will return a lot of data.
response = uniprot.search()
response = uniprot.search( header = 1 ) # if you need the columns header

# response format is TSV
for line in response.iter_lines():
line = line.decode('utf-8')
print(line.split("\t"))

# run a count - equivalent to hitting "Count" on the web interface
response = uniprot.count()
print(response.text)

# run a search with custom filters and default attributes.
response = uniprot.search({
'filters': {
    'accession': 'Q9FMA1'
}
}, header = 1 )

response = uniprot.search({
'filters': {
    'accession': ['Q9FMA1', 'Q8LFJ9']  # ID-list specified accessions
}
}, header = 1 )

# run a search with custom filters and attributes (no header)
response = uniprot.search({
'filters': {
    'accession': ['Q9FMA1', 'Q8LFJ9']
},
'attributes': [
    'accession', 'protein_name'
]
})

Shortcut function: connect directly to a biomart dataset This is short in code but it might be long in time since the module needs to fetch all server's databases to find your dataset.

from biomart import BiomartDataset

interpro = BiomartDataset( "http://www.biomart.org/biomart", name = 'entry' )

response = interpro.search({
'filters': { 'entry_id': 'IPR027603' },
'attributes': [ 'entry_name', 'abstract' ]
})

biomart's People

Contributors

krassowski avatar sebriois avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.