view predict/parse_dis_pac.py @ 119:7bb98e9296e9 draft default tip

Uploaded
author tyty
date Tue, 14 Apr 2015 14:18:40 -0400
parents a292aaf51735
children
line wrap: on
line source

#parse reactivity file into a dictionary

import sys

def parse_dist(in_file):
    result = []
    distribution = {}
    name = []
    f = open(in_file)
    for aline in f.readlines():
        line = aline.strip()
        dis = line.strip()
        dist = dis.split('\t') #split the line and the reactivites or reads are in a list
        if len(dist) > 0:
            if len(dist) == 1:
                if dist[0].strip().find('coverage')==-1:
                    name.append(line) #add the name in the name list
                    flag = 1
                    t_name = line
            else:
                distri = []
                for i in range(0, len(dist)):
                    distri.append(dist[i].strip())
                distribution[t_name] = distri #add the list of reactivities into a dictionary
    result.append(name)
    result.append(distribution) #Output the dictionary
    f.close()
    return result