コード例 #1
0
ファイル: test_format.py プロジェクト: jeycin/qiime
 def test_write_summarize_taxa_transposed_output(self):
     """write_summarize_taxa_transposed_output functions as expected"""
     write_summarize_taxa(self.taxa_summary, self.taxa_header, self.tmp_fp1, transposed_output=True)
     obs = open(self.tmp_fp1).read()
     exp = '\n'.join(['SampleID\ta;b;c\td;e;f',
                      'foo\t0\t3\nbar\t1\t4',
                      'foobar\t2\t5\n'])
     self.assertEqual(obs,exp)
     self.files_to_remove.append(self.tmp_fp1)
コード例 #2
0
ファイル: test_format.py プロジェクト: jeycin/qiime
 def test_write_summarize_taxa(self):
     """write_summarize_taxa functions as expected"""
     write_summarize_taxa(self.taxa_summary, self.taxa_header, self.tmp_fp1)
     obs = open(self.tmp_fp1).read()
     exp = '\n'.join(['Taxon\tfoo\tbar\tfoobar',
                      'a;b;c\t0\t1\t2',
                      'd;e;f\t3\t4\t5\n'])
     self.assertEqual(obs,exp)
     self.files_to_remove.append(self.tmp_fp1)
コード例 #3
0
ファイル: test_format.py プロジェクト: Gaby1212/qiime
    def test_write_summarize_taxa(self):
        """write_summarize_taxa functions as expected"""
        # Classic format.
        write_summarize_taxa(self.taxa_summary, self.taxa_header, self.tmp_fp1)
        obs = open(self.tmp_fp1).read()
        exp = "\n".join(["Taxon\tfoo\tbar\tfoobar", "a;b;c\t0\t1\t2", "d;e;f\t3\t4\t5\n"])
        self.assertEqual(obs, exp)
        self.files_to_remove.append(self.tmp_fp1)

        # BIOM format.
        write_summarize_taxa(self.taxa_summary, self.taxa_header, self.tmp_fp2, file_format="biom")
        exp = parse_classic_table_to_rich_table(exp.split("\n"), None, None, None, SparseTaxonTable)
        obs = open(self.tmp_fp2).read()
        obs = parse_biom_table(obs)
        self.assertEqual(obs, exp)
        self.files_to_remove.append(self.tmp_fp2)
コード例 #4
0
ファイル: test_format.py プロジェクト: Gaby1212/qiime
    def test_write_summarize_taxa_transposed_output(self):
        """write_summarize_taxa_transposed_output functions as expected"""
        # Classic format.
        write_summarize_taxa(self.taxa_summary, self.taxa_header, self.tmp_fp1, transposed_output=True)
        obs = open(self.tmp_fp1).read()
        exp = "\n".join(["SampleID\ta;b;c\td;e;f", "foo\t0\t3\nbar\t1\t4", "foobar\t2\t5\n"])
        self.assertEqual(obs, exp)
        self.files_to_remove.append(self.tmp_fp1)

        # BIOM format.
        write_summarize_taxa(
            self.taxa_summary, self.taxa_header, self.tmp_fp2, transposed_output=True, file_format="biom"
        )
        exp = parse_classic_table_to_rich_table(exp.split("\n"), None, None, None, SparseTaxonTable)
        obs = open(self.tmp_fp2).read()
        obs = parse_biom_table(obs)
        self.assertEqual(obs, exp)
        self.files_to_remove.append(self.tmp_fp2)
