def test_format_tep_file_lines(self): """ format_tep_file_lines: this converts files into tep lines """ # set variables prefs_dict1 = {'sample_coloring': {'TEST1': {'column': 'TEST1', 'colors': (('red', (0, 100, 100)), ('blue', (240, 100, 100)))}}} test_biom2 = parse_biom_table(biom2) # test with prefs file exp1 = ['>>tre\n', "['(tax1:0.00000043418318065054,((tax2:0.01932550067944402081,tax3:0.08910446960529855298):0.00000043418318065054,tax4:0.17394765077611337722):0.00000043418318065054,tax5:0.00000043418318065054):0.0;']", '\n', '>>otm\n#OTU ID\tOTU Metadata\n', u'tax1\tk__Bacteria;p__Proteobacteria;', '\n', u'tax2\tk__Bacteria;p__Cyanobacteria;', '\n', '>>osm\n', '# Constructed from biom file\n#OTU ID\tsam1\tsam2\tConsensus Lineage\ntax1\t7.0\t4.0\tk__Bacteria;p__Proteobacteria\ntax2\t1.0\t2.0\tk__Bacteria;p__Cyanobacteria', '\n>>sam\n', "['#SampleID\\tcol1\\tcol0\\tDescription', 'sam1\\tv1_3\\tv0_3\\td1', 'sam2\\taval\\tanother\\td2']", '\n>>pre\n', '0,100,100,\n', '240,100,100,\n', '>defaultTEST1:TEST1\n'] obs1 = format_tep_file_lines(test_biom2, StringIO(example_mapping_file2.split('\n')), StringIO(example_tree.split('\n')), prefs_dict1) self.assertEqual(obs1,exp1) # test without prefs file exp2 = ['>>tre\n', "['(tax1:0.00000043418318065054,((tax2:0.01932550067944402081,tax3:0.08910446960529855298):0.00000043418318065054,tax4:0.17394765077611337722):0.00000043418318065054,tax5:0.00000043418318065054):0.0;']", '\n', '>>otm\n#OTU ID\tOTU Metadata\n', u'tax1\tk__Bacteria;p__Proteobacteria;', '\n', u'tax2\tk__Bacteria;p__Cyanobacteria;', '\n', '>>osm\n', '# Constructed from biom file\n#OTU ID\tsam1\tsam2\tConsensus Lineage\ntax1\t7.0\t4.0\tk__Bacteria;p__Proteobacteria\ntax2\t1.0\t2.0\tk__Bacteria;p__Cyanobacteria', '\n>>sam\n', "['#SampleID\\tcol1\\tcol0\\tDescription', 'sam1\\tv1_3\\tv0_3\\td1', 'sam2\\taval\\tanother\\td2']"] obs2 = format_tep_file_lines(test_biom2, StringIO(example_mapping_file2.split('\n')), StringIO(example_tree.split('\n')), {}) self.assertEqual(obs2,exp2)
def test_format_tep_file_lines(self): """ format_tep_file_lines: this converts files into tep lines """ # set variables prefs_dict1 = {'sample_coloring': {'TEST1': {'column': 'TEST1', 'colors': (('red', (0, 100, 100)), ('blue', (240, 100, 100)))}}} test_biom2 = parse_biom_table(biom2) # test with prefs file exp1 = [ '>>tre\n', "['(tax1:0.00000043418318065054,((tax2:0.01932550067944402081,tax3:0.08910446960529855298):0.00000043418318065054,tax4:0.17394765077611337722):0.00000043418318065054,tax5:0.00000043418318065054):0.0;']", '\n', '>>otm\n#OTU ID\tOTU Metadata\n', u'tax1\tk__Bacteria;p__Proteobacteria;', '\n', u'tax2\tk__Bacteria;p__Cyanobacteria;', '\n', '>>osm\n', '# Constructed from biom file\n#OTU ID\tsam1\tsam2\tConsensus Lineage\ntax1\t7.0\t4.0\tk__Bacteria;p__Proteobacteria\ntax2\t1.0\t2.0\tk__Bacteria;p__Cyanobacteria', '\n>>sam\n', "['#SampleID\\tcol1\\tcol0\\tDescription', 'sam1\\tv1_3\\tv0_3\\td1', 'sam2\\taval\\tanother\\td2']", '\n>>pre\n', '0,100,100,\n', '240,100,100,\n', '>defaultTEST1:TEST1\n'] obs1 = format_tep_file_lines(test_biom2, StringIO( example_mapping_file2.split('\n')), StringIO(example_tree.split('\n')), prefs_dict1) self.assertEqual(obs1, exp1) # test without prefs file exp2 = [ '>>tre\n', "['(tax1:0.00000043418318065054,((tax2:0.01932550067944402081,tax3:0.08910446960529855298):0.00000043418318065054,tax4:0.17394765077611337722):0.00000043418318065054,tax5:0.00000043418318065054):0.0;']", '\n', '>>otm\n#OTU ID\tOTU Metadata\n', u'tax1\tk__Bacteria;p__Proteobacteria;', '\n', u'tax2\tk__Bacteria;p__Cyanobacteria;', '\n', '>>osm\n', '# Constructed from biom file\n#OTU ID\tsam1\tsam2\tConsensus Lineage\ntax1\t7.0\t4.0\tk__Bacteria;p__Proteobacteria\ntax2\t1.0\t2.0\tk__Bacteria;p__Cyanobacteria', '\n>>sam\n', "['#SampleID\\tcol1\\tcol0\\tDescription', 'sam1\\tv1_3\\tv0_3\\td1', 'sam2\\taval\\tanother\\td2']"] obs2 = format_tep_file_lines(test_biom2, StringIO( example_mapping_file2.split('\n')), StringIO(example_tree.split('\n')), {}) self.assertEqual(obs2, exp2)
def main(): option_parser, opts, args =\ parse_command_line_parameters(**script_info) # get command line arguments otu_table_fp = opts.otu_table_fp mapping_fp = opts.mapping_fp tree_fp = opts.tree_fp output_dir = opts.output_dir output_basename = splitext(split(otu_table_fp)[1])[0] web_flag = opts.web_flag url = opts.url # create a generic output folder if not present if not output_dir: output_dir = 'make_tep_output/' create_dir(output_dir) # open files for parsing otu_table_data = parse_biom_table(open(otu_table_fp, 'U')) mapping_lines = open(mapping_fp, 'U') tree_lines = open(tree_fp, 'U') prefs_dict = {} if opts.prefs_file_fp: prefs_fp = opts.prefs_file_fp # I don't like this eval statement prefs_dict = eval(open(prefs_fp, 'U').read()) # get the tep file lines lines = format_tep_file_lines(otu_table_data, mapping_lines, tree_lines, prefs_dict) # write tep file lines if url path not given tep_fp = '%s/%s.tep' % (output_dir, output_basename) if not url: # write tep file tepfile = open(tep_fp, 'w') tepfile.writelines(lines) tepfile.close() # get the jnlp file lines lines = format_jnlp_file_lines(web_flag, url, tep_fp) # write jnlp file jnlp_fp = '%s/%s.jnlp' % (output_dir, output_basename) jnlpfile = open(jnlp_fp, 'w') jnlpfile.writelines(lines) jnlpfile.close()
def main(): option_parser, opts, args =\ parse_command_line_parameters(**script_info) # get command line arguments otu_table_fp = opts.otu_table_fp mapping_fp = opts.mapping_fp tree_fp = opts.tree_fp output_dir = opts.output_dir output_basename = splitext(split(otu_table_fp)[1])[0] web_flag = opts.web_flag url = opts.url # create a generic output folder if not present if not output_dir: output_dir = 'make_tep_output/' create_dir(output_dir) # open files for parsing otu_table_data = parse_biom_table(open(otu_table_fp, 'U')) mapping_lines = open(mapping_fp, 'U') tree_lines = open(tree_fp, 'U') prefs_dict={} if opts.prefs_file_fp: prefs_fp = opts.prefs_file_fp # I don't like this eval statement prefs_dict = eval(open(prefs_fp,'U').read()) # get the tep file lines lines = format_tep_file_lines(otu_table_data, mapping_lines, tree_lines, prefs_dict) # write tep file lines if url path not given tep_fp = '%s/%s.tep' % (output_dir,output_basename) if not url: # write tep file tepfile = open(tep_fp, 'w') tepfile.writelines(lines) tepfile.close() # get the jnlp file lines lines = format_jnlp_file_lines(web_flag, url, tep_fp) # write jnlp file jnlp_fp = '%s/%s.jnlp' % (output_dir,output_basename) jnlpfile = open(jnlp_fp, 'w') jnlpfile.writelines(lines) jnlpfile.close()