コード例 #1
0
 def save_without_cloneID(self, Cell2BestSeq):
     Align = MegaAlignment()
     tree_builder = MegaML()
     tree_analyzer = TreeAnalizer()
     BestSeq_builder_3 = Align.UpMeg(Cell2BestSeq, self.CellLs)
     Align.save_mega_alignment_to_file(self.out_file_name,
                                       BestSeq_builder_3)
コード例 #2
0
    def find_decomposed_clone(self, no_back_para_mut_decomposed_seq, REP,
                              Tree):
        Align = MegaAlignment()
        CloLs, Clo2Seq = Align.name2seq(no_back_para_mut_decomposed_seq)
        DecTipLs = []
        DecLs = []
        DecAncLs = []
        RmDecom = []
        for Clo in CloLs:
            #   ClosestAnc = Align.find_closest_anc(Clo,Clo2Seq)
            #  if ClosestAnc!='' :
            #      DecAncLs.appned(Clo)
            if Clo.find('Clu') != -1:
                ID = 'REP' + str(REP)
                In = -1 * len(ID)
                if Clo[In:] == ID:
                    DecLs.append(Clo)
                    Posi = Tree.find(Clo[1:] + ':') + len(Clo)
                    #   print Tree[Posi]
                    Go = 'y'
                    BraLen = ''
                    while Go == 'y':
                        BraLen += Tree[Posi]
                        if Tree[Posi] == ',' or Tree[Posi] == ')': Go = 'n'
                        Posi += 1
                #   print Clo,BraLen
                    if float(BraLen[:-1]) == 0: DecAncLs.append(Clo)  ######
                    else: DecTipLs.append(Clo)

    #  print DecLs,DecAncLs

        if DecLs == []: NewDecom = 'n'
        elif DecTipLs != []:
            NewDecom = 'y'
            for Tip in DecTipLs:
                TipSeq = Clo2Seq[Tip]
                OriTu = Tip.split('Clu')[0]
                #  TipMutC
                Anc = 'n'
                for Clo in Clo2Seq:
                    if Clo != Tip:  # and OriTu!=Clo:
                        UniNum = Align.CountAdditionalMut(TipSeq, Clo2Seq[Clo])
                        if UniNum == 0: Anc = 'y'
                if Anc == 'y': RmDecom.append(Tip)
        else: NewDecom = 'anc'
        #      NewDecom='anc'
        #     for Dclo in DecLs:
        #        if DecAncLs.count(Dclo)==0: 	NewDecom='y'

        #   print Clo2Seq.keys()
        if RmDecom == []: NewClo2Seq_buil = no_back_para_mut_decomposed_seq
        else:
            NewCloDic = {}
            for Clo in Clo2Seq:
                if RmDecom.count(Clo) == 0: NewCloDic[Clo] = Clo2Seq[Clo]
            NewClo2Seq_buil = Align.UpMeg(NewCloDic, [])
        return NewDecom, RmDecom, NewClo2Seq_buil
コード例 #3
0
 def add_back_anc(self, Sub_seq_builder, All_seq_builder):
     Align = MegaAlignment()
     Ls, Sub = Align.name2seq(Sub_seq_builder)
     Ls, All = Align.name2seq(All_seq_builder)
     Clo2Seq = {}
     for Clo in All:
         if Sub.has_key(Clo) == True: Clo2Seq[Clo] = Sub[Clo]
         else: Clo2Seq[Clo] = All[Clo]
     Seq_Buil = Align.UpMeg(Clo2Seq, [])
     return Seq_Buil