コード例 #5
0
    def test_write_summarize_taxa(self):
        """write_summarize_taxa functions as expected"""
        # Classic format.
        write_summarize_taxa(self.taxa_summary, self.taxa_header, self.tmp_fp1)
        obs = open(self.tmp_fp1).read()
        exp = '\n'.join(['Taxon\tfoo\tbar\tfoobar',
                         'a;b;c\t0\t1\t2',
                         'd;e;f\t3\t4\t5\n'])
        self.assertEqual(obs, exp)
        self.files_to_remove.append(self.tmp_fp1)

        # BIOM format.
        write_summarize_taxa(self.taxa_summary, self.taxa_header, self.tmp_fp2,
                             file_format='biom')
        exp = parse_classic_table_to_rich_table(exp.split('\n'), None, None,
                                                None, SparseTaxonTable)
        obs = open(self.tmp_fp2).read()
        obs = parse_biom_table(obs)
        self.assertEqual(obs, exp)
        self.files_to_remove.append(self.tmp_fp2)
コード例 #6
0
    def test_write_summarize_taxa_transposed_output(self):
        """write_summarize_taxa_transposed_output functions as expected"""
        # Classic format.
        write_summarize_taxa(
            self.taxa_summary,
            self.taxa_header,
            self.tmp_fp1,
            transposed_output=True)
        obs = open(self.tmp_fp1).read()
        exp = '\n'.join(['SampleID\ta;b;c\td;e;f',
                         'foo\t0\t3\nbar\t1\t4',
                         'foobar\t2\t5\n'])
        self.assertEqual(obs, exp)
        self.files_to_remove.append(self.tmp_fp1)

        # BIOM format.
        write_summarize_taxa(self.taxa_summary, self.taxa_header, self.tmp_fp2,
                             transposed_output=True, file_format='biom')
        exp = parse_classic_table_to_rich_table(exp.split('\n'), None, None,
                                                None, SparseTaxonTable)
        obs = open(self.tmp_fp2).read()
        obs = parse_biom_table(obs)
        self.assertEqual(obs, exp)
        self.files_to_remove.append(self.tmp_fp2)
コード例 #7
0
def main():
    option_parser, opts, args = parse_command_line_parameters(**script_info)

    lower_percentage = opts.lower_percentage
    upper_percentage = opts.upper_percentage
    otu_table_fp = opts.otu_table_fp
    otu_table = parse_biom_table(open(otu_table_fp, 'U'))
    delimiter = opts.delimiter
    mapping_fp = opts.mapping
    md_as_string = opts.md_as_string
    md_identifier = opts.md_identifier
    levels = opts.level.split(',')
    suppress_classic_table_output = opts.suppress_classic_table_output
    suppress_biom_table_output = opts.suppress_biom_table_output

    if upper_percentage!=None and lower_percentage!=None:
        raise ValueError("upper_percentage and lower_percentage are mutually exclusive")
    
    if upper_percentage!=None and lower_percentage!=None and mapping:
        raise ValueError("upper_percentage and lower_percentage can not be using with mapping file")
        
    if upper_percentage!=None and (upper_percentage<0 or upper_percentage>1.0):
        raise ValueError('max_otu_percentage should be between 0.0 and 1.0')
    
    if lower_percentage!=None and (lower_percentage<0 or lower_percentage>1.0):
        raise ValueError('lower_percentage should be between 0.0 and 1.0')
        
    if mapping_fp:
        mapping_file = open(mapping_fp, 'U')
        mapping, header, comments = parse_mapping_file(mapping_file)
        
        # use the input Mapping file for producing the output filenames
        map_dir_path,map_fname=split(mapping_fp)
        map_basename,map_fname_ext=splitext(map_fname)
    else:
        if suppress_classic_table_output and suppress_biom_table_output:
            option_parser.error("Both classic and BIOM output formats were "
                                "suppressed.")

    if opts.relative_abundance != '':
        option_parser.error("Deprecated. Please use --absolute_abundances to disable relative abundance")

    if not opts.absolute_abundance:
        otu_table = otu_table.normObservationBySample()

    # introduced output directory to will allow for multiple outputs
    if opts.output_dir:
        create_dir(opts.output_dir,False)
        output_dir_path=opts.output_dir
    else:
        output_dir_path='./'

    # use the input OTU table to produce the output filenames
    dir_path,fname=split(otu_table_fp)
    basename,fname_ext=splitext(fname)
    
    # Iterate over the levels and generate a summarized taxonomy for each
    for level in levels:
        if mapping_fp:
            #define output filename
            output_fname = join(output_dir_path,
                                        map_basename+'_L%s.txt' % (level))
                                        
            summary, tax_order = add_summary_mapping(otu_table, 
                                                     mapping,
                                                     int(level),
                                                     md_as_string,
                                                     md_identifier)
                                                     
            write_add_taxa_summary_mapping(summary,tax_order,mapping,
                                            header,output_fname,delimiter)
        else:
            # define the output filename. The extension will be added to the
            # end depending on the output format
            output_fname = join(output_dir_path, basename + '_L%s' % level)

            summary, header = make_summary(otu_table,
                                           int(level),
                                           upper_percentage,
                                           lower_percentage,
                                           md_as_string,
                                           md_identifier)

            if not suppress_classic_table_output:
                write_summarize_taxa(summary, header, output_fname + '.txt',
                                     delimiter, opts.transposed_output,
                                     file_format='classic')
            if not suppress_biom_table_output:
                write_summarize_taxa(summary, header, output_fname + '.biom',
                                     delimiter, opts.transposed_output,
                                     file_format='biom')
