def adjust_quartet_weight(dir,filename,prefix,suffix,g,w):
    f=open(dir+'//'+filename,'r')
    q_dict={}
    q_dict_tmp={}
    for line in f:
        q=line.split(':',1)[0]
        v=int(line.split(':',1)[1].replace('\n',''))
        q_dict[q]=v
    f.close()
    for i in range(1,g+1):
        del q_dict_tmp
        q_dict_tmp=q_dict.copy()
        f=open(dir+'//'+prefix+str(i)+suffix,'r')
        for line in f:
            qlist=get_taxa(line.split(':',1)[0])
            q=format(int(qlist[0]),int(qlist[1]),int(qlist[2]),int(qlist[3]))
            v=int(line.split(':',1)[1].replace('\n',''))*w
            if q in q_dict_tmp:
                q_dict_tmp[q]=q_dict_tmp[q]+v-1
        f.close()
        sp=''
        if(len(filename.split('_'))>2):
            sp='_'+filename.split('_')[2].split('.')[0]
        write(q_dict_tmp,dir+'//'+prefix+str(i)+'_w_'+str(w)+sp+suffix)  
        print "Gene-",i," Done" 
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')