def main():
    option_parser, opts, args = parse_command_line_parameters(**script_info)

    if not os.path.exists(opts.output_path):
        os.makedirs(opts.output_path)
    maker = RarefactionMaker(opts.input_path, opts.depth, opts.depth, 1, opts.num_reps)
    maker.rarefy_to_files(
        opts.output_path, False, include_lineages=opts.lineages_included, empty_otus_removed=(not opts.keep_empty_otus)
    )
def main():
    option_parser, opts, args = parse_command_line_parameters(**script_info)

    if not os.path.exists(opts.output_path):
        os.makedirs(opts.output_path)
    maker = RarefactionMaker(opts.input_path, opts.depth, opts.depth,
                             1, opts.num_reps)
    maker.rarefy_to_files(opts.output_path, False,
                          include_lineages=opts.lineages_included,
                          empty_otus_removed=(not opts.keep_empty_otus))
def main():
    option_parser, opts, args = parse_command_line_parameters(**script_info)

    if opts.step <= 0:
        option_parser.error("nonpositive step not allowed (%s was supplied)" % \
          (opts.step,))
    create_dir(opts.output_path, fail_on_exist=False)
    maker = RarefactionMaker(opts.input_path, opts.min, opts.max,
        opts.step, opts.num_reps)
    maker.rarefy_to_files(opts.output_path, False,
        include_lineages=opts.lineages_included,
        empty_otus_removed=(not opts.keep_empty_otus))
Пример #4
0
 def test_rarefy_to_list(self):
     """rarefy_to_list should rarefy correctly, same names, rm empty samples
     
     """
     maker = RarefactionMaker(self.otu_tuple, 0, 1, 1, 1)
     res = maker.rarefy_to_list(include_full=True)
     self.assertFloatEqual(res[-1][2], self.sample_names)
     self.assertFloatEqual(res[-1][3], self.taxon_names)
     self.assertFloatEqual(res[-1][4], self.otu_table_transpose.T)
     
     # each sample should have 1 seq, sample z should be removed
     self.assertFloatEqual((res[1][4]).sum(0),[1.0,1.0] )
Пример #5
0
    def test_rarefy_to_files(self):
        """rarefy_to_files should write valid files
        
        """
        maker = RarefactionMaker(self.otu_table_fp, 0, 1, 1, 1)
        maker.rarefy_to_files(self.rare_dir,include_full=True,include_lineages=False)

        fname = os.path.join(self.rare_dir,"rarefaction_1_0.biom")
        otu_table = parse_biom_table(open(fname,'U'))

        self.assertFloatEqual(otu_table.SampleIds, self.otu_table.SampleIds[:2])
        # third sample had 0 seqs, so it's gone
        self.assertFloatEqual(otu_table.ObservationIds, self.otu_table.ObservationIds)
Пример #6
0
    def test_rarefy_to_files(self):
        """rarefy_to_files should write valid files

        """
        maker = RarefactionMaker(self.otu_table_fp, 1, 2, 1, 1)
        maker.rarefy_to_files(self.rare_dir,
                              include_full=True,
                              include_lineages=False)

        fname = os.path.join(self.rare_dir, "rarefaction_1_0.biom")
        otu_table = load_table(fname)

        self.assertItemsEqual(otu_table.ids(), self.otu_table.ids()[:2])
Пример #7
0
    def test_rarefy_to_list(self):
        """rarefy_to_list should rarefy correctly, same names
        
        """
        maker = RarefactionMaker(self.otu_table_fp, 0, 1, 1, 1)
        res = maker.rarefy_to_list(include_full=True)
        self.assertFloatEqual(res[-1][2].SampleIds, self.otu_table.SampleIds)
        self.assertFloatEqual(res[-1][2].ObservationIds, self.otu_table.ObservationIds)
        self.assertEqual(res[-1][2], self.otu_table)

        sample_value_sum = []
        for val in res[1][2].iterSampleData():
            sample_value_sum.append(val.sum())
        self.assertFloatEqual(sample_value_sum, [1.0, 1.0])
