# Path: picrust/parse.py
# def extract_ids_from_table(table_lines,delimiter="\t",header_start_string="#",id_field_idx=0):
#     """Return a list of ids from a tab-delimited table
# 
#     table_lines -- an iterable collection of lines
#     delimiter -- the delimiter for fields in a line
#     header_start_string -- the string (if any) marking header lines
#     that should be skipped.
# 
#     NOTE:  this works with legacy QIIME OTU tables (amongst others)
# 
#     """
#     header, id_fields = parse_trait_table(table_lines,delimiter=delimiter,has_header=False)
#     result = []
#     for f in id_fields:
#         result.append(f[id_field_idx])
#     return result
# 
# def parse_asr_confidence_output(table_lines,param_names=['loglik','sigma'],format='sigma'):
#     """Return reconstruction parameters from reconstruction table
# 
# 
#     """
#     min_value_dict = {}
#     max_value_dict = {}
#     params = {}
#     column_mapping = {}
#     for i,line in enumerate(table_lines):
#         if i == 0:
#             #Header line, skip it
#             column_names = line.split("\t")[1:]
#             for i in range(len(column_names)):
#                 column_mapping[column_names[i]] = i
#             continue
#         fields = line.split("\t")
#         if fields[0] in param_names:
#             vals = fields[1].split("|")
#             valid_vals = []
#             for val in vals:
#                 if val == "NaN":
#                     valid_vals.append(None)
#                 else:
#                     valid_vals.append(float(val))
#             params[fields[0]]=valid_vals
#             continue
#         organism_name = fields[0]
#         data_fields = fields[1:]
#         #print "data_fields:",data_fields
#         min_vals = map(float,[f.split("|")[0] for f in data_fields])
#         max_vals = map(float,[f.split("|")[1] for f in data_fields])
#         min_value_dict[organism_name]=min_vals
#         max_value_dict[organism_name]=max_vals
#         #print "min_val_dict:",min_value_dict
#     return min_value_dict,max_value_dict,params,column_mapping


from cogent.util.unit_test import TestCase, main
from picrust.parse import extract_ids_from_table, parse_asr_confidence_output
        """extract_ids_from_table extracts ids from a legacy QIIME 1.3 OTU table
        """
        exp = ['39','238','277','1113','1206','1351',\
          '1637','2043','3472','3757','4503','4546',\
          '5403','5479']
        obs = extract_ids_from_table(otu_table_lines)
        self.assertEqual(obs,exp)
        
    
    def test_parse_asr_confidence_output(self):
        """parse_asr_confidence_output parses PICRUST per node confidence output in ML format (includes sigma and loglik values)"""
        
        asr_lines = asr_confidence_output

        min_vals ={\
          'node1': -36.0545,\
          'node10': -15.3024,\
          "'f__Acaryochloridaceae__g__Acaryochloris'":-7.1233,\
          "'f__Synechococcaceae'": -9.2953
        }
        max_vals ={\
          'node1': 44.0219,\
          'node10': 23.2732,\
          "'f__Acaryochloridaceae__g__Acaryochloris'":14.682,\
          "'f__Synechococcaceae'": 17.0651
        }
        sigma = 5986.9627
        loglik = -12353.4949
        
        obs_min_vals,obs_max_vals, params,column_mapping =\

# Path: picrust/parse.py
# def extract_ids_from_table(table_lines,delimiter="\t",header_start_string="#",id_field_idx=0):
#     """Return a list of ids from a tab-delimited table
# 
#     table_lines -- an iterable collection of lines
#     delimiter -- the delimiter for fields in a line
#     header_start_string -- the string (if any) marking header lines
#     that should be skipped.
# 
#     NOTE:  this works with legacy QIIME OTU tables (amongst others)
# 
#     """
#     header, id_fields = parse_trait_table(table_lines,delimiter=delimiter,has_header=False)
#     result = []
#     for f in id_fields:
#         result.append(f[id_field_idx])
#     return result
# 
# def parse_asr_confidence_output(table_lines,param_names=['loglik','sigma'],format='sigma'):
#     """Return reconstruction parameters from reconstruction table
# 
# 
#     """
#     min_value_dict = {}
#     max_value_dict = {}
#     params = {}
#     column_mapping = {}
#     for i,line in enumerate(table_lines):
#         if i == 0:
#             #Header line, skip it
#             column_names = line.split("\t")[1:]
#             for i in range(len(column_names)):
#                 column_mapping[column_names[i]] = i
#             continue
#         fields = line.split("\t")
#         if fields[0] in param_names:
#             vals = fields[1].split("|")
#             valid_vals = []
#             for val in vals:
#                 if val == "NaN":
#                     valid_vals.append(None)
#                 else:
#                     valid_vals.append(float(val))
#             params[fields[0]]=valid_vals
#             continue
#         organism_name = fields[0]
#         data_fields = fields[1:]
#         #print "data_fields:",data_fields
#         min_vals = map(float,[f.split("|")[0] for f in data_fields])
#         max_vals = map(float,[f.split("|")[1] for f in data_fields])
#         min_value_dict[organism_name]=min_vals
#         max_value_dict[organism_name]=max_vals
#         #print "min_val_dict:",min_value_dict
#     return min_value_dict,max_value_dict,params,column_mapping


# Path: tests/test_parse.py
from cogent.util.unit_test import TestCase, main
from picrust.parse import extract_ids_from_table, parse_asr_confidence_output

        """extract_ids_from_table extracts ids from a legacy QIIME 1.3 OTU table
        """
        exp = ['39','238','277','1113','1206','1351',\
          '1637','2043','3472','3757','4503','4546',\
          '5403','5479']
        obs = extract_ids_from_table(otu_table_lines)
        self.assertEqual(obs,exp)
        
    
    def test_parse_asr_confidence_output(self):
        """parse_asr_confidence_output parses PICRUST per node confidence output in ML format (includes sigma and loglik values)"""
        
        asr_lines = asr_confidence_output

        min_vals ={\
          'node1': -36.0545,\
          'node10': -15.3024,\
          "'f__Acaryochloridaceae__g__Acaryochloris'":-7.1233,\
          "'f__Synechococcaceae'": -9.2953
        }
        max_vals ={\
          'node1': 44.0219,\
          'node10': 23.2732,\
          "'f__Acaryochloridaceae__g__Acaryochloris'":14.682,\
          "'f__Synechococcaceae'": 17.0651
        }
        sigma = 5986.9627
        loglik = -12353.4949
        
        obs_min_vals,obs_max_vals, params,column_mapping =\

         parse_asr_confidence_output(asr_confidence_output)