コード例 #1
0
    def bayes_major(self):
        self = pickle.load(
            open(
                "/%s/%s_self_fitting.p" %
                (self.output_directory, self.output_prefix), 'rb'))
        logging.info('Run the algorithm for the second time ...')
        ngene = 0
        for (tgid, tginst) in self.allgenedict.iteritems():
            #logging.info(tgid)
            iteratenbem(tginst,
                        debug=False,
                        meanvarmodel=self.mrm,
                        restart=False,
                        size_factor=self.size_f,
                        beta1_prior_var=self.non_PPI_beta_prior_variance)
            ngene += 1

        for (tgid, tginst) in self.allgenedict.iteritems():
            if len(tginst.w_estimate) == 0:
                tginst.w_estimate = np.ones(len(tginst.sgrnaid))

        pickle.dump(
            self,
            open(
                "/%s/%s_self_bayes_major.p" %
                (self.output_directory, self.output_prefix), 'wb'))
コード例 #2
0
ファイル: mlemageck_bayes.py プロジェクト: yarker/MAGeCK_Repo
    def bayes_iteration(self):
        logging.info('Iteratioin...')
        PPI_choice=[False,True]

        for PPI in PPI_choice:
            self=pickle.load(open("/%s/%s_self_constant_optimization.p" %(self.output_directory,self.output_prefix),'rb'))
            self.PPI_prior=PPI
            if self.PPI_diagnosis==False and self.PPI_prior==True:
                pass
            else:
                self.outliers_removal=False
                for (tgid,tginst) in self.allgenedict.iteritems():
                    iteratenbem(tginst,debug=False,meanvarmodel=self.mrm,restart=False,PPI_prior=self.PPI_prior,removeoutliers=self.outliers_removal,size_factor=self.size_f,beta1_prior_var=self.non_PPI_beta_prior_variance)
                pickle.dump(self,open("/%s/%s_self_bayes_iteration_PPI_%s_outliers_removal_%s.p" %(self.output_directory,self.output_prefix,self.PPI_prior,self.outliers_removal),'wb'))

                #base_index=np.where(~self.design_matrix[:,1:].any(axis=1))[0]
                #transform_list=[1 if i in base_index else -1 for i in range(self.design_matrix.shape[0])]
                #transform_matrix=np.matrix(transform_list)

                for (tgid,tginst) in self.allgenedict.items():
                    bayes_selection(tginst,log_list=self.log_list,selection_constant=self.selection_constant)
                self.outliers_removal=True
                for (tgid,tginst) in self.allgenedict.iteritems():
                    iteratenbem(tginst,debug=False,meanvarmodel=self.mrm,restart=False,PPI_prior=self.PPI_prior,removeoutliers=self.outliers_removal,size_factor=self.size_f,beta1_prior_var=self.non_PPI_beta_prior_variance)
                pickle.dump(self,open("/%s/%s_self_bayes_iteration_PPI_%s_outliers_removal_%s.p" %(self.output_directory,self.output_prefix,self.PPI_prior,self.outliers_removal),'wb'))
コード例 #3
0
ファイル: mlemageck_bayes.py プロジェクト: yarker/MAGeCK_Repo
    def bayes_init(self):
        maxgene=np.inf
        if self.negative_control==None:
            self.allgenedict,self.invalid_gRNA_dict=read_gene_from_file(self.count_table,includesamples=self.include_samples,negative_control=self.negative_control)
        else:
            self.allgenedict,self.invalid_gRNA_dict,self.negative_control_gRNAs=read_gene_from_file(self.count_table,includesamples=self.include_samples,negative_control=self.negative_control)

        # calculate the size factor
        cttab_sel={}
        for (geneid,gk) in self.allgenedict.iteritems():
            sgid=gk.sgrnaid
            sgreadmat=gk.nb_count.getT().tolist()
            for i in range(len(sgid)):
                cttab_sel[sgid[i]]=sgreadmat[i]
        if hasattr(self,'norm_method'):
            if self.norm_method!='none':
                self.size_f=normalizeCounts(cttab_sel,method=self.norm_method,returnfactor=True,reversefactor=True,negative_control_gRNAs=self.negative_control_gRNAs)
            else:
                self.size_f=None
        else:
            self.size_f=normalizeCounts(cttab_sel,returnfactor=True,reversefactor=True)
        logging.info('size factor: '+','.join([str(x) for x in self.size_f]))
        #logging.info(self.design_matrix)
        desmat=self.design_matrix
        for (tgid,tginst) in self.allgenedict.iteritems():
            #if tgid=="INO80B":
            tginst.design_mat=desmat
            iteratenbem(tginst,debug=False,estimateeff=False,alpha_val=0.05,size_factor=self.size_f)
            tginst.w_estimate=[]
        deviation(self.allgenedict)

        self.non_PPI_beta_prior_variance=beta_non_PPI_prior_calculation(self.allgenedict)
        pickle.dump(self,open("/%s/%s_self_bayes_init.p" %(self.output_directory,self.output_prefix),'wb'))
