예제 #1
0
파일: coordinate.py 프로젝트: ecotox/pacfm
 def yield_pathway_names(self, karyotype):
     for chromosome in self.chromosomes:
         name= Abbrator(chromosome.name, 15, upper= False, pathway=True).abbr
         name= name.capitalize()
         self.abbreviations[chromosome.name] = name 
         coors= chromosome.get_coordinates()
         first= coors[0].get_coordinate()[1]
         karyotype_name= coors[0].get_name_by_level(1)
         last=  coors[-1].get_coordinate()[1]
         coor= (first + last)/2
         line= map(str, [karyotype[karyotype_name], coor, coor, name])              
         yield "\t".join(line)+"\n"
예제 #2
0
파일: coordinate.py 프로젝트: ecotox/pacfm
    def yield_text(self, karyotype, coors_between_letters=100):
        """
            self.karyotype
            Abbrator
        """
        ### below parameters are related to the karyotype size!!1
        ### TODO adjust them accordingly!!!!

            ### factors: directionality, color
            ### 
            #" current problems: 
            #    1 highlights and text coordinates do not match with the heatmap coordinates. check it out
            #    2 spaces between words should not take 3 times the siz of an empty character.
            #    3 ....
        coor_step_size= 5
        
        total_coordinate_len= len(self.get_all_coordinates())
        total_ideogram_len= total_coordinate_len * coor_step_size
        ### broadest level will fit more letters.
        if self.level == 1:
            total_letters= 190
        elif self.level == 2:
            total_letters= 180
        
        ### total number of letters that an ideogram (circle) can fit
        #total_letters= 180
        
        ### length of a character in coordinate units
        char_len=  total_ideogram_len / total_letters  


        
        if self.calculation_type == "sum":
            values= sorted([chrom.get_unique_total_value() for chrom in self.chromosomes])
            #global_total_value= self.get_total_value()
       
        elif self.calculation_type == "average":
            values= sorted([chrom.get_unique_average_value() for chrom in self.chromosomes])
            #global_total_value = self.get_average_value()

        heat_stop_1= int(0.8* len(self.chromosomes))
        heat_stop_2= int(0.5* len(self.chromosomes))
        threshold1= values[heat_stop_1]
        threshold2= values[heat_stop_2]
        ### avg does not work in our case. check what are the light
        ### colors and what are the dark colors in the circos coloring
        ### scheme. in worst case, color dark if the abundance level s
        ### lower than 2/3 instead of averadge. 


        for chrom in self.chromosomes:
            
            name= chrom.name
            
            coordinate_len= len(chrom.get_coordinates())
            chromosome_len= coordinate_len * coor_step_size

            allowed_char_n = int(chromosome_len / char_len) 
            
            abbr_pathway= Abbrator(name, allowed_char_n).abbr
            karyotype_name= chrom.get_coordinates()[0].get_name_by_level(1).strip()
            ### there is enough space after the abbreviation for sure
            self.abbreviations[name] = abbr_pathway

            ### center the label in the ideogram


            ### update the pathway abbreviation according to blank penalty rules
            abbr_pathway= abbr_pathway.replace('.', '')

            free_space= chromosome_len - (len(abbr_pathway) * char_len)
            free_coors= free_space / coor_step_size 
            init_coor= free_coors / 2 
            
            if init_coor < 0 : init_coor= 0
            
            options= ""
           

            
            if self.calculation_type == "sum":
                total= chrom.get_unique_total_value()

            elif self.calculation_type == "average":
                total= chrom.get_unique_average_value()
                
            
            if total < threshold2:
                color = "vdgrey"
           
            elif total >= threshold2 and total < threshold1:
                color= "vvdgrey"

            else:
                color = "white"

            option1= "color=%s" %color
            ## below options did not work
            
            #option2= "label_snuggle=yes" 
            #option3= "label_parallel=no"
            #options= ",".join([option1, option2, option3])
            options= option1


            blank_penalty= 0

            for i in range(len(abbr_pathway)):
                #coor_index= int(init_coor) + int(i * char_len / coor_step_size)
                coor_index= int(init_coor) + (int(init_coor) + int(i * char_len)) / coor_step_size
               
                #if self.level == 2:

                #    pdb.set_trace()
                
                coor= chrom.get_coordinates()[coor_index] 
            
                letter= abbr_pathway[i] 
                
                if letter == " ":
                    blank_penalty+=1
                    
                    #line = [karyotype[karyotype_name], str(startCoor), 
                    #        str(startCoor + int(char_len)), letter, options]

                    #yield "\t".join(line)+'\n'


                else:
                    
                    #if letter == ".":
                    #    blank_penalty += 1
                    #    continue
                    penalty= blank_penalty * int(char_len) / 3
                    crs= coor.get_coordinate()
                    ### we have to also update the init_coor accordingly
                    startCoor= crs[0] - int(penalty) 
                    
                    
                    line = [karyotype[karyotype_name], str(startCoor), 
                            str(startCoor + int(char_len)), letter, options]

                    yield "\t".join(line)+'\n'