# Path: picrust/ace.py
# def ace_for_picrust(tree_path,trait_table_path,method='pic',HALT_EXEC=False):
#     '''Runs the Ace application controller given path of tree and trait table and returns a Table'''
#     #initialize Ace app controller
#     ace=Ace(HALT_EXEC=HALT_EXEC)
# 
#     tmp_output_count_path=get_tmp_filename()
#     tmp_output_prob_path=get_tmp_filename()
# 
#     #quote file names
#     tree_path='"{0}"'.format(tree_path)
#     trait_table_path='"{0}"'.format(trait_table_path)
# 
#     as_string = " ".join([tree_path,trait_table_path,method,tmp_output_count_path,tmp_output_prob_path])
#     #Run ace here
#     result = ace(data=as_string)
# 
#     #Load the output into Table objects
#     try:
#         asr_table=LoadTable(filename=tmp_output_count_path,header=True,sep='\t')
#     except IOError:
#         raise RuntimeError,\
#          ("R reported an error on stderr:"
#           " %s" % "\n".join(result["StdErr"].readlines()))
# 
#     asr_prob_table=LoadTable(filename=tmp_output_prob_path,header=True,sep='\t')
# 
#     #Remove tmp files
#     remove(tmp_output_count_path)
#     remove(tmp_output_prob_path)
# 
#     return asr_table,asr_prob_table


from cogent.util.unit_test import TestCase, main
from picrust.ace import ace_for_picrust
from cogent.app.util import get_tmp_filename
from cogent.util.misc import remove_files
from cogent import LoadTable
from cogent.util.table import Table
        self.in_tree2_file.write(in_tree2)
        self.in_tree2_file.close()

        #create a tmp trait file
        self.in_trait1_fp = get_tmp_filename(prefix='AceTests',suffix='.tsv')
        self.in_trait1_file=open(self.in_trait1_fp,'w')
        self.in_trait1_file.write(in_trait1)
        self.in_trait1_file.close()

        #create another tmp trait file (need to test table with only single column seperately)
        self.in_trait2_fp = get_tmp_filename(prefix='AceTests',suffix='.tsv')
        self.in_trait2_file=open(self.in_trait2_fp,'w')
        self.in_trait2_file.write(in_trait2)
        self.in_trait2_file.close()

        #create a tmp trait file (with underscores in tip names)
        self.in_trait3_fp = get_tmp_filename(prefix='AceTests',suffix='.tsv')
        self.in_trait3_file=open(self.in_trait3_fp,'w')
        self.in_trait3_file.write(in_trait3)
        self.in_trait3_file.close()

        self.files_to_remove = [self.in_tree1_fp,self.in_trait1_fp,self.in_trait2_fp, self.in_trait3_fp, self.in_tree2_fp]

    def tearDown(self):
        remove_files(self.files_to_remove)
                       

    def test_ace_for_picrust_ml(self):
        """ test_ace_for_picrust with method 'ML' functions as expected with valid input
        """

# Path: picrust/ace.py
# def ace_for_picrust(tree_path,trait_table_path,method='pic',HALT_EXEC=False):
#     '''Runs the Ace application controller given path of tree and trait table and returns a Table'''
#     #initialize Ace app controller
#     ace=Ace(HALT_EXEC=HALT_EXEC)
# 
#     tmp_output_count_path=get_tmp_filename()
#     tmp_output_prob_path=get_tmp_filename()
# 
#     #quote file names
#     tree_path='"{0}"'.format(tree_path)
#     trait_table_path='"{0}"'.format(trait_table_path)
# 
#     as_string = " ".join([tree_path,trait_table_path,method,tmp_output_count_path,tmp_output_prob_path])
#     #Run ace here
#     result = ace(data=as_string)
# 
#     #Load the output into Table objects
#     try:
#         asr_table=LoadTable(filename=tmp_output_count_path,header=True,sep='\t')
#     except IOError:
#         raise RuntimeError,\
#          ("R reported an error on stderr:"
#           " %s" % "\n".join(result["StdErr"].readlines()))
# 
#     asr_prob_table=LoadTable(filename=tmp_output_prob_path,header=True,sep='\t')
# 
#     #Remove tmp files
#     remove(tmp_output_count_path)
#     remove(tmp_output_prob_path)
# 
#     return asr_table,asr_prob_table


# Path: tests/test_ace.py
from cogent.util.unit_test import TestCase, main
from picrust.ace import ace_for_picrust
from cogent.app.util import get_tmp_filename
from cogent.util.misc import remove_files
from cogent import LoadTable
from cogent.util.table import Table

        self.in_tree2_file.write(in_tree2)
        self.in_tree2_file.close()

        #create a tmp trait file
        self.in_trait1_fp = get_tmp_filename(prefix='AceTests',suffix='.tsv')
        self.in_trait1_file=open(self.in_trait1_fp,'w')
        self.in_trait1_file.write(in_trait1)
        self.in_trait1_file.close()

        #create another tmp trait file (need to test table with only single column seperately)
        self.in_trait2_fp = get_tmp_filename(prefix='AceTests',suffix='.tsv')
        self.in_trait2_file=open(self.in_trait2_fp,'w')
        self.in_trait2_file.write(in_trait2)
        self.in_trait2_file.close()

        #create a tmp trait file (with underscores in tip names)
        self.in_trait3_fp = get_tmp_filename(prefix='AceTests',suffix='.tsv')
        self.in_trait3_file=open(self.in_trait3_fp,'w')
        self.in_trait3_file.write(in_trait3)
        self.in_trait3_file.close()

        self.files_to_remove = [self.in_tree1_fp,self.in_trait1_fp,self.in_trait2_fp, self.in_trait3_fp, self.in_tree2_fp]

    def tearDown(self):
        remove_files(self.files_to_remove)
                       

    def test_ace_for_picrust_ml(self):
        """ test_ace_for_picrust with method 'ML' functions as expected with valid input
        """

        actual,actual_ci= ace_for_picrust(self.in_tree1_fp, self.in_trait1_fp, method="ML")