コード例 #4
0
    def bayes_iteration(self):
        logging.info('Iteratioin...')
        PPI_choice = [False, True]

        for PPI in PPI_choice:
            self = pickle.load(
                open(
                    "/%s/%s_self_constant_optimization.p" %
                    (self.output_directory, self.output_prefix), 'rb'))
            self.PPI_prior = PPI
            if self.PPI_diagnosis == False and self.PPI_prior == True:
                pass
            else:
                self.outliers_removal = False
                for (tgid, tginst) in self.allgenedict.iteritems():
                    iteratenbem(
                        tginst,
                        debug=False,
                        meanvarmodel=self.mrm,
                        restart=False,
                        PPI_prior=self.PPI_prior,
                        removeoutliers=self.outliers_removal,
                        size_factor=self.size_f,
                        beta1_prior_var=self.non_PPI_beta_prior_variance)
                pickle.dump(
                    self,
                    open(
                        "/%s/%s_self_bayes_iteration_PPI_%s_outliers_removal_%s.p"
                        % (self.output_directory, self.output_prefix,
                           self.PPI_prior, self.outliers_removal), 'wb'))

                #base_index=np.where(~self.design_matrix[:,1:].any(axis=1))[0]
                #transform_list=[1 if i in base_index else -1 for i in range(self.design_matrix.shape[0])]
                #transform_matrix=np.matrix(transform_list)

                for (tgid, tginst) in self.allgenedict.items():
                    bayes_selection(tginst,
                                    log_list=self.log_list,
                                    selection_constant=self.selection_constant)
                self.outliers_removal = True
                for (tgid, tginst) in self.allgenedict.iteritems():
                    iteratenbem(
                        tginst,
                        debug=False,
                        meanvarmodel=self.mrm,
                        restart=False,
                        PPI_prior=self.PPI_prior,
                        removeoutliers=self.outliers_removal,
                        size_factor=self.size_f,
                        beta1_prior_var=self.non_PPI_beta_prior_variance)
                pickle.dump(
                    self,
                    open(
                        "/%s/%s_self_bayes_iteration_PPI_%s_outliers_removal_%s.p"
                        % (self.output_directory, self.output_prefix,
                           self.PPI_prior, self.outliers_removal), 'wb'))
コード例 #5
0
    def bayes_init(self):
        maxgene = np.inf
        if self.negative_control == None:
            self.allgenedict, self.invalid_gRNA_dict = read_gene_from_file(
                self.count_table,
                includesamples=self.include_samples,
                negative_control=self.negative_control)
        else:
            self.allgenedict, self.invalid_gRNA_dict, self.negative_control_gRNAs = read_gene_from_file(
                self.count_table,
                includesamples=self.include_samples,
                negative_control=self.negative_control)

        # calculate the size factor
        cttab_sel = {}
        for (geneid, gk) in self.allgenedict.iteritems():
            sgid = gk.sgrnaid
            sgreadmat = gk.nb_count.getT().tolist()
            for i in range(len(sgid)):
                cttab_sel[sgid[i]] = sgreadmat[i]
        if hasattr(self, 'norm_method'):
            if self.norm_method != 'none':
                self.size_f = normalizeCounts(
                    cttab_sel,
                    method=self.norm_method,
                    returnfactor=True,
                    reversefactor=True,
                    negative_control_gRNAs=self.negative_control_gRNAs)
            else:
                self.size_f = None
        else:
            self.size_f = normalizeCounts(cttab_sel,
                                          returnfactor=True,
                                          reversefactor=True)
        logging.info('size factor: ' + ','.join([str(x) for x in self.size_f]))
        #logging.info(self.design_matrix)
        desmat = self.design_matrix
        for (tgid, tginst) in self.allgenedict.iteritems():
            #if tgid=="INO80B":
            tginst.design_mat = desmat
            iteratenbem(tginst,
                        debug=False,
                        estimateeff=False,
                        alpha_val=0.05,
                        size_factor=self.size_f)
            tginst.w_estimate = []
        deviation(self.allgenedict)

        self.non_PPI_beta_prior_variance = beta_non_PPI_prior_calculation(
            self.allgenedict)
        pickle.dump(
            self,
            open(
                "/%s/%s_self_bayes_init.p" %
                (self.output_directory, self.output_prefix), 'wb'))
コード例 #6
0
ファイル: mlemageck_bayes.py プロジェクト: yarker/MAGeCK_Repo
    def bayes_major(self):
        self=pickle.load(open("/%s/%s_self_fitting.p" %(self.output_directory,self.output_prefix),'rb'))
        logging.info('Run the algorithm for the second time ...')
        ngene=0
        for (tgid,tginst) in self.allgenedict.iteritems():
            #logging.info(tgid)
            iteratenbem(tginst,debug=False,meanvarmodel=self.mrm,restart=False,size_factor=self.size_f,beta1_prior_var=self.non_PPI_beta_prior_variance)
            ngene+=1

        for (tgid,tginst) in self.allgenedict.iteritems():
            if len(tginst.w_estimate)==0:
                tginst.w_estimate=np.ones(len(tginst.sgrnaid))

        pickle.dump(self,open("/%s/%s_self_bayes_major.p" %(self.output_directory,self.output_prefix),'wb'))