Пример #8
0
    def test_rarefy_to_files2(self):
        """rarefy_to_files should write valid files with some metadata on otus

        """
        maker = RarefactionMaker(self.otu_table_meta_fp, 0, 1, 1, 1)
        maker.rarefy_to_files(self.rare_dir,
                              include_full=True,
                              include_lineages=False)

        fname = os.path.join(self.rare_dir, "rarefaction_1_0.biom")
        with biom_open(fname, 'U') as biom_file:
            otu_table = Table.from_hdf5(biom_file)

        self.assertItemsEqual(otu_table.ids(), self.otu_table.ids()[:2])
Пример #9
0
    def test_rarefy_to_list(self):
        """rarefy_to_list should rarefy correctly, same names

        """
        maker = RarefactionMaker(self.otu_table_fp, 0, 1, 1, 1)
        res = maker.rarefy_to_list(include_full=True)
        self.assertItemsEqual(res[-1][2].SampleIds, self.otu_table.SampleIds)
        self.assertItemsEqual(res[-1][2].ObservationIds,
                              self.otu_table.ObservationIds)
        self.assertEqual(res[-1][2], self.otu_table)

        sample_value_sum = []
        for val in res[1][2].iterSampleData():
            sample_value_sum.append(val.sum())
        assert_almost_equal(sample_value_sum, [1.0, 1.0])
Пример #10
0
    def test_rarefy_to_list(self):
        """rarefy_to_list should rarefy correctly, same names

        """
        maker = RarefactionMaker(self.otu_table_fp, 0, 1, 1, 1)
        res = maker.rarefy_to_list(include_full=True)
        self.assertItemsEqual(res[-1][2].ids(), self.otu_table.ids())
        self.assertItemsEqual(res[-1][2].ids(axis='observation'),
                              self.otu_table.ids(axis='observation'))
        self.assertEqual(res[-1][2], self.otu_table)

        sample_value_sum = []
        for val in res[1][2].iter_data(axis='sample'):
            sample_value_sum.append(val.sum())
        npt.assert_almost_equal(sample_value_sum, [1.0, 1.0])
Пример #11
0
    def test_rarefy_to_files(self):
        """rarefy_to_files should write valid files

        """
        maker = RarefactionMaker(self.otu_table_fp, 1, 2, 1, 1)
        maker.rarefy_to_files(
            self.rare_dir,
            include_full=True,
            include_lineages=False)

        fname = os.path.join(self.rare_dir, "rarefaction_1_0.biom")
        otu_table = load_table(fname)

        self.assertItemsEqual(
            otu_table.ids(),
            self.otu_table.ids()[:2])
Пример #12
0
    def test_rarefy_to_list(self):
        """rarefy_to_list should rarefy correctly, same names

        """
        maker = RarefactionMaker(self.otu_table_fp, 0, 1, 1, 1)
        res = maker.rarefy_to_list(include_full=True)
        self.assertItemsEqual(res[-1][2].ids(), self.otu_table.ids())
        self.assertItemsEqual(
            res[-1][2].ids(axis='observation'),
            self.otu_table.ids(axis='observation'))
        self.assertEqual(res[-1][2], self.otu_table)

        sample_value_sum = []
        for val in res[1][2].iter_data(axis='sample'):
            sample_value_sum.append(val.sum())
        npt.assert_almost_equal(sample_value_sum, [1.0, 1.0])
Пример #13
0
    def test_rarefy_to_files2(self):
        """rarefy_to_files should write valid files with some metadata on otus

        """
        maker = RarefactionMaker(self.otu_table_meta_fp, 0, 1, 1, 1)
        maker.rarefy_to_files(self.rare_dir,
                              include_full=True,
                              include_lineages=False)

        fname = os.path.join(self.rare_dir, "rarefaction_1_0.biom")
        otu_table = parse_biom_table(open(fname, 'U'))

        self.assertItemsEqual(otu_table.SampleIds,
                              self.otu_table.SampleIds[:2])
        # third sample had 0 seqs, so it's gone
        self.assertItemsEqual(otu_table.ObservationIds,
                              self.otu_table.ObservationIds)
