AnnotateHumannRings.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:pypers 作者: frankosan 项目源码 文件源码
def process(self):

        ip_rings = open(self.input_rings)

        fileName, fileExt = os.path.splitext(self.input_rings)
        self.output_rings = '%s/%s.annot%s' % (self.output_dir,os.path.basename(fileName),fileExt)

        cmap = plt.get_cmap('hot')

        op_rings = open(self.output_rings,'w')

        for read in ip_rings:
            # Change the color palette
            m = re.search('#(\w{2})0{4}',read)
            if m:
                hexcode = mplcols.rgb2hex(cmap(int(m.group(1),16)))
                read = read.replace(m.group(0),hexcode)
            op_rings.write('%s\n' % read.rstrip())

        rings = {} # dict of lists to hold rings names


        ip_tree = open(self.input_tree,'ro')
        for line in ip_tree:

            level=line.split('.')

            if len(level) > 1:

                if level[0] not in rings:
                    rings[level[0]] = []

                if level[1] not in rings[level[0]]:
                    rings[level[0]].append(level[1])


        colors = ['b','g','r','w','y']
        i = 0
        j = 1

        for ring in rings:
            op_rings.write('%s\t%s\t%i.00:%s\n' % (ring,'annotation',j,ring))
            op_rings.write('%s\t%s\t%s\n' % (ring,'annotation_background_color',colors[i]))

            k = 1
            for level2 in rings[ring]:
                op_rings.write('%s.%s\t%s\t%i.%02i:%s\n' % (ring,level2,'annotation',j,k,level2))
                op_rings.write('%s.%s\t%s\t%s\n' % (ring,level2,'annotation_background_color',colors[i]))
                k += 1

            i += 1
            j += 1
            if i == len(colors):
                i = 0
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号