def test_add_counts_to_mapping(self): """NumIndividuals is added to the mapping file""" # Get the output filepath out_fp = get_tmp_filename(tmp_dir=self.tmp_dir, suffix='.txt') # Add the output filepath to clean variable self._paths_to_clean_up = [out_fp] # Perform the test add_counts_to_mapping(self.biom_table, self.mapping, False, out_fp) f = open(out_fp, 'U') obs = f.readlines() f.close() self.assertEqual(obs, exp_mapping_file_seqs.splitlines(True)) # Get the output filepath out_fp = get_tmp_filename(tmp_dir=self.tmp_dir, suffix='.txt') # Add the output filepath to clean variable self._paths_to_clean_up.append(out_fp) # Perform the test add_counts_to_mapping(self.biom_table, self.mapping, True, out_fp) f = open(out_fp, 'U') obs = f.readlines() f.close() self.assertEqual(obs, exp_mapping_file_otu.splitlines(True))
'--input_fp', type="existing_filepath", help='Biom table filepath'), make_option('-m', '--mapping_fp', type="existing_filepath", help='Mapping file filepath'), make_option('-o', '--output_fp', type="new_filepath", help='Output mapping filepath') ] script_info['optional_options'] = [ make_option( '--otu_counts', action='store_true', default=False, help='Counts are presented as number of observed OTUs per sample, ' + 'rather than counts of sequences per sample [default: %default]') ] script_info['version'] = __version__ if __name__ == '__main__': option_parser, opts, args = parse_command_line_parameters(**script_info) biom_fp = opts.input_fp mapping_fp = opts.mapping_fp output_fp = opts.output_fp otu_counts = opts.otu_counts add_counts_to_mapping(open(biom_fp, 'U'), open(mapping_fp, 'U'), otu_counts, output_fp)
"%prog -i otu_table.biom -m mapping_file.txt -o mapping_w_counts.txt"), ("Example", "Count the number of OTUs per sample present in " + \ "'otu_table.biom' and add this counts to 'mapping_file.txt'", "%prog -i otu_table.biom -m mapping_file.txt --otu_counts " + \ "-o mapping_w_counts.txt") ] script_info['output_description'] = "The mapping file with the counts added" script_info['required_options'] = [ make_option('-i', '--input_fp', type="existing_filepath", help='Biom table filepath'), make_option('-m', '--mapping_fp', type="existing_filepath", help='Mapping file filepath'), make_option('-o', '--output_fp', type="new_filepath", help='Output mapping filepath') ] script_info['optional_options'] = [ make_option('--otu_counts', action='store_true', default=False, help='Counts are presented as number of observed OTUs per sample, ' + 'rather than counts of sequences per sample [default: %default]') ] script_info['version'] = __version__ if __name__ == '__main__': option_parser, opts, args = parse_command_line_parameters(**script_info) biom_fp = opts.input_fp mapping_fp = opts.mapping_fp output_fp = opts.output_fp otu_counts = opts.otu_counts add_counts_to_mapping(open(biom_fp, 'U'), open(mapping_fp, 'U'), otu_counts, output_fp)