# Path: picrust/format_tree_and_trait_table.py
# def reformat_tree_and_trait_table(tree,trait_table_lines,trait_to_tree_mapping,\
#     input_trait_table_delimiter="\t", output_trait_table_delimiter="\t",\
#     filter_table_by_tree_tips=True, convert_trait_floats_to_ints=False,\
#     filter_tree_by_table_entries=True,convert_to_bifurcating=False,\
#     add_branch_length_to_root=False, name_unnamed_nodes=True,\
#     remove_whitespace_from_labels = True,replace_ambiguous_states=True,\
#     replace_problematic_label_characters = True,min_branch_length=0.0001,\
#     verbose=True):
# def check_node_labels(input_tree,verbose=False):
# def set_label_conversion_fns(remove_whitespace_from_labels=True,\
#   replace_problematic_label_characters=True,verbose=False):
# def set_value_conversion_fns(replace_ambiguous_states=True,\
#       convert_trait_floats_to_ints=False,verbose=False):
# def fix_tree_labels(tree,label_conversion_fns,verbose=False):
# def make_internal_nodes_unique(tree,base_name='internal_node_%i'):
# def format_tree_node_names(tree,label_formatting_fns=[]):
# def nexus_lines_from_tree(tree):
# def add_branch_length_to_root(tree, root_name ="root",root_length=0.0001):
# def set_min_branch_length(tree,min_length= 0.0001):
# def make_nexus_trees_block(tree):
# def validate_trait_table_to_tree_mappings(tree,trait_table_ids,verbose=True):
# def filter_table_by_presence_in_tree(tree,trait_table_fields,name_field_index = 0,delimiter="\t"):
# def make_translate_conversion_fn(translation_dict):
#     def translate_conversion_fn(trait_value_field):
# def make_char_translation_fn(translation_dict,deletion_chars=''):
#     def translate_conversion_fn(trait_value_field):
# def remove_spaces(trait_label_field):
# def convert_trait_table_entries(trait_table_fields,\
#         label_conversion_fns=[str],value_conversion_fns = [float]):
# def ensure_root_is_bifurcating(tree,root_name='root',verbose=False):
# def filter_tree_tips_by_presence_in_table(tree,trait_table_fields,name_field_index = 0,\
#       delimiter="\t",verbose=True):
# def get_sub_tree(tree,tips_not_to_prune):
# def print_node_summary_table(input_tree):
# def add_to_filename(filename,new_suffix,delimiter="_"):
# def make_id_mapping_dict(tree_to_trait_mappings):
# def parse_id_mapping_file(file_lines,delimiter="\t"):
# def remap_trait_table_organisms(trait_table_fields,trait_to_tree_mapping_dict,verbose=False):
# def load_picrust_tree(tree_fp, verbose=False):
# def load_tab_delimited_trait_table(trait_table_fp,verbose=False):


from cogent.util.unit_test import main, TestCase
from cogent import LoadTree
from cogent.parse.tree import DndParser
from picrust.format_tree_and_trait_table import reformat_tree_and_trait_table,\
  nexus_lines_from_tree,add_branch_length_to_root,\
  set_min_branch_length,make_nexus_trees_block,\
  filter_table_by_presence_in_tree,convert_trait_table_entries,\
  yield_trait_table_fields,ensure_root_is_bifurcating,\
  filter_tree_tips_by_presence_in_table,print_node_summary_table,\
  add_to_filename,make_id_mapping_dict,make_translate_conversion_fn,\
  make_char_translation_fn,remove_spaces, format_tree_node_names
        #Basic Test
        filename = "my_tree.newick"
        new_suffix = "formatted"
        delimiter = "_"

        obs = add_to_filename(filename,new_suffix,delimiter)
        exp = "my_tree_formatted.newick"
        
        self.assertEqual(obs,exp)

        #Make sure it works with multiple extensions
        
        # NOTE: this fn is based on splitext from os.path
        # therefore only the rightmost extension is considered.
        
        
        filename = "my_tree.this.is.a.newick"
        new_suffix = "formatted"
        delimiter = "."

        obs = add_to_filename(filename,new_suffix,delimiter)
        exp = "my_tree.this.is.a.formatted.newick"
        
        self.assertEqual(obs,exp)

    def test_make_id_mapping_dict(self):
        """Make id mapping dict should generate two mapping dicts"""

        mappings = self.GreengenesToIMG
        trait_to_tree_mappings =\

