<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Plotting
Step1:  Demo plot_heatmap()
Step2:  Run plot_heatmap_genus() across broad conditions
Step3:  heatmap_from_taxa_dict()
Reproduce Mila's plots which often have mixed taxonomy levels.
Import the data that was not reduced to Genus.
Step4:  170313 add bar plots of the key methanotrophs/methylotrophs
Step5:  170313 add bar plots of the four groups.
<ASSISTANT_TASK:>
Python Code:
data_reduced_genus = pd.read_csv(MAIN_DIR + "results/reduced_data--genus_only.csv")
abundance_utils.filter_by_abundance(data=data_reduced_genus, 
                    abundance_column='fraction of reads', high=1, low=0.5).head()
Explanation: Plotting
End of explanation
data_reduced_genus.head()
# Change 'other' to 'other & unknown'
data_reduced_genus.ix[data_reduced_genus['Genus'] == 'other', 'Genus'] = r'other \& unknown'
data_reduced_genus.head()
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)
Explanation: Demo plot_heatmap()
End of explanation
# 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')
Explanation: Run plot_heatmap_genus() across broad conditions
End of explanation
data_reduced = pd.read_csv(MAIN_DIR + "/results/reduced_data--all_taxonomy_remains.csv")
plot_1_spec_dict = {'Phylum':['Bacteroidetes'], 
                    'Order':['Burkholderiales','Methylophilales',
                             'Methylococcales']}
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)
plot_1_data.head()
t_dicts = [
    {'Phylum':['Bacteroidetes'], 
     'Order':['Burkholderiales', 'Methylophilales', 'Methylococcales']},
        
    {'Genus':['Methylobacter', 'Methylovulum', 'Methylomonas', 'Methylomicrobium', 
              'Methyloglobulus', 'Methylococcus', 'Methylocaldum', 'Methylosarcina']},
    
    {'Genus':['Methylotenera', 'Methylovorus', 'Methylophilus', 'Methylobacillus']}
    ]
for t in t_dicts:
    print(t)
    print(abundance_plot_utils.taxa_dict_to_descriptive_string(t))
print(MAIN_DIR)
print(PLOT_DIR)
# 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/')
    
# 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/')
Explanation: heatmap_from_taxa_dict()
Reproduce Mila's plots which often have mixed taxonomy levels.
Import the data that was not reduced to Genus.
End of explanation
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)
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)
# 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)
Explanation: 170313 add bar plots of the key methanotrophs/methylotrophs
End of explanation
pd.read_csv(MAIN_DIR + "/results/reduced_data--all_taxonomy_remains.csv").head()
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'))
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'))
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'))
Explanation: 170313 add bar plots of the four groups.
End of explanation
<END_TASK>