def test_run_trajectory_analysis_wdiff(self):
     """Correctly computes the window difference method"""
     obs = run_trajectory_analysis(self.ord_res, self.metadata_map,
                                   trajectory_categories=self.categories,
                                   sort_category=self.sort_by,
                                   algorithm='wdiff', window_size=3)
     exp_control_group = GroupResults('Control', np.array([-2.5790341819,
                                                           -2.0166764661,
                                                           -3.0360721941,
                                                           0.]),
                                      -1.9079457105,
                                      {'mean': -1.9079457105,
                                       'std': 1.1592139913}, None)
     exp_fast_group = GroupResults('Fast', np.array([11.2291654905,
                                                     3.9163741156,
                                                     4.4943507388]),
                                   6.5466301150,
                                   {'mean': 6.5466301150,
                                    'std': 3.3194494926},
                                   "Cannot calculate the first difference "
                                   "with a window of size (3).")
     exp_treatment = CategoryResults('Treatment', 0.0103976830,
                                     [exp_control_group, exp_fast_group],
                                     None)
     exp = GradientANOVAResults('wdiff', False, [exp_treatment])
     self.assert_gradientANOVA_results_almost_equal(obs, exp)
 def test_run_trajectory_analysis_trajectory(self):
     """Correctly computes the trajectory method"""
     obs = run_trajectory_analysis(self.ord_res,
                                   self.metadata_map,
                                   trajectory_categories=self.categories,
                                   sort_category=self.sort_by,
                                   algorithm='trajectory')
     exp_control_group = GroupResults(
         'Control',
         np.array([8.6681963576, 7.0962717982, 7.1036434615, 4.0675712674]),
         6.73392072123, {'2-norm': 13.874494152}, None)
     exp_fast_group = GroupResults(
         'Fast', np.array([11.2291654905, 3.9163741156, 4.4943507388]),
         6.5466301150, {'2-norm': 12.713431181}, None)
     exp_treatment = CategoryResults('Treatment', 0.9374500147,
                                     [exp_control_group, exp_fast_group],
                                     None)
     exp = GradientANOVAResults('trajectory', False, [exp_treatment])
     self.assert_gradientANOVA_results_almost_equal(obs, exp)
 def test_run_trajectory_analysis_diff(self):
     """Correctly computes the first difference method"""
     obs = run_trajectory_analysis(self.ord_res, self.metadata_map,
                                   trajectory_categories=self.categories,
                                   sort_category=self.sort_by,
                                   algorithm='diff')
     exp_control_group = GroupResults('Control', np.array([-1.5719245594,
                                                           0.0073716633,
                                                           -3.0360721941]),
                                      -1.5335416967,
                                      {'mean': -1.5335416967,
                                       'std': 1.2427771485}, None)
     exp_fast_group = GroupResults('Fast', np.array([-7.3127913749,
                                                     0.5779766231]),
                                   -3.3674073758,
                                   {'mean': -3.3674073758,
                                    'std': 3.9453839990}, None)
     exp_treatment = CategoryResults('Treatment', 0.6015260608,
                                     [exp_control_group, exp_fast_group],
                                     None)
     exp = GradientANOVAResults('diff', False, [exp_treatment])
     self.assert_gradientANOVA_results_almost_equal(obs, exp)
 def test_run_trajectory_analysis_trajectory(self):
     """Correctly computes the trajectory method"""
     obs = run_trajectory_analysis(self.ord_res, self.metadata_map,
                                   trajectory_categories=self.categories,
                                   sort_category=self.sort_by,
                                   algorithm='trajectory')
     exp_control_group = GroupResults('Control', np.array([8.6681963576,
                                                           7.0962717982,
                                                           7.1036434615,
                                                           4.0675712674]),
                                      6.73392072123,
                                      {'2-norm': 13.874494152}, None)
     exp_fast_group = GroupResults('Fast', np.array([11.2291654905,
                                                     3.9163741156,
                                                     4.4943507388]),
                                   6.5466301150,
                                   {'2-norm': 12.713431181}, None)
     exp_treatment = CategoryResults('Treatment', 0.9374500147,
                                     [exp_control_group, exp_fast_group],
                                     None)
     exp = GradientANOVAResults('trajectory', False, [exp_treatment])
     self.assert_gradientANOVA_results_almost_equal(obs, exp)
 def test_run_trajectory_analysis_avg(self):
     """Correctly computes the avg method"""
     obs = run_trajectory_analysis(self.ord_res,
                                   self.metadata_map,
                                   trajectory_categories=self.categories)
     exp_control_group = GroupResults(
         'Control',
         np.array([
             2.3694943596755276, 3.3716388181385781, 5.4452089176253367,
             4.5704258453173559, 4.4972603724478377
         ]), 4.05080566264, {'avg': 4.0508056626409275}, None)
     exp_fast_group = GroupResults(
         'Fast',
         np.array([
             7.2220488239279126, 4.2726021564374372, 1.1169097274372082,
             4.02717600030876
         ]), 4.15968417703, {'avg': 4.1596841770278292}, None)
     exp_treatment = CategoryResults('Treatment', 0.93311555,
                                     [exp_control_group, exp_fast_group],
                                     None)
     exp = GradientANOVAResults('avg', False, [exp_treatment])
     self.assert_gradientANOVA_results_almost_equal(obs, exp)
