Esempio n. 1
0
    def make_network(self, algo = 'crude', **kwargs):
        '''
        '''
        import SurveyStructures.OTUnetwork as ONet
        n, k       = self.shape
        row_labels = kwargs.get('row_labels', range(k))
        col_labels = kwargs.get('col_labels', range(n))
        
        md = self.to_Surveymat(**kwargs)
        if   algo == 'crude':   mat,pval = (md.log10()).correlation(type = 'pearsonr')
        elif algo in set(['sparse', 'csi', 'clr']):   
            v_sparse, c_sparse, Cov_sparse = self.basis_corr(method = algo,**kwargs)
            mat   = MatrixDictionary()
            mat.from_matrix(c_sparse, row_labels, row_labels)
            pval = mat
        elif algo == 'basis':
            md     = Survey_matrix()
            n, k   = self.shape
            mat    = np.log(self.basis)
            md.from_matrix(mat.transpose(), row_labels, col_labels)
            mat,pval = md.correlation(type = 'pearsonr')
        elif algo in set(['pearsonr','kendalltau','spearmanr']):
            abunds = self.to_Surveymat()
            mat,pval = abunds.correlation(type = algo)

                
        ## make network
        if algo == 'MI': net = ONet.OTUnetwork(  abunds = abunds, lineages = lineages, matrix = mat.to_PairMatrix(), p_vals = {'direct':None}, algo = 'MI', lag = 0)
        else:  net = ONet.OTUnetwork(node_ids = mat.row_labels(), matrix = mat, p_vals = {'direct':pval}, algo = algo, lag = 0)
        return net
Esempio n. 2
0
    def make_network(self, algo='crude', **kwargs):
        '''
        '''
        import SurveyStructures.OTUnetwork as ONet
        n, k = self.shape
        row_labels = kwargs.get('row_labels', range(k))
        col_labels = kwargs.get('col_labels', range(n))

        md = self.to_Surveymat(**kwargs)
        if algo == 'crude':
            mat, pval = (md.log10()).correlation(type='pearsonr')
        elif algo in set(['sparse', 'csi', 'clr']):
            v_sparse, c_sparse, Cov_sparse = self.basis_corr(method=algo,
                                                             **kwargs)
            mat = MatrixDictionary()
            mat.from_matrix(c_sparse, row_labels, row_labels)
            pval = mat
        elif algo == 'basis':
            md = Survey_matrix()
            n, k = self.shape
            mat = np.log(self.basis)
            md.from_matrix(mat.transpose(), row_labels, col_labels)
            mat, pval = md.correlation(type='pearsonr')
        elif algo in set(['pearsonr', 'kendalltau', 'spearmanr']):
            abunds = self.to_Surveymat()
            mat, pval = abunds.correlation(type=algo)

        ## make network
        if algo == 'MI':
            net = ONet.OTUnetwork(abunds=abunds,
                                  lineages=lineages,
                                  matrix=mat.to_PairMatrix(),
                                  p_vals={'direct': None},
                                  algo='MI',
                                  lag=0)
        else:
            net = ONet.OTUnetwork(node_ids=mat.row_labels(),
                                  matrix=mat,
                                  p_vals={'direct': pval},
                                  algo=algo,
                                  lag=0)
        return net
Esempio n. 3
0
def test_independent_betabinom(): 
    n = 5
    m = 50
    mat = np.floor(100*np.random.rand(n,m))
    mat[1,:] = 100-mat[0,:]
    row_labels = range(n)
    col_labels = range(m)
    data = Survey_matrix()
    data.from_matrix(mat, row_labels, col_labels)
    c,p = data.correlation(type = 'pearsonr')
    print c.to_matrix()
    print p.to_matrix()
    sim = independent_betabinom(data)
    c_sim, p = sim.correlation(type = 'pearsonr')
    print c_sim.to_matrix()
    print p.to_matrix()
    sim_norm = sim.normalize(rows = False)
    c_sim_norm, p = sim_norm.correlation(type = 'pearsonr')
    print c_sim_norm.to_matrix()
    print p.to_matrix()
Esempio n. 4
0
def test_independent_betabinom():
    n = 5
    m = 50
    mat = np.floor(100 * np.random.rand(n, m))
    mat[1, :] = 100 - mat[0, :]
    row_labels = range(n)
    col_labels = range(m)
    data = Survey_matrix()
    data.from_matrix(mat, row_labels, col_labels)
    c, p = data.correlation(type='pearsonr')
    print c.to_matrix()
    print p.to_matrix()
    sim = independent_betabinom(data)
    c_sim, p = sim.correlation(type='pearsonr')
    print c_sim.to_matrix()
    print p.to_matrix()
    sim_norm = sim.normalize(rows=False)
    c_sim_norm, p = sim_norm.correlation(type='pearsonr')
    print c_sim_norm.to_matrix()
    print p.to_matrix()