コード例 #4
0
    def regress_cnv(self):
        Align = MegaAlignment()
        CloFreAna = CloneFrequencyAnalizer()
        self.Tumor2Clone_frequency = {}
        HitCloSeq_dic = {}
        self.tumor2CNVSNVposi = {}
        #  print 'nnls removing SNV-CNVs'
        for tumor in self.v_obs:
            #  print tumor

            v_obs_single = self.v_obs[tumor]
            v_obs_single_sub = []
            Seq_dic_sub = {}
            RmSNVPosi = []
            CNVls = self._CNV_file[tumor]
            Len = len(CNVls)
            c = 0
            while c < Len:
                if CNVls[c] == 'normal':
                    v_obs_single_sub.append(v_obs_single[c])

                else:
                    RmSNVPosi.append(c)
                c += 1
            for Clo in self.ini_clone_order:
                NewSeq = ''
                OldSeq = self.ini_clone_seq[Clo]
                c = 0
                while c < Len:
                    if RmSNVPosi.count(c) == 0: NewSeq += OldSeq[c]
                    c += 1
                Seq_dic_sub[Clo] = NewSeq

            self.tumor2CNVSNVposi[tumor] = RmSNVPosi
            MutWildAlleleCount_noCNV = self.make_mut_wild_allele_count_noCNV(
                {}, self.ini_clone_order,
                Seq_dic_sub)  #PreAbsCNV, clone_order, SNV_seq, Tu2CloFre
            Cmatrix_noCNV, Cmatrix_noCNV_dic = self.make_Min(
                self.ini_clone_order, Seq_dic_sub, MutWildAlleleCount_noCNV)
            self.Cmatrix_noCNV_mat = Cmatrix_noCNV
            self.Cmatrix_noCNV_dic = Cmatrix_noCNV_dic
            Clone2Freq = self.do_nnls0(Cmatrix_noCNV, self.ini_clone_order,
                                       v_obs_single_sub)
            self.Tumor2Clone_frequency['T-' + tumor] = Clone2Freq
            for Clo in Clone2Freq:
                if Clone2Freq[Clo] > 0:
                    if HitCloSeq_dic.has_key('#' + Clo) != True:
                        HitCloSeq_dic['#' + Clo] = self.ini_clone_seq['#' +
                                                                      Clo]
        self.hitclone_seq_builder = Align.UpMeg(HitCloSeq_dic, [])
        CloFreAna.save_frequency_table_to_file('Ini_freq.txt',
                                               self.Tumor2Clone_frequency, [])
        Align.save_mega_alignment_to_file('Ini.meg', self.hitclone_seq_builder)
コード例 #5
0
    def finalize_results(self, decomposed_seq_builder,
                         decomposed_Tumor2Clone_frequency,
                         origianl_seq_builder, original_Tumor2Clone_frequency,
                         REP):
        Align = MegaAlignment()
        Ls, DecomSeqDic = Align.name2seq(decomposed_seq_builder)
        #   print Ls
        Ls, OriSeqDic = Align.name2seq(origianl_seq_builder)
        NewCloSeqDic = {}
        NewCloFre = {}
        #    print decomposed_Tumor2Clone_frequency,original_Tumor2Clone_frequency
        for Tu in original_Tumor2Clone_frequency:
            if decomposed_Tumor2Clone_frequency.has_key(Tu) != True:

                CloFre = original_Tumor2Clone_frequency[Tu]
                for Clo in CloFre:
                    if CloFre[Clo] > 0:
                        NewCloSeqDic['#' + Clo] = OriSeqDic['#' + Clo]
            elif decomposed_Tumor2Clone_frequency[Tu] == {}:

                CloFre = original_Tumor2Clone_frequency[Tu]
                for Clo in CloFre:
                    if CloFre[Clo] > 0:
                        NewCloSeqDic['#' + Clo] = OriSeqDic['#' + Clo]

            else:
                CloFre0 = decomposed_Tumor2Clone_frequency[Tu]
                CloFre = {}
                for Clo in CloFre0:
                    Fre = CloFre0[Clo]
                    if Fre > 0:
                        if (Clo.find('Clu') != -1 and Clo.find('REP')
                                == -1) or Clo.find('REP' + str(REP - 1)) != -1:
                            CloFre[Clo + 'REP' + str(REP)] = Fre
                            NewCloSeqDic['#' + Clo + 'REP' +
                                         str(REP)] = DecomSeqDic['#' + Clo]
                        else:
                            CloFre[Clo] = Fre
                            if OriSeqDic.has_key('#' + Clo) == True:
                                NewCloSeqDic['#' + Clo] = OriSeqDic['#' + Clo]
                            else:
                                NewCloSeqDic['#' + Clo] = DecomSeqDic['#' +
                                                                      Clo]
            NewCloFre[Tu] = CloFre
        rename_seq_builder = Align.UpMeg(NewCloSeqDic, [])
        #  open('AA','r').readlines()
        return rename_seq_builder, NewCloFre
