In [ ]:
%load_ext autoreload
%autoreload 2

In [ ]:
%run GLOBALS.py

In [ ]:
import matplotlib

matplotlib.use('TkAgg')
import matplotlib.pyplot as plt

In [ ]:
#import numpy as np
import os
import pandas as pd
import re
import seaborn as sns
#import matplotlib.pyplot as plt
%matplotlib inline

In [ ]:
import elviz_utils
import abundance_utils
import abundance_plot_utils

Plotting


In [ ]:
data_reduced_genus = pd.read_csv(MAIN_DIR + "results/reduced_data--genus_only.csv")

In [ ]:
abundance_utils.filter_by_abundance(data=data_reduced_genus, 
                    abundance_column='fraction of reads', high=1, low=0.5).head()

Demo plot_heatmap()


In [ ]:
data_reduced_genus.head()

In [ ]:
# Change 'other' to 'other & unknown'
data_reduced_genus.ix[data_reduced_genus['Genus'] == 'other', 'Genus'] = r'other \& unknown'
data_reduced_genus.head()

In [ ]:
plot_path = PLOT_DIR + "/genus_only"

abundance_plot_utils.plot_heatmap_genus(dataframe=data_reduced_genus, 
                                        high=1, low = 0.5, 
                                        oxy='High', rep='all', 
                                        plot_dir=plot_path)

Run plot_heatmap_genus() across broad conditions


In [ ]:
# Loop through the ranges we want. 
oxy_conditions = ['Low', 'High']
max_abundance = 1
range_pairs = [(0.01, max_abundance), 
               (0.05, max_abundance), 
               (0.1, max_abundance), 
               (0.5, max_abundance)]
for o in oxy_conditions:
    for r in range_pairs:
        #print "oxygen:", o
        #print "range:", r
        #print "range (low):", r[0]
        abundance_plot_utils.plot_heatmap_genus(dataframe=data_reduced_genus,
                                                low =r[0], high=r[1], oxy=o, rep='all',
                                                plot_dir = PLOT_DIR + '/genus_only')

heatmap_from_taxa_dict()

Reproduce Mila's plots which often have mixed taxonomy levels.

Import the data that was not reduced to Genus.


In [ ]:
data_reduced = pd.read_csv(MAIN_DIR + "/results/reduced_data--all_taxonomy_remains.csv")

In [ ]:
plot_1_spec_dict = {'Phylum':['Bacteroidetes'], 
                    'Order':['Burkholderiales','Methylophilales',
                             'Methylococcales']}

In [ ]:
plot_1_data = abundance_plot_utils.aggregate_mixed_taxonomy(dataframe = 
                          pd.read_csv(
        MAIN_DIR + "/results/reduced_data--all_taxonomy_remains.csv"),
                          taxa_dict = plot_1_spec_dict,
                                                            main_dir = MAIN_DIR)

In [ ]:
plot_1_data.head()

In [ ]:
t_dicts = [
    {'Phylum':['Bacteroidetes'], 
     'Order':['Burkholderiales', 'Methylophilales', 'Methylococcales']},
        
    {'Genus':['Methylobacter', 'Methylovulum', 'Methylomonas', 'Methylomicrobium', 
              'Methyloglobulus', 'Methylococcus', 'Methylocaldum', 'Methylosarcina']},
    
    {'Genus':['Methylotenera', 'Methylovorus', 'Methylophilus', 'Methylobacillus']}

    ]

In [ ]:
for t in t_dicts:
    print(t)
    print(abundance_plot_utils.taxa_dict_to_descriptive_string(t))

In [ ]:
print(MAIN_DIR)
print(PLOT_DIR)

In [ ]:
# plot without annotations
for t_dict in t_dicts:
    abundance_plot_utils.heatmap_from_taxa_dict(
        dataframe = pd.read_csv(MAIN_DIR + "/results/reduced_data--all_taxonomy_remains.csv"),
        taxa_dict = t_dict,
        annotate=False,
        main_dir = MAIN_DIR,
        plot_dir= PLOT_DIR + '/mixed_taxonomy/')

