# 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
#!/usr/bin/env python
# File created on 22 Feb 2012
from __future__ import division

__author__ = "Greg Caporaso"
__copyright__ = "Copyright 2011-2013, The PICRUSt Project"
__credits__ = ["Greg Caporaso"]
__license__ = "GPL"
__version__ = "1.1.4"
__maintainer__ = "Greg Caporaso"
__email__ = "gregcaporaso@gmail.com"
__status__ = "Development"
 


class ParseTests(TestCase):
    """ """
    
    def setUp(self):
        """ """
        self.counts_f1 = counts_f1.split('\n')
        self.counts_bad1 = counts_bad1.split('\n')
        self.counts_bad2 = counts_bad2.split('\n')
    
    def test_extract_ids_from_table_qiime_legacy_otu_table(self):
        """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']

# 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

#!/usr/bin/env python
# File created on 22 Feb 2012
from __future__ import division

__author__ = "Greg Caporaso"
__copyright__ = "Copyright 2011-2013, The PICRUSt Project"
__credits__ = ["Greg Caporaso"]
__license__ = "GPL"
__version__ = "1.1.4"
__maintainer__ = "Greg Caporaso"
__email__ = "gregcaporaso@gmail.com"
__status__ = "Development"
 


class ParseTests(TestCase):
    """ """
    
    def setUp(self):
        """ """
        self.counts_f1 = counts_f1.split('\n')
        self.counts_bad1 = counts_bad1.split('\n')
        self.counts_bad2 = counts_bad2.split('\n')
    
    def test_extract_ids_from_table_qiime_legacy_otu_table(self):
        """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)