コード例 #6
0
    def add_back_CNVSNV(self, DecomTu2Seq_builder_sub, CNV_information,
                        original_seqs_builder_all,
                        original_Tumor2Clone_frequency, tsp_list):
        all_tsp = tsp_information(tsp_list)
        v_obs = all_tsp.tumor2alt_frequency()
        Seq_all_dic = {}
        Align = MegaAlignment()
        Original_clols, Original_clodic_all = Align.name2seq(
            original_seqs_builder_all)
        for Tumor in DecomTu2Seq_builder_sub:
            Seq_builder_sub = DecomTu2Seq_builder_sub[Tumor]
            if Seq_builder_sub != []:
                SNVfre_list = v_obs[Tumor]
                CloLs, Clo2Seq = Align.name2seq(Seq_builder_sub)
                CNVinfo = CNV_information[Tumor]
                Len = len(CNVinfo)
                #  print Tumor, Clo2Seq.keys()
                for Clo in Clo2Seq:
                    Seq_sub = Clo2Seq[Clo]
                    c_seq = 0
                    c_all = 0
                    Seq_all = ''
                    while c_all < Len:
                        if CNVinfo[c_all] == 'normal':
                            Seq_all += Seq_sub[c_seq]
                            c_seq += 1
                        else:
                            if SNVfre_list[c_all] == 0: Seq_all += 'A'
                            else: Seq_all += '?'
                        c_all += 1
                    if Original_clodic_all.has_key(Clo) == True:
                        Seq_all_dic[Clo] = Original_clodic_all[Clo]
                    else:
                        Seq_all_dic[Clo] = Seq_all
            else:
                CloFre = original_Tumor2Clone_frequency['T-' + Tumor]

                for Clo in CloFre:
                    if CloFre[Clo] > 0:
                        if Seq_all_dic.has_key('#' + Clo) != True:
                            Seq_all_dic['#' + Clo] = Original_clodic_all['#' +
                                                                         Clo]

        decom_all_seq_builder = Align.UpMeg(Seq_all_dic, [])

        return decom_all_seq_builder
コード例 #7
0
 def get_best_alignment(self, files, ID, remove_redundant, tree_list): 
     Align = MegaAlignment()	
     AncFile = files[0]
     print 'processing file: ' + AncFile
     AncFile=open(AncFile,'r').readlines()
     Lines=[]
     Add='n'	
     for i in AncFile:
             if i.find('Index ')!=-1: Add='y'
             elif Add=='y': 
                 i=i.strip().split(' ')
                 In=[]			
                 for ii in i:
                     if ii!='': In.append(ii)
                 Lines.append(In)				
     Anc2Seq=self.GetRel(Lines)          
     outseq=	Align.UpMeg(Anc2Seq,[])	
     outseq = Align.remove_redund_seqs(outseq)		
     return outseq, tree_list[0]#, best_outset[1], best_outset[2], best_outset[4] #NadeMapInfo, mask_seq, Good_posi_info]