In [ ]:
# plot with annotations
for t_dict in t_dicts:
    abundance_plot_utils.heatmap_from_taxa_dict(dataframe = 
                                               pd.read_csv(MAIN_DIR + "/results/reduced_data--all_taxonomy_remains.csv"),
                                               taxa_dict = t_dict,
                                               facet = 'rep',
                                               annotate = False,
                                               main_dir = MAIN_DIR,
                                               plot_dir = PLOT_DIR + '/mixed_taxonomy/')

170313 add bar plots of the key methanotrophs/methylotrophs


In [ ]:
plot_name = os.path.join(PLOT_DIR, '170420_methanotroph_methylotroph_taxa' + '--portrait.pdf')
p = abundance_plot_utils.plot_dominant_methylotrophs(data_reduced_genus, plot_name)

In [ ]:
plot_name = os.path.join(PLOT_DIR, '170420_methanotroph_methylotroph_taxa' + '--landscape.pdf')
p = abundance_plot_utils.plot_dominant_methylotrophs(data_reduced_genus, plot_name, portrait=False)

In [ ]:
# make a png copy for defense 170420
plot_name = os.path.join(PLOT_DIR, '170420_methanotroph_methylotroph_taxa' + '--landscape.png')
p = abundance_plot_utils.plot_dominant_methylotrophs(data_reduced_genus, plot_name, portrait=False)

170313 add bar plots of the four groups.


In [ ]:
pd.read_csv(MAIN_DIR + "/results/reduced_data--all_taxonomy_remains.csv").head()

In [ ]:
abundance_plot_utils.plot_bars_for_taxa_dict(
    dataframe = pd.read_csv(MAIN_DIR + "/results/reduced_data--all_taxonomy_remains.csv"),
    taxa_dict = plot_1_spec_dict,
    order_list = ['Methylococcales', 'Methylophilales',
                  'Bacteroidetes', 'Burkholderiales', 'unknown \& other'],
    summarize_other = True,
    colors = ['#2c7fb8', '#feb24c', '#525252', '#969696', '#d9d9d9'],
    main_dir = MAIN_DIR,
    filename = os.path.join(PLOT_DIR + '/mixed_taxonomy/', '170413_4_main_groups.pdf'))

In [ ]:
p = abundance_plot_utils.plot_bars_for_taxa_dict(
    dataframe = pd.read_csv(MAIN_DIR + "/results/reduced_data--all_taxonomy_remains.csv"),
    taxa_dict = plot_1_spec_dict,
    order_list = ['Methylococcales', 'Methylophilales',
                  'Bacteroidetes', 'Burkholderiales', 'unknown \& other'],
    summarize_other = True,
    colors = ['#2c7fb8', '#feb24c', '#525252', '#969696', '#d9d9d9'],
    main_dir = MAIN_DIR, portrait=False,
    filename = os.path.join(PLOT_DIR + '/mixed_taxonomy/', '170413_4_main_groups--landscape.pdf'))

In [ ]:
p = abundance_plot_utils.plot_bars_for_taxa_dict(
    dataframe = pd.read_csv(MAIN_DIR + "/results/reduced_data--all_taxonomy_remains.csv"),
    taxa_dict = plot_1_spec_dict,
    order_list = ['Methylococcales', 'Methylophilales',
                  'Bacteroidetes', 'Burkholderiales', 'unknown \& other'],
    summarize_other = True,
    colors = ['#2c7fb8', '#feb24c', '#525252', '#969696', '#d9d9d9'],
    main_dir = MAIN_DIR, portrait=False,
    filename = os.path.join(PLOT_DIR + '/mixed_taxonomy/', '170413_4_main_groups--landscape.png'))

In [ ]: