Beispiel #1
0
    def looping_JSD_one_sample(self):

        self.jsd = JSD.Class_JSD(self.desk)
        ''' -----------------------------------------'''

        self.time = crono.Timing()
        self.entFile = bioClass.Entropy_File()
        self.set_my_cluster_filenames()

        name = '%s %s %s' % (self.desk.organism, self.gene, self.title)
        self.names = [[self.cluster_input_filename, name]]

        self.hmi = MI.Mutual_Information_Horizontal(self.desk,
                                                    want_nuc_aa_list=False,
                                                    want_shannon=False)
        if not self.hmi.ok:
            self.error_msg = 'Problems with Init_MI_Heat_Map_Hist_Graph.'
            return False

        if self.desk.organism == "Drosophila":
            self.dr = dro.Drosophila()

        # filename_dist_mat = self.cluster_input_filename
        ''' always read and calc in looping_JSD_one_sample'''
        ret, dicMI, _, _ = self.read_and_calc_one_sample()

        if not ret:
            return False

        xlabel = 'species x species'

        ylabel = 'JSD(%s)' % (self.desk.unit)

        if self.desk.showGraph or self.desk.saveGraph:
            self.jsd.plot_JSD_MI(self.desk,
                                 dicMI,
                                 self.desk.filename_correction,
                                 xlabel,
                                 ylabel,
                                 onlyRef=True,
                                 stay=True)

        return True
Beispiel #2
0
    def __init__(self, desk, want_nuc_aa_list=False, want_shannon = False):
        self.ok = False

        if want_nuc_aa_list:
            self.build_dna_aa(desk)

        self.pij =  []
        self.MIk = 0
        
        self.time = crono.Timing()
        
        self.entFile = bioClass.Entropy_File()

        self.legColumns = 1
        self.legendTitle = '%s Species'%(desk.organism)
        self.title = 'Horizontal MI'        
        
        ''' numLines=1, numCols=1, 
                       legColumns=self.legColumns, 
                       legendTitle=self.legendTitle, title=self.title '''
        self.ent = bioClass.Entropy(desk)


        
        if want_shannon:
            filenameShannon = 'shannon_random_DNA_Letter%i_Exp100_dic.txt'
            self.filenameShannon1 = filenameShannon%(desk.numOfLetters)
            self.filenameShannon2 = filenameShannon%(desk.numOfLetters*2)
            
            ok, msg = self.ent.read_shannon_random_file(desk.rootEntropy, self.filenameShannon1, desk.numOfLetters, showKeys = False)
            if not ok:
                desk.showmsg_obs(msg + ', didnt find Shannon dictionary for %i letter.'%(desk.numOfLetters))
                return
       
            ok, msg = self.ent.read_shannon_random_file(desk.rootEntropy, self.filenameShannon2, 2*desk.numOfLetters, showKeys = False)
            if not ok:
                desk.showmsg_obs(msg + ', didnt find Shannon dictionary for %i letters.'%(2*desk.numOfLetters))
                return
    
        self.ok = True
Beispiel #3
0
    def looping_JSD_all_samples(self):
        plt.close("all")
        plt.clf()

        self.jsd = JSD.Class_JSD(self)

        self.filename_correction = '_bias_corr' if self.withCorrection else ''
                      
        if self.withCorrection:
            self.filename_correction = '_bias_corr'
        else:
            self.filename_correction = ''
            
        self.time = crono.Timing()
        
        name = '%s %s %s'%(self.organism, self.gene, self.title)

        self.entFile = bioClass.Entropy_File()

        self.set_my_cluster_filenames()
        
        self.names = [[self.cluster_input_filename, name]]

        self.hmi = MI.Mutual_Information_Horizontal(self, want_nuc_aa_list=False, want_shannon = False)
        if not self.hmi.ok:
            self.error_msg = 'Problems with Init_MI_Heat_Map_Hist_Graph.'
            return False

        if self.organism == "Drosophila":
            self.dr = dro.Drosophila()
        
        filename_dist_mat = self.cluster_input_filename
                        
        if not os.path.exists(self.rootTable +  filename_dist_mat) or self.de_novo:
            ''' if not found in looping_JSD_all_samples read and calc '''
            ret, dicMI, stri, sError  = self.read_and_calc_all_samples()
        else:
            ret, dicMI, stri, sError = self.read_distance_matrix(filename_dist_mat)
        
        if not ret:
            return False
        
        xlabel = 'species x species'
        
        ylabel = 'JSD(%s)'%(self.unit)

        if self.saveData:
            self.showmsg_obs('\n ============ %s ============'%(self.striMatrix))
            self.showmsg_obs(stri)
            self.showmsg_obs('============ SE %s ============'%(self.striMatrix))
            self.showmsg_obs(sError)
            self.showmsg_obs('============ %s ============\n'%(self.striMatrix))

            if not self.hmi.entFile.write_file(self.rootTable, filename_dist_mat, stri, True):
                return False
            
            filename = filename_dist_mat.replace('.txt','') + '_se.txt'
            if not self.hmi.entFile.write_file(self.rootTable, filename, sError):
                return False

            striSummary = self.hmi.print_MI_species_data(dicMI, roundVal=self.roundVal)
            filename = filename.replace('_se.txt','') + '_summary.txt'
            if not self.hmi.entFile.write_file(self.rootTable, filename, striSummary, True):
                return False

        if self.showGraph or self.saveGraph:
            self.jsd.plot_JSD_MI(self, dicMI, self.filename_correction, xlabel, ylabel, onlyRef=False )

           
        return True
Beispiel #4
0
    def looping(self, desk, opt):
        print("-->>", opt)
        plt.close("all")
        plt.clf()

        desk.minmax = opt[0]

        if desk.each_all == 'each':
            loopCorrection = [desk.withCorrection]
        else:
            loopCorrection = [True, False]

        for correction in loopCorrection:
            ''' -----------------------------------------'''
            desk.withCorrection = correction

            self.time = timePack.Timing()

            name = '%s %s %s' % (desk.organism, desk.gene, desk.title)
            print 'name', name

            self.entFile = bioClass.Entropy_File()

            desk.set_cluster_filenames()

            desk.names = [desk.cluster_input_filename, name]

            self.imi = imi.Mutual_Information_Vertical(desk)
            if not self.imi.ok:
                self.error_msg = 'Problems with Init_MI_Heat_Map_Hist_Graph.'
                return False

            filename_dist_mat = desk.cluster_input_filename

            if not os.path.exists(desk.rootTable +
                                  filename_dist_mat) or desk.de_novo:
                ret, dicMI, stri, sError = self.read_and_calc(desk)
            else:
                ret, dicMI, stri, sError = self.read_distance_matrix(
                    desk, filename_dist_mat)

            if not ret:
                return False

            xlabel = 'species x species'
            ''' recalc: desk.title_jsd and desk.unit '''
            desk.set_cluster_filenames()

            ylabel = 'JSD(%s)' % (desk.unit)

            desk.showmsg_obs('\n ============ %s ============' %
                             (desk.striMatrix))
            desk.showmsg_obs(stri)
            desk.showmsg_obs('============ SE %s ============' %
                             (desk.striMatrix))
            desk.showmsg_obs(sError)
            desk.showmsg_obs('============ %s ============\n' %
                             (desk.striMatrix))

            if desk.saveData:
                if not self.imi.entFile.write_file(
                        desk.rootTable, filename_dist_mat, stri, True):
                    return False

                filename = filename_dist_mat.replace('.txt', '') + '_se.txt'
                if not self.imi.entFile.write_file(desk.rootTable, filename,
                                                   sError):
                    return False

                striSummary = self.imi.print_MI_species_data(
                    dicMI, roundVal=desk.roundVal)
                filename = filename.replace('_se.txt', '') + '_summary.txt'
                if not self.imi.entFile.write_file(desk.rootTable, filename,
                                                   striSummary, True):
                    return False

            listSpecies = self.get_species(desk)
            self.imi.ttest_MI_species_data(desk, listSpecies, dicMI)

            if desk.showGraph or desk.saveGraph:
                self.jsd.plot_JSD_MI(desk, dicMI, xlabel, ylabel)

        return True