コード例 #8
0
    def regress_cnv(self):
        Align = MegaAlignment()
        self.Tumor2Clone_frequency = {}
        HitCloSeq_dic = {}
        for tumor in self.v_obs:
            v_obs_single = self.v_obs[tumor]
            v_obs_single_sub = []
            Seq_dic_sub = {}
            RmSNVPosi = []
            CNVls = self._CNV_file[tumor]
            Len = len(CNVls)
            c = 0
            while c < Len:
                if CNVls[c] == 'normal':
                    v_obs_single_sub.append(v_obs_single[c])

                else:
                    RmSNVPosi.append(c)
                c += 1
            for Clo in self.ini_clone_order:
                NewSeq = ''
                OldSeq = self.ini_clone_seq[Clo]
                c = 0
                while c < Len:
                    if RmSNVPosi.count(c) == 0: NewSeq += OldSeq[c]
                    c += 1
                Seq_dic_sub[Clo] = NewSeq
            print(tumor, 'exclude bad SNVs for clone frequency computation',
                  RmSNVPosi)
            Cmatrix_noCNV = self.make_Cmatrix(Seq_dic_sub)
            Clone2Freq = self.do_nnls0(Cmatrix_noCNV, v_obs_single_sub)
            self.Tumor2Clone_frequency['T-' + tumor] = Clone2Freq
            for Clo in Clone2Freq:
                if Clone2Freq[Clo] > 0:
                    HitCloSeq_dic['#' + Clo] = self.ini_clone_seq['#' + Clo]
        self.hitclone_seq_builder = Align.UpMeg(HitCloSeq_dic, [])
コード例 #9
0
    def get_candidate_decomposed_clones(self, target_tumor, CluInf_tu,Tuseq):
        Align = MegaAlignment()	
     	
        NameOrder, Name2Seq = Align.name2seq(CluInf_tu[0])
	
        LenSeq = len(Name2Seq[NameOrder[0]])
    
        SigCluLs=[]		
        for Name in NameOrder: #Root is the first cluster or initial candidate clone
               if Name!='#Clu0' and Name.find('Clu')!=-1: SigCluLs.append(Name)
        CluCombLs,IDend=self.combinations([],SigCluLs,0,{})   
        print(target_tumor,'make cluster comb',SigCluLs,CluCombLs,NameOrder)
   	
        if CluCombLs!={}:   
			 
             CloCan2Seq={}
             Got_Candidate='n'			 
             for Root in NameOrder: #Root is the first cluster or initial candidate clone
               if Root=='#Clu0' or Root.find('Clu')==-1:			 
                RootSeq=Name2Seq[Root]
                if Root=='#Clu0': CloCan2Seq['#'+target_tumor+'Clu0']=RootSeq  #Root is candidate clone              				
                RootMut=Align.GetMutPos(RootSeq)
                Got_Candidate='y'
                if CluCombLs!={}:				
                 for ID in CluCombLs:
                    CluLs=CluCombLs[ID]	
            			
                    CluN=''
                    MutPosLs=[]						
                    for Clu in CluLs:  
                        Seq=Name2Seq[Clu]
                        CluMut=Align.GetMutPos(Seq)
                        MutPosLs+=	CluMut							
                        CluN+=Clu.replace('#','')

                    Good='y'					
                    for Mut in MutPosLs:
                         if RootMut.count(Mut)!=0: Good='n'
					 
                    if Good=='y':	
                         AllMutPosLs=MutPosLs+RootMut					
                         Seq=Align.ModSeq('A'*LenSeq,AllMutPosLs,'T',LenSeq)
                         Redun_ls=Align.find_redundant(Seq,self.clone_seq) #all other clones ####	
                       				
                         if Redun_ls==[]:			
                            CloCan2Seq['#'+target_tumor+Root.replace('#','')+CluN]=Seq
                   					
  
             if CloCan2Seq!={}:	  
	
                      CloCan2Seq.update(self.clone_seq) 
                      Can_list=list(CloCan2Seq.keys())					  
                            					  
                      new_seq = Align.UpMeg(CloCan2Seq,Can_list)
                   						   
                      clone_frequency_combo = CloneFrequencyComputer_cnv1(new_seq, {target_tumor:self.v_obs[target_tumor]}, {target_tumor:self._CNV_file[target_tumor]}, self.freq_cutoff)
                      clone_frequency_combo.regress_cnv()					
                      CluComboHit=self.findcombohit(clone_frequency_combo.hitclone_seq_builder)
                      if CluComboHit=='y':
                            print('test the quality of clustercombo, by removing tumor seq (if any)')
                            hit_seq_ls,hit_seq_dic=Align.name2seq(clone_frequency_combo.hitclone_seq_builder) 							
                            Tuseq_ls=Align.find_redundant(Tuseq,hit_seq_dic)	
                            if Tuseq_ls==[]:
                                  print('tumor genotype did not hit, so clustercombo is good')							
                                  return clone_frequency_combo.hitclone_seq_builder,Tuseq
                            else:
                                  print('tumor genotype was hit, so test if clustercombo still hit without tumor genotype: testing if clustercombo genotypes fit well')
                                  Tuseq_ls=Align.find_redundant(Tuseq,CloCan2Seq)									  
                                  sub_hit_seq=[]
                                  for seqname in CloCan2Seq:
                                        if Tuseq_ls.count(seqname)==0:sub_hit_seq+=[seqname,CloCan2Seq[seqname]]
                            
                                  clone_frequency_combo_new = CloneFrequencyComputer_cnv1(sub_hit_seq, {target_tumor:self.v_obs[target_tumor]}, {target_tumor:self._CNV_file[target_tumor]}, self.freq_cutoff)
                                  clone_frequency_combo_new.regress_cnv()					
                                  CluComboHit=self.findcombohit(clone_frequency_combo_new.hitclone_seq_builder)
                                  if CluComboHit=='y': 
                           					  
                                     return clone_frequency_combo_new.hitclone_seq_builder,Tuseq 
                                  else: 
                                     return CluInf_tu[0],''								  
                      else: return CluInf_tu[0] ,''                                 								  
                                							
                      	
             else: return CluInf_tu[0],''
        return CluInf_tu[0],''		
