示例#1
0
def get_quartets(filepath):
    f = open(filepath,'r')
    q_set=set()
    for line in f:
        q_set.add(unique_quartet(line))
    f.close()
    return q_set
def update(dict_list,filepath):
    f=open(filepath,'r')
    for line in f:
        q=unique_quartet(line)
        for i in range(len(dict_list)):
            if q in dict_list[i]:
                dict_list[i][q]+=1
            else:
                dict_list[i][q]=1
    f.close()    
def adjust_quartet_weight_similarity(file_dir,gene,numtaxa,n):
    nlist=neighbors(file_dir+'//gene_'+str(gene)+'_similarity.txt', n, gene)
    wlist=[2,10,25]
    q_dict=[{},{},{}]
    for i in range(numtaxa-3):
        for j in range(len(wlist)):
            q_dict[j][format(i, i+1, i+2, i+3)]=0
    f = open(file_dir+'//gene_'+str(gene)+'_quartets.txt','r')
    for line in f:
        q=unique_quartet(line)
        for i in range(len(wlist)):
            q_dict[i][q]=wlist[i]
    f.close()
    for i in nlist:
        print 'neighbor ',i
        update(q_dict, file_dir+'//gene_'+str(i)+'_quartets.txt')
    for i in range(len(wlist)):
        write(q_dict[i],file_dir+'//gene_'+str(gene)+'_neighbor_'+str(n)+'_w_'+str(wlist[i])+'_quartets.txt')