コード例 #8
0
def main():
    option_parser, opts, args = parse_command_line_parameters(**script_info)

    lower_percentage = opts.lower_percentage
    upper_percentage = opts.upper_percentage
    otu_table_fp = opts.otu_table_fp
    otu_table = parse_otu_table(open(otu_table_fp, 'U'))
    delimiter = opts.delimiter
    mapping_fp = opts.mapping
    levels = opts.level.split(',')

    if upper_percentage!=None and lower_percentage!=None:
        raise ValueError("upper_percentage and lower_percentage are mutually exclusive")
    
    if upper_percentage!=None and lower_percentage!=None and mapping:
        raise ValueError("upper_percentage and lower_percentage can not be using with mapping file")
        
    if upper_percentage!=None and (upper_percentage<0 or upper_percentage>1.0):
        raise ValueError('max_otu_percentage should be between 0.0 and 1.0')
    
    if lower_percentage!=None and (lower_percentage<0 or lower_percentage>1.0):
        raise ValueError('lower_percentage should be between 0.0 and 1.0')
        
    if mapping_fp:
        mapping_file = open(mapping_fp, 'U')
        mapping, header, comments = parse_mapping_file(mapping_file)
        
        # use the input Mapping file for producing the output filenames
        map_dir_path,map_fname=split(mapping_fp)
        map_basename,map_fname_ext=splitext(map_fname)

    if opts.relative_abundance != '':
        raise option_parser.error("Deprecated. Please use --absolute_abundances to disable relative abundance")

    if not opts.absolute_abundance:
        otu_table = convert_otu_table_relative(otu_table)

    # introduced output directory to will allow for multiple outputs
    if opts.output_dir:
        create_dir(opts.output_dir,False)
        output_dir_path=opts.output_dir
    else:
        output_dir_path='./'

    # use the input OTU table to produce the output filenames
    dir_path,fname=split(otu_table_fp)
    basename,fname_ext=splitext(fname)
    
    # Iterate over the levels and generate a summarized taxonomy for each
    for level in levels:
        if mapping_fp:
            #define output filename
            output_fname = join(output_dir_path,
                                        map_basename+'_L%s.txt' % (level))
                                        
            summary, tax_order = add_summary_mapping(otu_table, mapping,
                                                     int(level))
            write_add_taxa_summary_mapping(summary,tax_order,mapping,
                                            header,output_fname,delimiter)
        else:
            #define output filename
            output_fname = join(output_dir_path,basename+'_L%s.txt' % (level))
            
            summary, header = make_summary(otu_table, int(level),
                                            upper_percentage, lower_percentage)
            write_summarize_taxa(summary, header, output_fname, delimiter)