コード例 #10
0
            print(Message)
            summary_file += Message + '\n'
            DecomTuNum = len(Message.split(','))

            if Message[:10] != 'decomposed' or DecomTuNum > (1.0 * len(v_obs) /
                                                             2):
                Repeat = 'n'
                final_seq = clone_frequency_cnv.hitclone_seq_builder
                final_clofre = clone_frequency_cnv.Tumor2Clone_frequency
                print('no more new clones',
                      clone_frequency_cnv.Tumor2Clone_frequency)

            else:

                hit_seq_dic['#hg19'] = 'A' * num_sites
                hit_seq_build = Align.UpMeg(hit_seq_dic,
                                            list(hit_seq_dic.keys()))
                id = 'dec_mega_alignment'
                status = tree_builder.do_mega_mp(hit_seq_build, id)
                if status == True and ItC < 5:
                    decomseqs_with_ancestor, A1 = tree_builder.alignment_least_back_parallel_muts(
                    )  # True will execute code to remove redundant seqs (True is default)
                    # self._cleanup_temp_files()
                    clone_frequency_cnv2 = CloneFrequencyComputer_cnv1(
                        decomseqs_with_ancestor, v_obs, CNV_information_test,
                        params.freq_cutoff)
                    clone_frequency_cnv2.regress_cnv()
                    decomseqs_with_ancestor_clone_freq = clone_frequency_cnv2.Tumor2Clone_frequency
                    decomseqs_with_ancestor = clone_frequency_cnv2.hitclone_seq_builder
                    seqs_with_ancestor, A1, A2 = OutFile.ReNameCloFreMeg(
                        decomseqs_with_ancestor,
                        decomseqs_with_ancestor_clone_freq, 'number')
