Exemplo n.º 1
0
def main():
    option_parser, opts, args = parse_command_line_parameters(**script_info)

    if exists(opts.output_dir):
        # don't overwrite existing output directory - make the user provide a
        # different name or move/delete the existing directory since it may
        # have taken a while to create.
        option_parser.error("Output directory (%s) already exists. "
                            "Won't overwrite." % opts.output_dir)

    personal_ids = opts.personal_ids
    if personal_ids is not None:
        personal_ids = opts.personal_ids.split(',')

    individual_titles = opts.individual_titles.split(',')

    if opts.print_only:
        command_handler = print_commands
    else:
        command_handler = call_commands_serially

    if opts.verbose:
        status_update_callback = print_to_stdout
    else:
        status_update_callback = no_status_updates

    create_personal_results(opts.output_dir,
                            opts.mapping_fp,
                            opts.coord_fname,
                            opts.collated_dir,
                            opts.otu_table_fp,
                            opts.prefs_fp,
                            opts.personal_id_column,
                            personal_ids,
                            opts.column_title,
                            individual_titles,
                            opts.category_to_split,
                            opts.time_series_category,
                            rarefaction_depth=opts.rarefaction_depth,
                            alpha=opts.alpha,
                            rep_set_fp=opts.rep_set_fp,
                            parameter_fp=opts.parameter_fp,
                            body_site_rarefied_otu_table_dir=opts.body_site_rarefied_otu_table_dir,
                            retain_raw_data=opts.retain_raw_data,
                            suppress_alpha_rarefaction=opts.suppress_alpha_rarefaction,
                            suppress_beta_diversity=opts.suppress_beta_diversity,
                            suppress_taxa_summary_plots=opts.suppress_taxa_summary_plots,
                            suppress_alpha_diversity_boxplots=opts.suppress_alpha_diversity_boxplots,
                            suppress_otu_category_significance=opts.suppress_otu_category_significance,
                            command_handler=command_handler,
                            status_update_callback=status_update_callback)
Exemplo n.º 2
0
    def test_create_personal_results_print_only(self):
        """Test running workflow, but only printing the commands."""
        # Save stdout and replace it with something that will capture the print
        # statement. Note: this code was taken from here:
        # http://stackoverflow.com/questions/4219717/how-to-assert-output-
        #     with-nosetest-unittest-in-python/4220278#4220278
        saved_stdout = sys.stdout

        try:
            out = StringIO()
            sys.stdout = out

            obs = create_personal_results(self.output_dir, self.mapping_fp,
                    self.coord_fp, self.rarefaction_dir, self.otu_table_fp,
                    self.prefs_fp, 'PersonalID', rarefaction_depth=10,
                    command_handler=print_commands)
            obs_output = out.getvalue().strip()
        finally:
            sys.stdout = saved_stdout

        exp = set(['NAU123/time_series', 'NAU123/beta_diversity',
                   'NAU789/beta_diversity', 'NAU789/otu_category_significance',
                   'NAU789/alpha_rarefaction', 'NAU456/time_series',
                   'NAU123/alpha_rarefaction', 'NAU456/adiv_boxplots',
                   'NAU456/otu_category_significance', 'NAU123/adiv_boxplots',
                   'NAU123/otu_category_significance', 'NAU789/adiv_boxplots',
                   'NAU789/time_series', 'NAU456/alpha_rarefaction',
                   'NAU456/beta_diversity'])
        fps = []
        for fp in obs:
            fps.append(join(basename(dirname(fp)), basename(fp)))
        # Order is not guaranteed.
        fps = set(fps)

        self.assertEqual(fps, exp)
Exemplo n.º 3
0
    def test_create_personal_results_suppress_all(self):
        """Test running workflow with all output types suppressed."""
        # No output directories should be created under each personal ID
        # directory. We should only end up with a log file, support_files
        # directory, directories for each personal ID, and an index.html file
        # in each.
        exp_personal_ids = ['NAU123', 'NAU456', 'NAU789']

        obs = create_personal_results(self.output_dir, self.mapping_fp,
                self.coord_fp, self.rarefaction_dir, self.otu_table_fp,
                self.prefs_fp, 'PersonalID',
                suppress_alpha_rarefaction=True,
                suppress_beta_diversity=True,
                suppress_taxa_summary_plots=True,
                suppress_alpha_diversity_boxplots=True,
                suppress_otu_category_significance=True)
        self.assertEqual(obs, [])

        num_logs = len(glob(join(self.output_dir, 'log_*.txt')))
        self.assertEqual(num_logs, 1)

        support_files_exist = isdir(join(self.output_dir, 'support_files'))
        self.assertTrue(support_files_exist)

        for personal_id in exp_personal_ids:
            personal_dir_exists = isdir(join(self.output_dir, personal_id))
            self.assertTrue(personal_dir_exists)

            personal_files = map(basename,
                                 glob(join(self.output_dir, personal_id, '*')))
            self.assertEqual(personal_files, ['index.html'])