# Path: picrust/format_tree_and_trait_table.py
# def reformat_tree_and_trait_table(tree,trait_table_lines,trait_to_tree_mapping,\
#     input_trait_table_delimiter="\t", output_trait_table_delimiter="\t",\
#     filter_table_by_tree_tips=True, convert_trait_floats_to_ints=False,\
#     filter_tree_by_table_entries=True,convert_to_bifurcating=False,\
#     add_branch_length_to_root=False, name_unnamed_nodes=True,\
#     remove_whitespace_from_labels = True,replace_ambiguous_states=True,\
#     replace_problematic_label_characters = True,min_branch_length=0.0001,\
#     verbose=True):
# def check_node_labels(input_tree,verbose=False):
# def set_label_conversion_fns(remove_whitespace_from_labels=True,\
#   replace_problematic_label_characters=True,verbose=False):
# def set_value_conversion_fns(replace_ambiguous_states=True,\
#       convert_trait_floats_to_ints=False,verbose=False):
# def fix_tree_labels(tree,label_conversion_fns,verbose=False):
# def make_internal_nodes_unique(tree,base_name='internal_node_%i'):
# def format_tree_node_names(tree,label_formatting_fns=[]):
# def nexus_lines_from_tree(tree):
# def add_branch_length_to_root(tree, root_name ="root",root_length=0.0001):
# def set_min_branch_length(tree,min_length= 0.0001):
# def make_nexus_trees_block(tree):
# def validate_trait_table_to_tree_mappings(tree,trait_table_ids,verbose=True):
# def filter_table_by_presence_in_tree(tree,trait_table_fields,name_field_index = 0,delimiter="\t"):
# def make_translate_conversion_fn(translation_dict):
#     def translate_conversion_fn(trait_value_field):
# def make_char_translation_fn(translation_dict,deletion_chars=''):
#     def translate_conversion_fn(trait_value_field):
# def remove_spaces(trait_label_field):
# def convert_trait_table_entries(trait_table_fields,\
#         label_conversion_fns=[str],value_conversion_fns = [float]):
# def ensure_root_is_bifurcating(tree,root_name='root',verbose=False):
# def filter_tree_tips_by_presence_in_table(tree,trait_table_fields,name_field_index = 0,\
#       delimiter="\t",verbose=True):
# def get_sub_tree(tree,tips_not_to_prune):
# def print_node_summary_table(input_tree):
# def add_to_filename(filename,new_suffix,delimiter="_"):
# def make_id_mapping_dict(tree_to_trait_mappings):
# def parse_id_mapping_file(file_lines,delimiter="\t"):
# def remap_trait_table_organisms(trait_table_fields,trait_to_tree_mapping_dict,verbose=False):
# def load_picrust_tree(tree_fp, verbose=False):
# def load_tab_delimited_trait_table(trait_table_fp,verbose=False):


# Path: tests/test_format_tree_and_trait_table.py
from cogent.util.unit_test import main, TestCase
from cogent import LoadTree
from cogent.parse.tree import DndParser
from picrust.format_tree_and_trait_table import reformat_tree_and_trait_table,\
  nexus_lines_from_tree,add_branch_length_to_root,\
  set_min_branch_length,make_nexus_trees_block,\
  filter_table_by_presence_in_tree,convert_trait_table_entries,\
  yield_trait_table_fields,ensure_root_is_bifurcating,\
  filter_tree_tips_by_presence_in_table,print_node_summary_table,\
  add_to_filename,make_id_mapping_dict,make_translate_conversion_fn,\
  make_char_translation_fn,remove_spaces, format_tree_node_names

        #Basic Test
        filename = "my_tree.newick"
        new_suffix = "formatted"
        delimiter = "_"

        obs = add_to_filename(filename,new_suffix,delimiter)
        exp = "my_tree_formatted.newick"
        
        self.assertEqual(obs,exp)

        #Make sure it works with multiple extensions
        
        # NOTE: this fn is based on splitext from os.path
        # therefore only the rightmost extension is considered.
        
        
        filename = "my_tree.this.is.a.newick"
        new_suffix = "formatted"
        delimiter = "."

        obs = add_to_filename(filename,new_suffix,delimiter)
        exp = "my_tree.this.is.a.formatted.newick"
        
        self.assertEqual(obs,exp)

    def test_make_id_mapping_dict(self):
        """Make id mapping dict should generate two mapping dicts"""

        mappings = self.GreengenesToIMG
        trait_to_tree_mappings =\

        make_id_mapping_dict(mappings)