コード例 #11
0
    def remove_insignificant_clones(self, v_obs, CloFre_clone,
                                    clone_seq_builder, Tu2CNV, Cut):
        Align = MegaAlignment()
        OutAncAll = 'SigTest.txt'
        outAncAll = 'tumor\tDecsendant-Ancestor\tSNV posi\tType\tObsFre\n'
        Clone_list, clone_seq_dic = Align.name2seq(clone_seq_builder)
        new_clone_freq = {}
        new_clone_seq_dic = {}
        for tumor in v_obs:
            CNV = Tu2CNV[tumor]
            Clo2Fre = CloFre_clone['T-' + tumor]
            ObsFre = v_obs[tumor]

            clone_order = []
            MutNum2Clo = {}
            MutNum_ls = []
            for Clo in Clo2Fre:
                if Clo2Fre[Clo] > 0:
                    MutPosLs = Align.GetMutPos(clone_seq_dic['#' + Clo])
                    MutNum = len(MutPosLs)
                    if MutNum2Clo.has_key(MutNum) != True:
                        MutNum2Clo[MutNum] = []
                    MutNum2Clo[MutNum].append(Clo)
                    MutNum_ls.append(MutNum)
            MutNum_ls = list(set(MutNum_ls))
            MutNum_ls.sort(reverse=True)
            for MutNum in MutNum_ls:

                clone_order += MutNum2Clo[MutNum]

            CloNum = len(clone_order)
            C1Max = CloNum - 1
            InsigLs = []

            C1 = 0
            while C1 < C1Max:
                Clo1 = clone_seq_dic['#' + clone_order[C1]]
                num_sites = len(Clo1)
                Min_num = 0.01 * num_sites
                C2 = C1 + 1
                while C2 < CloNum:
                    Clo2 = clone_seq_dic['#' + clone_order[C2]]

                    Share = []
                    Unique = []
                    c = 0
                    while c < num_sites:
                        if CNV[c] == 'normal':
                            if Clo1[c] == 'T' and Clo2[c] == 'T':
                                Share.append(ObsFre[c])
                                outAncAll += tumor + '\t' + clone_order[
                                    C1] + '-' + clone_order[C2] + '\t' + str(
                                        c) + '\tShare\t' + str(
                                            ObsFre[c]) + '\n'
                            elif Clo1[c] == 'T' and Clo2[c] == 'A':
                                Unique.append(ObsFre[c])
                                outAncAll += tumor + '\t' + clone_order[
                                    C1] + '-' + clone_order[C2] + '\t' + str(
                                        c) + '\tUnique\t' + str(
                                            ObsFre[c]) + '\n'

                        c += 1
                    if (len(Share) < 3
                            or len(Unique) < 3) or (len(Share) < Min_num
                                                    or len(Unique) < Min_num):
                        P = 1
                    else:
                        P = scipy.stats.ttest_ind(Share,
                                                  Unique,
                                                  equal_var=False)

                        P = P[-1]
                    if P > Cut:
                        if clone_order[C1].find('Clu') != -1 and clone_order[
                                C2].find('Clu') == -1:
                            InsigLs.append(clone_order[C1])
                        else:
                            InsigLs.append(clone_order[C2])

                    C2 += 1

                C1 += 1
            InsigLs = list(set(InsigLs))
            if InsigLs != []: print 'insignificant clones', tumor, InsigLs
            new_clone_fre_in = {}
            for Clo in Clo2Fre:
                if Clo2Fre[Clo] > 0 and InsigLs.count(Clo) == 0:
                    new_clone_fre_in[Clo] = Clo2Fre[Clo]
                    new_clone_seq_dic['#' + Clo] = clone_seq_dic['#' + Clo]
            new_clone_freq['T-' + tumor] = new_clone_fre_in
        new_seq_builder = Align.UpMeg(new_clone_seq_dic, [])

        return new_seq_builder, new_clone_freq
