Esempio n. 1
0
    def test_run_jackknifed_beta_diversity_parallel(self):
        """ run_jackknifed_beta_diversity generates expected results """

        run_jackknifed_beta_diversity(
            self.test_data['biom'][0],
            self.test_data['tree'][0],
            20,
            self.test_out,
            call_commands_serially,
            self.params,
            self.qiime_config,
            self.test_data['map'][0],
            parallel=True,
            status_update_callback=no_status_updates)

        weighted_unifrac_upgma_tree_fp = join(self.test_out,
                                              'weighted_unifrac',
                                              'upgma_cmp', 'jackknife_named_nodes.tre')
        unweighted_unifrac_upgma_tree_fp = join(
            self.test_out, 'unweighted_unifrac', 'upgma_cmp',
            'jackknife_named_nodes.tre')
        weighted_unifrac_emperor_index_fp = join(
            self.test_out, 'weighted_unifrac', 'emperor_pcoa_plots',
            'index.html')
        unweighted_unifrac_emperor_index_fp = join(
            self.test_out, 'unweighted_unifrac', 'emperor_pcoa_plots',
            'index.html')

        input_file_basename = splitext(split(self.test_data['biom'][0])[1])[0]
        unweighted_unifrac_dm_fp = join(self.test_out,
                                        'unweighted_unifrac_%s.txt' % input_file_basename)
        weighted_unifrac_dm_fp = join(self.test_out,
                                      'weighted_unifrac_%s.txt' % input_file_basename)

       # check for expected relations between values in the unweighted unifrac
        # distance matrix
        dm = parse_distmat_to_dict(open(unweighted_unifrac_dm_fp))
        self.assertTrue(dm['f1']['f2'] < dm['f1']['p1'],
                        "Distance between pair of fecal samples is larger than distance"
                        " between fecal and palm sample (unweighted unifrac).")
        self.assertEqual(dm['f1']['f1'], 0)
        # check for expected relations between values in the weighted unifrac
        # distance matrix
        dm = parse_distmat_to_dict(open(weighted_unifrac_dm_fp))
        self.assertTrue(dm['f1']['f2'] < dm['f1']['p1'],
                        "Distance between pair of fecal samples is larger than distance"
                        " between fecal and palm sample (unweighted unifrac).")
        self.assertEqual(dm['f1']['f1'], 0)

        # check that final output files have non-zero size
        self.assertTrue(getsize(weighted_unifrac_upgma_tree_fp) > 0)
        self.assertTrue(getsize(unweighted_unifrac_upgma_tree_fp) > 0)
        self.assertTrue(getsize(weighted_unifrac_emperor_index_fp) > 0)
        self.assertTrue(getsize(unweighted_unifrac_emperor_index_fp) > 0)

        # Check that the log file is created and has size > 0
        log_fp = glob(join(self.test_out, 'log*.txt'))[0]
        self.assertTrue(getsize(log_fp) > 0)
def main():
    option_parser, opts, args = \
        parse_command_line_parameters(**script_info)

    verbose = opts.verbose

    otu_table_fp = opts.otu_table_fp
    output_dir = opts.output_dir
    tree_fp = opts.tree_fp
    seqs_per_sample = opts.seqs_per_sample
    verbose = opts.verbose
    print_only = opts.print_only
    master_tree = opts.master_tree

    parallel = opts.parallel
    # No longer checking that jobs_to_start > 2, but
    # commenting as we may change our minds about this.
    #if parallel: raise_error_on_parallel_unavailable()

    if opts.parameter_fp:
        try:
            parameter_f = open(opts.parameter_fp, 'U')
        except IOError:
            raise IOError("Can't open parameters file (%s). Does it exist? Do you have read access?"
                          % opts.parameter_fp)
        params = parse_qiime_parameters(parameter_f)
        parameter_f.close()
    else:
        params = parse_qiime_parameters([])
        # empty list returns empty defaultdict for now

    jobs_to_start = opts.jobs_to_start
    default_jobs_to_start = qiime_config['jobs_to_start']
    validate_and_set_jobs_to_start(params,
                                   jobs_to_start,
                                   default_jobs_to_start,
                                   parallel,
                                   option_parser)

    try:
        makedirs(output_dir)
    except OSError:
        if opts.force:
            pass
        else:
            # Since the analysis can take quite a while, I put this check
            # in to help users avoid overwriting previous output.
            option_parser.error("Output directory already exists. Please choose"
                                " a different directory, or force overwrite with -f.")

    if print_only:
        command_handler = print_commands
    else:
        command_handler = call_commands_serially

    if verbose:
        status_update_callback = print_to_stdout
    else:
        status_update_callback = no_status_updates

    run_jackknifed_beta_diversity(otu_table_fp=otu_table_fp,
                                  tree_fp=tree_fp,
                                  seqs_per_sample=seqs_per_sample,
                                  output_dir=output_dir,
                                  command_handler=command_handler,
                                  params=params,
                                  qiime_config=qiime_config,
                                  mapping_fp=opts.mapping_fp,
                                  parallel=parallel,
                                  status_update_callback=status_update_callback,
                                  master_tree=master_tree)
Esempio n. 3
0
def main():
    option_parser, opts, args = \
        parse_command_line_parameters(**script_info)

    verbose = opts.verbose

    otu_table_fp = opts.otu_table_fp
    output_dir = opts.output_dir
    tree_fp = opts.tree_fp
    seqs_per_sample = opts.seqs_per_sample
    verbose = opts.verbose
    print_only = opts.print_only
    master_tree = opts.master_tree

    parallel = opts.parallel
    # No longer checking that jobs_to_start > 2, but
    # commenting as we may change our minds about this.
    #if parallel: raise_error_on_parallel_unavailable()

    if opts.parameter_fp:
        try:
            parameter_f = open(opts.parameter_fp, 'U')
        except IOError:
            raise IOError(
                "Can't open parameters file (%s). Does it exist? Do you have read access?"
                % opts.parameter_fp)
        params = parse_qiime_parameters(parameter_f)
        parameter_f.close()
    else:
        params = parse_qiime_parameters([])
        # empty list returns empty defaultdict for now

    jobs_to_start = opts.jobs_to_start
    default_jobs_to_start = qiime_config['jobs_to_start']
    validate_and_set_jobs_to_start(params, jobs_to_start,
                                   default_jobs_to_start, parallel,
                                   option_parser)

    try:
        makedirs(output_dir)
    except OSError:
        if opts.force:
            pass
        else:
            # Since the analysis can take quite a while, I put this check
            # in to help users avoid overwriting previous output.
            option_parser.error(
                "Output directory already exists. Please choose"
                " a different directory, or force overwrite with -f.")

    if print_only:
        command_handler = print_commands
    else:
        command_handler = call_commands_serially

    if verbose:
        status_update_callback = print_to_stdout
    else:
        status_update_callback = no_status_updates

    run_jackknifed_beta_diversity(
        otu_table_fp=otu_table_fp,
        tree_fp=tree_fp,
        seqs_per_sample=seqs_per_sample,
        output_dir=output_dir,
        command_handler=command_handler,
        params=params,
        qiime_config=qiime_config,
        mapping_fp=opts.mapping_fp,
        parallel=parallel,
        status_update_callback=status_update_callback,
        master_tree=master_tree)