예제 #1
0
    def test_confirm_betadispr_results(self):
        mp_dm = DistanceMatrix.read(get_data_path('moving_pictures_dm.tsv'))
        mp_mf = pd.read_csv(get_data_path('moving_pictures_mf.tsv'), sep='\t')
        mp_mf.set_index('#SampleID', inplace=True)

        obs_med_mp = permdisp(mp_dm, mp_mf,
                              column='BodySite')
        obs_cen_mp = permdisp(mp_dm, mp_mf, column='BodySite',
                              test='centroid')

        exp_data_m = ['PERMDISP', 'F-value', 33, 4, 10.1956, 0.001, 999]
        exp_data_c = ['PERMDISP', 'F-value', 33, 4, 17.4242, 0.001, 999]
        exp_ind = ['method name', 'test statistic name', 'sample size',
                   'number of groups', 'test statistic', 'p-value',
                   'number of permutations']

        exp_med_mp = pd.Series(data=exp_data_m, index=exp_ind, dtype='object',
                               name='PERMDISP results')

        exp_cen_mp = pd.Series(data=exp_data_c, index=exp_ind, dtype='object',
                               name='PERMDISP results')

        self.assert_series_equal(exp_med_mp, obs_med_mp)

        self.assert_series_equal(exp_cen_mp, obs_cen_mp)
예제 #2
0
    def test_confirm_betadispr_results(self):
        mp_dm = DistanceMatrix.read(get_data_path('moving_pictures_dm.tsv'))
        mp_mf = pd.read_csv(get_data_path('moving_pictures_mf.tsv'), sep='\t')
        mp_mf.set_index('#SampleID', inplace=True)

        obs_med_mp = permdisp(mp_dm, mp_mf,
                              column='BodySite')
        obs_cen_mp = permdisp(mp_dm, mp_mf, column='BodySite',
                              test='centroid')

        exp_data_m = ['PERMDISP', 'F-value', 33, 4, 10.1956, 0.001, 999]
        exp_data_c = ['PERMDISP', 'F-value', 33, 4, 17.4242, 0.001, 999]
        exp_ind = ['method name', 'test statistic name', 'sample size',
                   'number of groups', 'test statistic', 'p-value',
                   'number of permutations']

        exp_med_mp = pd.Series(data=exp_data_m, index=exp_ind, dtype='object',
                               name='PERMDISP results')

        exp_cen_mp = pd.Series(data=exp_data_c, index=exp_ind, dtype='object',
                               name='PERMDISP results')

        self.assert_series_equal(exp_med_mp, obs_med_mp)

        self.assert_series_equal(exp_cen_mp, obs_cen_mp)
예제 #3
0
 def permanova_permdisp(self):
     # compute the permanova
     print('running permdisp\n\n')
     print(permdisp(distance_matrix=DistanceMatrix(self.dist_df),
                    grouping=[_.split('_')[0] for _ in list(self.dist_df)], permutations=999))
     print('running permanova\n\n')
     print(permanova(distance_matrix=DistanceMatrix(self.dist_df),
                     grouping=[_.split('_')[0] for _ in list(self.dist_df)], permutations=9999))
예제 #4
0
    def test_median_fsvd(self):

        exp = pd.Series(index=self.exp_index,
                        data=['PERMDISP', 'F-value', 9, 2, 0.04078077215673714,
                              0.8, 99],
                        name='PERMDISP results')

        np.random.seed(0)
        obs = permdisp(self.unifrac_dm, self.unif_grouping, test='median',
                       permutations=99,
                       method='fsvd', number_of_dimensions=3)

        self.assert_series_equal(obs, exp)

        np.random.seed(0)
        po = pcoa(self.unifrac_dm, method='fsvd', number_of_dimensions=3)
        obs = permdisp(po, self.unif_grouping, test='median',
                       permutations=99)

        self.assert_series_equal(obs, exp)
예제 #5
0
    def test_median_normal(self):

        exp = pd.Series(index=self.exp_index,
                        data=['PERMDISP', 'F-value', 9, 2, 0.139475441876,
                              0.61, 99],
                        name='PERMDISP results')

        np.random.seed(0)
        obs = permdisp(self.unifrac_dm, self.unif_grouping, test='median',
                       permutations=99)

        self.assert_series_equal(obs, exp)

        np.random.seed(0)
        po = pcoa(self.unifrac_dm)

        obs2 = permdisp(po, self.unif_grouping, test='median',
                        permutations=99)

        self.assert_series_equal(obs2, exp)
예제 #6
0
    def test_median_normal(self):

        exp = pd.Series(index=self.exp_index,
                        data=['PERMDISP', 'F-value', 9, 2, 0.139475441876,
                              0.61, 99],
                        name='PERMDISP results')

        np.random.seed(0)
        obs = permdisp(self.unifrac_dm, self.unif_grouping, test='median',
                       permutations=99)

        self.assert_series_equal(obs, exp)
예제 #7
0
    def test_centroid_normal(self):
        exp = pd.Series(index=self.exp_index,
                        data=['PERMDISP', 'F-value', 9, 2, 0.244501519876,
                              0.63, 99],
                        name='PERMDISP results')

        grouping = ['Control', 'Control', 'Control', 'Control', 'Control',
                    'Fast', 'Fast', 'Fast', 'Fast']

        np.random.seed(0)
        obs = permdisp(self.unifrac_dm, grouping, test='centroid',
                       permutations=99)

        self.assert_series_equal(obs, exp)
예제 #8
0
    def test_centroid_normal(self):
        exp = pd.Series(index=self.exp_index,
                        data=['PERMDISP', 'F-value', 9, 2, 0.244501519876,
                              0.63, 99],
                        name='PERMDISP results')

        grouping = ['Control', 'Control', 'Control', 'Control', 'Control',
                    'Fast', 'Fast', 'Fast', 'Fast']

        np.random.seed(0)
        obs = permdisp(self.unifrac_dm, grouping, test='centroid',
                       permutations=99)

        self.assert_series_equal(obs, exp)
예제 #9
0
    def test_no_permuations(self):
        obs = permdisp(self.eq_mat, self.grouping_eq, permutations=0)

        pval = obs['p-value']
        np.isnan(pval)
예제 #10
0
for a in range(len(rows[0])):
    if a > 0:
        this_sample = []
        for b in range(len(rows)):
            if b > 0:
                this_sample.append(float(rows[b][a]))
        samples.append(this_sample)
"""
only_samples = ['LR', 'SR']
new_samples, new_names = [], []
for a in range(len(sample_names)):
    for b in range(len(only_samples)):
        if sample_names[a] == only_samples[b]:
            new_samples.append(samples[a])
            new_names.append(sample_names[a])
samples = new_samples
sample_names = new_names
print(len(samples), len(sample_names))
"""

sam_dm = dm.from_iterable(samples, metric=braycurtis)
pdisp = permdisp(sam_dm,
                 sample_names,
                 column=None,
                 test='median',
                 permutations=999)
print(pdisp)
asim = anosim(sam_dm, sample_names, column=None, permutations=999)
print(asim)
perm = permanova(sam_dm, sample_names, column=None, permutations=999)
print(perm)
예제 #11
0
    def test_no_permuations(self):
        obs = permdisp(self.eq_mat, self.grouping_eq, permutations=0)

        pval = obs['p-value']
        np.isnan(pval)