コード例 #12
0
    def get_candidate_decomposed_clones(self, target_tumor):
        Align = MegaAlignment()
        CluInf_tu = self.ClusterInfo  #[target_tumor]
        NameOrder, Name2Seq = Align.name2seq(CluInf_tu[2])
        #  print target_tumor, CluInf_tu[0],CluInf_tu[1]
        HitCloCluLs = CluInf_tu[1]  #['T-'+target_tumor]
        TuIdentical_seq = self.identical_seq['T-' + target_tumor]
        LenSeq = len(Name2Seq[NameOrder[0]])
        TuSeq = self.T2Seq['#' + target_tumor]
        Clu2center = CluInf_tu[0]
        SigCluLs = []
        HitCloLs = []
        HitCloSeq_dic = {}
        RootClu = ''
        LarCen = 0.0
        for Hit in HitCloCluLs:
            if HitCloCluLs[Hit] > 0.02:
                if Hit[:len(target_tumor +
                            'Clu')] == target_tumor + 'Clu' and Hit.find(
                                'REP') == -1:
                    SigCluLs.append(Hit)
                    CluName = 'Clu' + Hit.split('Clu')[-1]
                    Center = float(Clu2center[CluName].split('-')[0])

                    for CluN in Clu2center:
                        Center2 = float(Clu2center[CluN].split('-')[0])
                        Sign = Clu2center[CluN].split('-')[1]
                        if Center == Center2 and CluName != CluN:
                            SigCluLs.append(target_tumor + CluN)
                        if LarCen < Center2:  # and Sign=='Pos':  #Pos for middle cut, Neg for K-means
                            LarCen = Center2
                            if Center == Center2: RootClu = target_tumor + CluN
                        elif LarCen <= Center2 and Sign == 'Pos':  #Pos for middle cut, Neg for K-means
                            LarCen = Center2
                            if Center == Center2: RootClu = target_tumor + CluN

                else:
                    HitCloLs.append(Hit)
                    HitCloSeq_dic['#' + Hit] = Name2Seq['#' + Hit]

    #  print 'cluls0',SigCluLs, HitCloLs, RootClu
        if RootClu != '':
            SigCluLs.remove(RootClu)
            HitCloLs.append(RootClu)
        # print 'cluls',SigCluLs, HitCloLs, RootClu
        if SigCluLs != []:
            CluCombLs, IDend = self.combinations([], SigCluLs, 0, {})
        else:
            CluCombLs = {}
        #  print CluCombLs
        if RootClu != '' or CluCombLs != {}:
            print 'make cluster comb'
            CloCan2Seq = {}
            Got_Candidate = 'n'
            for Root in HitCloLs:
                RootSeq = Name2Seq['#' + Root]
                LenSeq = len(RootSeq)
                RootMut = Align.GetMutPos(RootSeq)
                CloCan2Seq['#' + Root] = RootSeq
                Got_Candidate = 'y'
                if CluCombLs != {}:
                    for ID in CluCombLs:
                        CluLs = CluCombLs[ID]
                        #   print 'try make combo',Root,CluLs
                        CluN = ''
                        MutPosLs = []
                        for Clu in CluLs:
                            Seq = Name2Seq['#' + Clu]
                            CluMut = Align.GetMutPos(Seq)
                            MutPosLs += CluMut
                            CluN += Clu.replace(target_tumor + 'Clu', 'Clu')

                        MutPosLs = list(set(MutPosLs))
                        Go = 'y'
                        for Mut in MutPosLs:
                            if RootMut.count(Mut) != 0: Go = 'n'

                        if Go == 'y':
                            AllMutPosLs = MutPosLs + RootMut
                            Seq = Align.ModSeq('A' * LenSeq, AllMutPosLs, 'T',
                                               LenSeq)
                            Redun_ls = Align.find_redundant(Seq, HitCloSeq_dic)

                            if Redun_ls == []:
                                CloCan2Seq['#' + target_tumor + Root.replace(
                                    target_tumor + 'Clu', 'Clu') + CluN] = Seq
                                Got_Candidate = 'y'

            if Got_Candidate == 'y':
                Can_list = CloCan2Seq.keys()
                #   print 'find the good comb',Can_list

                new_seq = Align.UpMeg(CloCan2Seq, Can_list)
                alt_frequency = []
                CNVls = self.CNV_info[target_tumor]
                Len = len(CNVls)
                c = 0
                TuMatPosi = []
                tumor_genotype = ''
                while c < Len:
                    if CNVls[c] == 'normal':
                        alt_frequency.append(self.v_obs[target_tumor][c])
                        if self.v_obs[target_tumor][c] > 0:
                            TuMatPosi.append(c)
                            tumor_genotype += 'T'
                        else:
                            tumor_genotype += 'A'
                    c += 1

                clone_frequency = CloneFrequencyComputer_cnv1({}, {}, {},
                                                              self.freq_cutoff,
                                                              {})

                MutWildAlleleCount_noCNV = clone_frequency.make_mut_wild_allele_count_noCNV(
                    {}, Can_list,
                    CloCan2Seq)  #PreAbsCNV, clone_order, SNV_seq, Tu2CloFre
                Cmatrix_noCNV, Cmatrix_noCNV_dic = clone_frequency.make_Min(
                    Can_list, CloCan2Seq, MutWildAlleleCount_noCNV)
                Clone2Freq = clone_frequency.do_nnls0(Cmatrix_noCNV, Can_list,
                                                      alt_frequency)

                out2 = ['#MEGA', '!Title SNVs;', '!Format datatype=dna;', ' ']
                AllMut = []
                NewClone2Freq = {}
                CluHit = 'n'
                for Clo0 in Clone2Freq:
                    NewClone2Freq[Clo0] = Clone2Freq[Clo0]
                    if Clone2Freq[Clo0] > 0.02:

                        SeqMutPos = Align.GetMutPos(CloCan2Seq['#' + Clo0])
                        TuSeq = 'y'
                        for Mut in SeqMutPos:
                            if TuMatPosi.count(Mut) != 0: AllMut.append(Mut)
                        for Mut in TuMatPosi:
                            if SeqMutPos.count(Mut) == 0: TuSeq = 'n'
                        Iden = 'n'
                        for OriClo in self.OriAnc2Seq0:
                            c = 0
                            Dif = 'n'
                            while c < Len:
                                if self.OriAnc2Seq0[OriClo][c] != CloCan2Seq[
                                        '#' + Clo0][c]:
                                    Dif = 'y'
                                c += 1
                            if Dif == 'n': Iden = OriClo
                        if Iden != 'n':
                            out2 += [Iden, self.OriAnc2Seq0[Iden]]
                            NewClone2Freq[Iden[1:]] = Clone2Freq[Clo0]
                            NewClone2Freq[Clo0] = 0
                        elif TuSeq == 'n':

                            out2 += [
                                '#' + Clo0.replace(target_tumor + target_tumor,
                                                   target_tumor),
                                CloCan2Seq['#' + Clo0]
                            ]
                            if Clo0.find('Clu') != -1 and Clo0.find(
                                    'REP') == -1:
                                CluHit = 'y'
                        else:
                            out2 += [
                                '#' + target_tumor, CloCan2Seq['#' + Clo0]
                            ]
                            NewClone2Freq[target_tumor] = Clone2Freq[Clo0]
                            NewClone2Freq[Clo0] = 0
                AllMut = list(set(AllMut))
                if len(AllMut) < len(TuMatPosi):
                    out2 += ['#' + target_tumor, tumor_genotype]
                if CluHit == 'y':

                    #  print 'Decomposed!'	,target_tumor,NewClone2Freq,out2
                    return out2, NewClone2Freq

        return [], {}
コード例 #13
0
 def get_tree_with_branchLen(self, ID):
     Align = MegaAlignment()
     self.GetOut(ID + '.nwk', self.RescaledTree)
     SeqLs = Align.UpMeg(self.nodeid2seq, [])
     Align.save_mega_alignment_to_file(ID + '_NodeSeq.meg', SeqLs)