Emperor's Python API

This notebook demonstrate Emperor's new Python API, which can and will change as we continue to exercise this interface, for more information, have a look at the pull request here.

In [ ]:
import pandas as pd, numpy as np
from emperor import Emperor, nbinstall
from skbio import OrdinationResults

from emperor.qiime_backports.parse import parse_mapping_file
from emperor.qiime_backports.format import format_mapping_file

from skbio.io.util import open_file


def load_mf(fn):
    with open_file(fn) as f:
        mapping_data, header, _ = parse_mapping_file(f)
        _mapping_file = pd.DataFrame(mapping_data, columns=header)
        _mapping_file.set_index('SampleID', inplace=True)
    return _mapping_file

def write_mf(f, _df):
    with open(f, 'w') as fp:
        lines = format_mapping_file(['SampleID'] + _df.columns.tolist(),

We are going to load data from Fierer et al. 2010 (the data was retrieved from study 232 in Qiita, remember you need to be logged in to access the study).

Specifically, here we will reproduce Figure 1 A.

In [ ]:
mf = load_mf('keyboard/mapping-file.txt')
res = OrdinationResults.read('keyboard/unweighted-unifrac.even1000.txt')

If you want to share your notebook via GitHub use remote=True and make sure you share your notebook using nbviewer.

In [ ]:
x = Emperor(res, mf, remote=True)
In [ ]: