Beispiel #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
Beispiel #2
0
    def basis_corr(self, algo='SparCC', **kwargs):
        '''
        '''
        import basis_correlations as basecor
        counts_t, otus, samples = self.to_matrix()
        counts = counts_t.transpose()
        cor_med, cov_med = basecor.main(counts, algo=algo, **kwargs)
        cor = MatrixDictionary()

        cor.from_matrix(cor_med, otus, otus)
        if cov_med is None:
            cov = None
        else:
            cov = MatrixDictionary()
            cov.from_matrix(cov_med, otus, otus)
        return cor, cov
Beispiel #3
0
 def basis_corr(self, algo='SparCC', **kwargs):
     '''
     '''
     import basis_correlations as basecor 
     counts_t, otus, samples = self.to_matrix()
     counts = counts_t.transpose()
     cor_med, cov_med = basecor.main(counts, algo=algo, **kwargs)
     cor  = MatrixDictionary()
     
     cor.from_matrix(cor_med, otus, otus)
     if cov_med is None:
         cov = None
     else:
         cov  = MatrixDictionary()
         cov.from_matrix(cov_med, otus, otus)  
     return cor, cov
Beispiel #4
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