Example #6
0
 def test_run_trajectory_analysis_diff(self):
     """Correctly computes the first difference method"""
     obs = run_trajectory_analysis(self.ord_res, self.metadata_map,
                                   trajectory_categories=self.categories,
                                   sort_category=self.sort_by,
                                   algorithm='diff')
     exp_control_group = GroupResults('Control', np.array([-1.5719245594,
                                                           0.0073716633,
                                                           -3.0360721941]),
                                      -1.5335416967,
                                      {'mean': -1.5335416967,
                                       'std': 1.2427771485}, None)
     exp_fast_group = GroupResults('Fast', np.array([-7.3127913749,
                                                     0.5779766231]),
                                   -3.3674073758,
                                   {'mean': -3.3674073758,
                                    'std': 3.9453839990}, None)
     exp_treatment = CategoryResults('Treatment', 0.6015260608,
                                     [exp_control_group, exp_fast_group],
                                     None)
     exp = GradientANOVAResults('diff', False, [exp_treatment])
     self.assert_gradientANOVA_results_almost_equal(obs, exp)
 def test_run_trajectory_analysis_avg(self):
     """Correctly computes the avg method"""
     obs = run_trajectory_analysis(self.ord_res, self.metadata_map,
                                   trajectory_categories=self.categories)
     exp_control_group = GroupResults('Control',
                                      np.array([2.3694943596755276,
                                                3.3716388181385781,
                                                5.4452089176253367,
                                                4.5704258453173559,
                                                4.4972603724478377]),
                                      4.05080566264,
                                      {'avg': 4.0508056626409275}, None)
     exp_fast_group = GroupResults('Fast', np.array([7.2220488239279126,
                                                     4.2726021564374372,
                                                     1.1169097274372082,
                                                     4.02717600030876]),
                                   4.15968417703,
                                   {'avg': 4.1596841770278292}, None)
     exp_treatment = CategoryResults('Treatment', 0.93311555,
                                     [exp_control_group, exp_fast_group],
                                     None)
     exp = GradientANOVAResults('avg', False, [exp_treatment])
     self.assert_gradientANOVA_results_almost_equal(obs, exp)
    if weighted:
        if sort_by == 'SampleID':
            option_parser.error("The weighting_vector can't be the SampleID, "
                                "please specify a numeric column in the "
                                "--sort_by option.")
        elif not sort_category:
            option_parser.error("To weight the output, provide a metadata "
                                "category using the --sort_by option")

    if algorithm == 'wdiff':
        if not window_size:
            option_parser.error("You should provide --window_size when using "
                                "the wdiff algorithm")
        if window_size < 1:
            option_parser.error("--window_size should be a positive integer, "
                                "%d found" % window_size)

    res = run_trajectory_analysis(ord_res, metamap, categories,
                                  sort_category, algorithm, axes,
                                  weighted, window_size)

    if not exists(output_dir):
        mkdir(output_dir)

    trajectories_fp = join(output_dir, 'trajectories.txt')
    trajectories_raw_fp = join(output_dir, 'trajectories_raw_values.txt')

    with open(trajectories_fp, 'w') as out_f:
        with open(trajectories_raw_fp, 'w') as raw_f:
            res.to_files(out_f, raw_f)
 def test_run_trajectory_analysis_error(self):
     """Raises an error if the algorithm is not recognized"""
     with self.assertRaises(ValueError):
         run_trajectory_analysis(self.ord_res, self.metadata_map,
                                 algorithm='foo')
Example #10
0
    if weighted:
        if sort_by == 'SampleID':
            option_parser.error("The weighting_vector can't be the SampleID, "
                                "please specify a numeric column in the "
                                "--sort_by option.")
        elif not sort_category:
            option_parser.error("To weight the output, provide a metadata "
                                "category using the --sort_by option")

    if algorithm == 'wdiff':
        if not window_size:
            option_parser.error("You should provide --window_size when using "
                                "the wdiff algorithm")
        if window_size < 1:
            option_parser.error("--window_size should be a positive integer, "
                                "%d found" % window_size)

    res = run_trajectory_analysis(ord_res, metamap, categories, sort_category,
                                  algorithm, axes, weighted, window_size)

    if not exists(output_dir):
        mkdir(output_dir)

    trajectories_fp = join(output_dir, 'trajectories.txt')
    trajectories_raw_fp = join(output_dir, 'trajectories_raw_values.txt')

    with open(trajectories_fp, 'w') as out_f:
        with open(trajectories_raw_fp, 'w') as raw_f:
            res.to_files(out_f, raw_f)
 def test_run_trajectory_analysis_error(self):
     """Raises an error if the algorithm is not recognized"""
     with self.assertRaises(ValueError):
         run_trajectory_analysis(self.ord_res,
                                 self.metadata_map,
                                 algorithm='foo')