Пример #14
0
    def test_rarefy_to_files(self):
        """rarefy_to_files should write valid files

        """
        maker = RarefactionMaker(self.otu_table_fp, 0, 1, 1, 1)
        maker.rarefy_to_files(
            self.rare_dir,
            include_full=True,
            include_lineages=False)

        fname = os.path.join(self.rare_dir, "rarefaction_1_0.biom")
        with biom_open(fname, 'U') as biom_file:
            otu_table = Table.from_hdf5(biom_file)

        self.assertItemsEqual(
            otu_table.sample_ids,
            self.otu_table.sample_ids[:2])
def main():
    option_parser, opts, args = parse_command_line_parameters(**script_info)

    if opts.step <= 0:
        option_parser.error("step must be greater than 0")

    create_dir(opts.output_path, fail_on_exist=False)
    maker = RarefactionMaker(opts.input_path, opts.min, opts.max,
                             opts.step, opts.num_reps)

    if opts.subsample_multinomial:
        subsample_f = partial(subsample, replace=True)
    else:
        subsample_f = subsample

    maker.rarefy_to_files(opts.output_path,
                          False,
                          include_lineages=opts.lineages_included,
                          empty_otus_removed=(not opts.keep_empty_otus),
                          subsample_f=subsample_f)
Пример #16
0
def main():
    option_parser, opts, args = parse_command_line_parameters(**script_info)

    if opts.step <= 0:
        option_parser.error("nonpositive step not allowed (%s was supplied)" %
                            (opts.step, ))
    create_dir(opts.output_path, fail_on_exist=False)
    maker = RarefactionMaker(opts.input_path, opts.min, opts.max, opts.step,
                             opts.num_reps)

    if opts.subsample_multinomial:
        subsample_f = partial(subsample, replace=True)
    else:
        subsample_f = subsample

    maker.rarefy_to_files(opts.output_path,
                          False,
                          include_lineages=opts.lineages_included,
                          empty_otus_removed=(not opts.keep_empty_otus),
                          subsample_f=subsample_f)
Пример #17
0
def get_rarefactions(biom_object, minimum, maximum, iterations, steps):
    """rarify biom object and return rarefactions

	Inputs:
	biom_object: object to rarefy
	minimum: starting point for the rarefactions
	maximum: ending point for the rarefactions
	iterations: repetitions per rarefaction depth
	steps: number of levels between minimum and maximum

	Outputs:
	list of 3 element tuples, where each tuple contains as a 1st element the
	rarefaction depth, as a 2nd element the iteration number and as a 3rd
	element the rarefied biom corresponding to this depth
	"""

    rarefaction_step_size = int((maximum - minimum) / steps)

    rarefaction_maker = RarefactionMaker(biom_object, minimum,  maximum,\
     rarefaction_step_size, iterations)
    rarefactions = rarefaction_maker.rarefy_to_list()

    return rarefactions
Пример #18
0
def get_rarefactions(biom_object, minimum, maximum, iterations, steps):
	"""rarify biom object and return rarefactions

	Inputs:
	biom_object: object to rarefy
	minimum: starting point for the rarefactions
	maximum: ending point for the rarefactions
	iterations: repetitions per rarefaction depth
	steps: number of levels between minimum and maximum

	Outputs:
	list of 3 element tuples, where each tuple contains as a 1st element the
	rarefaction depth, as a 2nd element the iteration number and as a 3rd
	element the rarefied biom corresponding to this depth
	"""

	rarefaction_step_size = int((maximum - minimum)/steps)

	rarefaction_maker = RarefactionMaker(biom_object, minimum,  maximum,\
		rarefaction_step_size, iterations)
	rarefactions = rarefaction_maker.rarefy_to_list()

	return rarefactions