Beispiel #1
0
    def result(data, taxon_names, tree, sample_names, one_sample_name,
               **kwargs):
        """ wraps the fast_unifrac fn to return just a matrix, in correct order

            sample_names: list of unique strings
        """
        envs = make_envs_dict(data, sample_names, taxon_names)
        try:
            unifrac_res = fast_unifrac_one_sample(one_sample_name,
                                                  tree,
                                                  envs,
                                                  weighted=weighted,
                                                  metric=metric,
                                                  **kwargs)
        except ValueError as e:
            if 'one_sample_name not found' in str(e):
                warnings.warn('unifrac had no information on sample ' +\
                    one_sample_name +\
                     ". Distances involving that sample aren't meaningful")
                unifrac_res = (numpy.array([0.0]), [one_sample_name]
                               )  # self only
            else:
                raise e
        dist_mtx = _reorder_unifrac_res_one_sample(unifrac_res, sample_names)
        return dist_mtx
Beispiel #2
0
    def result(data, taxon_names, tree, sample_names, one_sample_name,**kwargs):
        """ wraps the fast_unifrac fn to return just a matrix, in correct order

            sample_names: list of unique strings
        """
        envs = make_envs_dict(data, sample_names, taxon_names)
        unifrac_res = fast_unifrac_one_sample(one_sample_name,
            tree, envs, weighted=weighted, metric=metric,**kwargs)
        dist_mtx = _reorder_unifrac_res_one_sample(unifrac_res,
            sample_names)
        return dist_mtx
    def test_fast_unifrac_one_sample2(self):
        """fu one sam should match whole weighted unifrac result, for env 'B'"""
        # first get full unifrac matrix
        res = fast_unifrac(self.t, self.env_counts, weighted=True)
        dmtx, env_order = res['distance_matrix']
        dmtx_vec = dmtx[env_order.index('B')]
        dmtx_vec = dmtx_vec[argsort(env_order)]

        # then get one sample unifrac vector
        one_sam_dvec, one_sam_env_order = \
            fast_unifrac_one_sample('B', self.t, self.env_counts,weighted=True)
        one_sam_dvec = one_sam_dvec[argsort(one_sam_env_order)]
        self.assertFloatEqual(one_sam_dvec, dmtx_vec)
 def test_fast_unifrac_one_sample2(self):
     """fu one sam should match whole weighted unifrac result, for env 'B'"""
     # first get full unifrac matrix
     res = fast_unifrac(self.t, self.env_counts, weighted=True)
     dmtx, env_order =  res['distance_matrix']
     dmtx_vec = dmtx[env_order.index('B')]
     dmtx_vec = dmtx_vec[argsort(env_order)]
     
     # then get one sample unifrac vector
     one_sam_dvec, one_sam_env_order = \
         fast_unifrac_one_sample('B', self.t, self.env_counts,weighted=True)
     one_sam_dvec = one_sam_dvec[argsort(one_sam_env_order)]
     self.assertFloatEqual(one_sam_dvec, dmtx_vec)
Beispiel #5
0
    def result(data, taxon_names, tree, sample_names, one_sample_name):
        """ wraps the fast_unifrac fn to return just a matrix, in correct order

            sample_names: list of unique strings
        """
        envs = make_envs_dict(data, sample_names, taxon_names)
        unifrac_res = fast_unifrac_one_sample(one_sample_name,
                                              tree,
                                              envs,
                                              weighted=weighted,
                                              metric=metric)
        dist_mtx = _reorder_unifrac_res_one_sample(unifrac_res, sample_names)
        return dist_mtx
 def test_fast_unifrac_one_sample3(self):
     """fu one sam should match missing env unifrac result, for env 'B'"""
     # first get full unifrac matrix
     res = fast_unifrac(self.t, self.missing_env_counts, weighted=False)
     dmtx, env_order =  res['distance_matrix']
     dmtx_vec = dmtx[env_order.index('C')]
     dmtx_vec = dmtx_vec[argsort(env_order)]
     
     # then get one sample unifrac vector
     one_sam_dvec, one_sam_env_order = \
         fast_unifrac_one_sample('C', self.t, 
         self.missing_env_counts,weighted=False)
     one_sam_dvec = one_sam_dvec[argsort(one_sam_env_order)]
     self.assertFloatEqual(one_sam_dvec, dmtx_vec)
     
     # and should raise valueerror when 'B'
     self.assertRaises(ValueError, fast_unifrac_one_sample, 'B', self.t, 
         self.missing_env_counts,weighted=False)
Beispiel #7
0
    def result(data, taxon_names, tree, sample_names, one_sample_name,**kwargs):
        """ wraps the fast_unifrac fn to return just a matrix, in correct order

            sample_names: list of unique strings
        """
        envs = make_envs_dict(data, sample_names, taxon_names)
        try:
            unifrac_res = fast_unifrac_one_sample(one_sample_name,
                tree, envs, weighted=weighted, metric=metric,**kwargs)
        except ValueError as e:
            if 'one_sample_name not found' in str(e):
                warnings.warn('unifrac had no information on sample ' +\
                    one_sample_name +\
                     ". Distances involving that sample aren't meaningful")
                unifrac_res = (numpy.array([0.0]),[one_sample_name]) # self only
            else:
                raise e
        dist_mtx = _reorder_unifrac_res_one_sample(unifrac_res,
            sample_names)
        return dist_mtx
    def test_fast_unifrac_one_sample3(self):
        """fu one sam should match missing env unifrac result, for env 'B'"""
        # first get full unifrac matrix
        res = fast_unifrac(self.t, self.missing_env_counts, weighted=False)
        dmtx, env_order = res['distance_matrix']
        dmtx_vec = dmtx[env_order.index('C')]
        dmtx_vec = dmtx_vec[argsort(env_order)]

        # then get one sample unifrac vector
        one_sam_dvec, one_sam_env_order = \
            fast_unifrac_one_sample('C', self.t,
            self.missing_env_counts,weighted=False)
        one_sam_dvec = one_sam_dvec[argsort(one_sam_env_order)]
        self.assertFloatEqual(one_sam_dvec, dmtx_vec)

        # and should raise valueerror when 'B'
        self.assertRaises(ValueError,
                          fast_unifrac_one_sample,
                          'B',
                          self.t,
                          self.missing_env_counts,
                          weighted=False)