def extract_hitseq(self,seq_buil,CloFre,Cut):
     Align=MegaAlignment()
     CloLs,Clo2Seq=Align.name2seq(seq_buil)	
     Hit={}
     for Clo in CloFre:
          if CloFre[Clo]>Cut: Hit['#'+Clo]=Clo2Seq['#'+Clo]
     return Hit			 
示例#2
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)
示例#3
0
 def __init__(self, seqs_with_ancestor, v_obs, CNV_info, freq_cutoff):
     self.CutOff = freq_cutoff
     Align = MegaAlignment()
     self.ini_clone_order, self.ini_clone_seq = Align.name2seq(
         seqs_with_ancestor)
     self._CNV_file = CNV_info
     self.v_obs = v_obs
示例#4
0
    def do_mega_mp(self, alignment_builder, mega_id):
        self._newick_trees = []
        print('constructing MP tree')
        result = False
        self._update_file_names(mega_id)
        Align = MegaAlignment()
        Align.save_mega_alignment_to_file(self._alignment_file,
                                          alignment_builder)
        cl = self._command_line_string()
        os.system(cl)
        if os.path.isfile(self._newick_file) == True:
            result = True
            nf = open(self._newick_file, 'r')
            ns = nf.readlines()
            for line in ns:
                self._newick_trees.append(line)
            nf.close()
            files = self._get_ancestral_states_files()
            self._retrieve_ancestral_states()
            seq_maker = MakeAncSeqMPMin()

            self.best_align_result = seq_maker.get_best_alignment(
                files, self._mega_id, True, self.newick_trees)

        self._cleanup_temp_files()
        return result
示例#5
0
    def do_mega_pp(self, alignment_builder, tree_builder, mega_id):

        print 'computing PP'
        result = False
        self._update_file_names(mega_id)

        Align = MegaAlignment()
        Align.save_mega_alignment_to_file(self._alignment_file,
                                          alignment_builder)  ###
        self.save_str_to_file(tree_builder, self._input_tree_file)

        cl = self._command_line_string()
        os.system(cl)

        PPfileLs = glob.glob(self._pp_file[:-4] + 'seq-*.csv')

        if PPfileLs != []:
            result = True
            for PPfile in PPfileLs:

                shutil.copyfile(PPfile, PPfile.split('\\')[-1])

    #    print result

        return result
    def EstimateSNVfre(self, Tu2CloFre, clone_seq0, ReadCount):
        Align = MegaAlignment()
        cloorder, clone_seq = Align.name2seq(clone_seq0)

        tumor2estSNV = {}
        tumor2diff = {}

        for tumor in Tu2CloFre:
            clone2frequency = Tu2CloFre[tumor]
            tumor = tumor.split('-')[-1]
            estSNVfreLs = []
            DiffLs = []
            snv_num = len(ReadCount[tumor + ':ref'])

            c = 0
            while c < snv_num:
                estSNVfre = 0
                for Clo in clone2frequency:

                    S = clone_seq['#' + Clo]

                    if str(clone2frequency[Clo]).find('e') != -1: F = 0
                    else: F = clone2frequency[Clo] / 2
                    if S[c] == 'T': estSNVfre += F

                estSNVfreLs.append(estSNVfre)
                Obs = 1.0 * float(ReadCount[tumor + ':alt'][c]) / (
                    float(ReadCount[tumor + ':alt'][c]) +
                    float(ReadCount[tumor + ':ref'][c]))
                Dif = estSNVfre - Obs
                DiffLs.append(Dif)
                c += 1
            tumor2estSNV[tumor] = estSNVfreLs
            tumor2diff[tumor] = DiffLs
        return tumor2estSNV, tumor2diff
 def findcombohit(self,seq_builder):
     Align=MegaAlignment()
     SeqLs,SeqDic=Align.name2seq(seq_builder)
     Find='n'
     for i in SeqLs:
         if i.find('Clu')!=-1: Find='y'
     return Find			
示例#8
0
    def fill_cloneseq(self):
        Align=MegaAlignment()	

        Cell2BestSeq={}
        
        for Clone in self.Clone2CellLs:
              CellLs=self.Clone2CellLs[Clone]
              DiffNucPosiLs=Align.GetDiffPosi(CellLs, self.Cell2Seq)
         
              Posi2Nuc={}
              for Posi in DiffNucPosiLs:
                   Nuc2PPls={'A':[],'T':[]}
                   for Cell in CellLs:				   
                         Nuc2PPls['A'].append(self.Cell2PPls[Cell][Posi]['A'])
                         Nuc2PPls['T'].append(self.Cell2PPls[Cell][Posi]['T'])
                   TAve=sum(Nuc2PPls['T'])/len(Nuc2PPls['T'])
                   AAve=sum(Nuc2PPls['A'])/len(Nuc2PPls['A'])
                   if TAve>AAve: Posi2Nuc[Posi]='T'
                   else: Posi2Nuc[Posi]='A'
              for Cell in CellLs:
                    CellSeq=self.Cell2Seq['#'+Cell]
              			
                    c=0
                    NewSeq=''
                    while c<self.SNVnum:
                        if CellSeq[c]=='?': NewSeq+='?' 
                        elif Posi2Nuc.has_key(c)!=True: NewSeq+=CellSeq[c]
                        else: NewSeq+=Posi2Nuc[c]
                        c+=1
                    Cell2BestSeq['#'+Cell]=NewSeq	
        self.save_with_cloneID(Cell2BestSeq)
        self.save_without_cloneID(Cell2BestSeq)		
示例#9
0
    def do_mega_mp(self, alignment_builder, mega_id):
        self._newick_trees = []
        print 'constructing MP tree'
        result = False
        self._update_file_names(mega_id)
        #  print self._alignment_file
        Align = MegaAlignment()
        Align.save_mega_alignment_to_file(self._alignment_file,
                                          alignment_builder)

        cl = self._command_line_string()
        os.system(cl)
        if os.path.isfile(self._newick_file) == True:
            result = True
            nf = open(self._newick_file, 'r')
            ns = nf.readlines()
            print 'MP tree(s):'
            for line in ns:
                print line
                self._newick_trees.append(line)
            nf.close()
            self._retrieve_ancestral_states()

    #  self._cleanup_temp_files()
        return result
示例#10
0
    def remove_ancestral_decomposed(self,
                                    remove_tumor_and_rename_decomposed_seq,
                                    Error_rate, tumor_seqs):
        #  print 'Tu',tumor_seqs
        Align = MegaAlignment()
        SeqOrderIni, Meg2Seq = Align.name2seq(
            remove_tumor_and_rename_decomposed_seq)
        TuLs, Tu2Seq = Align.name2seq(tumor_seqs)
        good_seq = ['#MEGA', '!Title SNVs;', '!Format datatype=dna;', ' ']
        RmCluClo = []
        for name1 in SeqOrderIni:
            if name1.find('Clu') != -1:
                seq1 = Meg2Seq[name1]
                for name2 in SeqOrderIni:
                    if name2 != '#hg19' and name1 != name2:
                        seq2 = Meg2Seq[name2]
                        Additional_mut_num1 = Align.CountAdditionalMut(
                            seq1, seq2)
                        Der = 1.0 * Additional_mut_num1 / len(seq1)

                        if name2.find('Clu') != -1:
                            if Additional_mut_num1 == 0: RmCluClo.append(name1)
                        else:
                            if Der < Error_rate: RmCluClo.append(name1)
        AddedTuLs = []
        for Name in SeqOrderIni:
            if RmCluClo.count(Name) == 0:
                good_seq += [Name, Meg2Seq[Name]]
                AddedTuLs.append(Name.split('Clu')[0])
        for Tu in TuLs:
            if AddedTuLs.count(Tu) == 0: good_seq += [Tu, Tu2Seq[Tu]]
        good_seq += ['#hg19', 'A' * len(seq1)]
        return good_seq
示例#11
0
    def do_mega_ml(self, alignment_builder, mega_id):

        print('constructing ML tree')
        result = False
        self._update_file_names(mega_id)
        print(self._alignment_file)
        Align = MegaAlignment()
        Align.save_mega_alignment_to_file(self._alignment_file,
                                          alignment_builder)

        cl = self._command_line_string()
        os.system(cl)
        if os.path.isfile(self._newick_file) == True:
            result = True
            nf = open(self._newick_file, 'r')
            # ns = nf.readlines()
            print('ML tree:')
            #  for line in ns:
            # print line
            self._newick_trees = nf.readlines()[0]
            print(self._newick_trees)
            nf.close()
        # self._retrieve_ancestral_states()

    # self._cleanup_temp_files()
        return result
示例#12
0
 def __init__(self, tumor_seq, tsp_list, mao_file):
     Align = MegaAlignment()
     self.tumor_list, self.tumor2seq = Align.name2seq(tumor_seq)
     self.Len = len(self.tumor2seq[self.tumor_list[0]])
     self.mao_file = mao_file
     self.tsp_list = tsp_list
     TSPinfo = tsp_information(tsp_list)
     self.Tu2SNV = TSPinfo.tumor2alt_frequency()
示例#13
0
    def ReNameCloFreMeg(self, seqs, CloFre, Name):
        Align = MegaAlignment()
        CloFreAnalize = CloneFrequencyAnalizer()

        NameOrder, Clo2Seq = Align.name2seq(seqs)
        if CloFre == {}:
            CloFre['T-A'] = {}
            for Clo in Clo2Seq:
                CloFre['T-A'][Clo[1:]] = 1

    # print Clo2Seq,seqs
        Len = len(Clo2Seq[NameOrder[0]])
        out = [
            '#MEGA', '!Title SNVs;', '!Format datatype=dna;', ' ', '#hg19',
            'A' * Len
        ]
        TuLs = []
        for Tu in CloFre:
            TuLs.append(Tu[3:])
        TuLs.sort()
        Old2NewCloLs = {}
        Old2NewCloNum = {}
        CloOrder = []
        Num = 1
        for Tu in CloFre:
            Clo2Fre = CloFre[Tu]
            HitClo = []
            for Clo in Clo2Fre:
                if Clo2Fre[Clo] > 0: HitClo.append(Clo)
            Tu = Tu[2:]
            C = 1
            CloLs, Fre2Clo = CloFreAnalize.Sort(HitClo,
                                                Clo2Fre)  #from large frequency
            for Clo in CloLs:
                Code = Clo in Old2NewCloLs
                if Code != True:
                    Old2NewCloLs[Clo] = ''
                    Old2NewCloNum[Clo] = 'Clone' + str(Num)
                    CloOrder.append(Clo)
                    Num += 1
                Old2NewCloLs[Clo] += Tu + str(C)
                C += 1
        if Name == 'list': Old2NewClo = Old2NewCloLs
        else: Old2NewClo = Old2NewCloNum
        NewCloOrder = []
        NewT2C2F = {}
        for Clo in CloOrder:
            NewCloOrder.append(Old2NewClo[Clo])
            out += ['#' + Old2NewClo[Clo], Clo2Seq['#' + Clo]]  #+'\n'
        for Tu in CloFre:
            C2F = CloFre[Tu]
            NewC2F = {}

            for C in C2F:
                if C2F[C] > 0:
                    NewC2F[Old2NewClo[C]] = C2F[C]
            NewT2C2F[Tu] = NewC2F
        return out, NewT2C2F, NewCloOrder
示例#14
0
    def save_with_cloneID(self, CellSeqDic):
        Align = MegaAlignment()
        outSeq_builder = ['#MEGA', '!Title SNVs;', '!Format datatype=dna;', ' ']
        for Clone in self.Clone2CellLs:
            CellLs = self.Clone2CellLs[Clone]
            for Cell in CellLs:
                outSeq_builder += ['#' + Cell + '_{' + Clone + '}', CellSeqDic['#' + Cell]] #######change

        Align.save_mega_alignment_to_file(self.out_file_name[:-4] + '_withCloneID.meg', outSeq_builder)
示例#15
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
示例#16
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
示例#17
0
 def __init__(self, ini_seq_builder, v_obs, clone_frequencies, CNV,
              freq_cutoff):
     self.freq_cutoff = freq_cutoff
     self.Tu2CloFre = clone_frequencies
     self.CloFreCutOff = self.freq_cutoff
     self.v_obs = v_obs
     Align = MegaAlignment()
     self.clone_order, self.clone_seq = Align.name2seq(ini_seq_builder)
     self._CNV_file = CNV
     self.snv_num = len(self.clone_seq[self.clone_order[0]])
 def __init__(self, ini_seq_builder, tsp_list, clone_frequencies, CNV,
              freq_cutoff):
     self.tsp_list = tsp_list
     self.freq_cutoff = freq_cutoff
     self.Tu2CloFre = clone_frequencies
     self.all_tsp = tsp_information(tsp_list)
     self.CloFreCutOff = self.freq_cutoff
     self.v_obs = self.all_tsp.tumor2alt_frequency()
     Align = MegaAlignment()
     self.clone_order, self.clone_seq = Align.name2seq(ini_seq_builder)
     self._CNV_file = CNV
    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)
示例#20
0
 def __init__(self, id0, seqs, PPcut): #seqs is list format of mega alignment
   self.PPcut=PPcut	  
   Align = MegaAlignment()
   tree_builder = MegaML() 
   tree_analyzer = TreeAnalizer()  
   self.InMeg = Align.AddNormal(seqs)
   status = tree_builder.do_mega_ml(self.InMeg, id0)
   if status == True:
            tree = tree_builder.newick_trees
   else:
             print 'failed to run megaML'	  
   self.Tree_rooted = tree_analyzer.RootTree(tree, 'Normal')
    def _remove_redund_seqs(self, Meg):
        print 'removing redundant seqs...'
        Align = MegaAlignment()
        NameOrder, Name2Seq = Align.name2seq(Meg)

        out2 = ['#MEGA', '!Title SNVs;', '!Format datatype=dna;']
        c = 0
        Name2IdenLs = {}
        SeqNum = len(NameOrder)
        Len = len(Name2Seq[NameOrder[0]])
        while c < SeqNum:
            Ref = NameOrder[c]
            RefSeq = Name2Seq[Ref]
            Name2IdenLs[Ref] = [Ref]
            Tc = 0
            while Tc < SeqNum:
                Tar = NameOrder[Tc]
                TarSeq = Name2Seq[Tar]
                DifC = self._count_diff_num(RefSeq, TarSeq)
                if DifC == 0:
                    Name2IdenLs[Ref].append(Tar)
                Tc += 1
            c += 1
        Done = []
        for Name in Name2Seq:
            Code = Name in Done
            if Code != True:
                IdenLs = Name2IdenLs[Name]
                GoodName = ''
                for i in IdenLs:
                    if GoodName == '': GoodName = i
                    elif i == '#hg19': GoodName = i
                    elif GoodName == '#hg19': pass
                    elif i.find('Node') == -1 and i.find('Clu') == -1:
                        GoodName = i
                    elif GoodName.find('Node') == -1 and GoodName.find(
                            'Clu') == -1:
                        pass
                    elif GoodName.find('Node') != -1:
                        GoodName = i
                    elif i.find('Node') != -1:
                        pass
                    elif i.find('Clu') != -1 and GoodName.find(
                            'Clu') != -1 and i.find(
                                'REP') != -1 and GoodName.find('REP') == -1:
                        GoodName = i
                    else:
                        pass
                out2 += [GoodName, Name2Seq[Name]]
                Done += IdenLs

        return out2
示例#22
0
   def __init__(self, seqs, num_support_position, Cell2PPls, initial_seq_builder, OutFileName):
      	
       self.cut = num_support_position
       Align = MegaAlignment()
       self.ini_seqs_builder = seqs
       self.CellLs, self.Cell2Seq = Align.name2seq(seqs)
 	
       self.SNVnum = len(self.Cell2Seq[self.CellLs[0]])
     
       self.InMeg = Align.AddNormal(seqs)
       IniCellLs, self.Cell2iniSeq = Align.name2seq(initial_seq_builder)
       self.Cell2PPls = Cell2PPls
       self.out_file_name = OutFileName
示例#23
0
 def clone_to_tumor_phylogeny(self, OriginalNwk, Tu2CloFre, CloSeqLs):
     KeepLs = ['hg19']
     Keep2TuLs = {'hg19': []}
     Align = MegaAlignment()
     CloOr, CloSeq = Align.name2seq(CloSeqLs)
     print Tu2CloFre
     for Tu in Tu2CloFre:
         CloFre = Tu2CloFre[Tu]
         CloLs = []
         for Clo in CloFre:
             if CloFre[Clo] > 0: CloLs.append(Clo)
         LarClo = ''
         LarMut = 0
         for Clo0 in CloLs:
             Seq0 = CloSeq['#' + Clo0]
             MutC = len(Align.GetMutPos(Seq0))
             if MutC > LarMut:
                 LarMut = MutC
                 LarClo = Clo0
             Keep = 'y'
             for Clo1 in CloLs:
                 if Clo0 != Clo1:
                     Seq1 = CloSeq['#' + Clo1]
                     UniMutNum = 0
                     Len = len(Seq1)
                     c = 0
                     while c < Len:
                         if Seq0[c] == 'T' and Seq1[c] == 'A':
                             UniMutNum += 1
                         c += 1
                     Pro = 1.0 * UniMutNum / Len
                     if Pro < 0.05: Keep = 'n'
             if Keep == 'y':
                 if KeepLs.count(Clo0) == 0:
                     KeepLs.append(Clo0)
                     Keep2TuLs[Clo0] = []
                 Keep2TuLs[Clo0].append(Tu)
         #KeepLs.append(LarClo)
         if KeepLs.count(LarClo) == 0:
             KeepLs.append(LarClo)
             Keep2TuLs[LarClo] = []
         Keep2TuLs[LarClo].append(Tu)
     RmLs = []
     for Clo in CloSeq:
         if KeepLs.count(Clo[1:]) == 0: RmLs.append(Clo[1:])
     print 'remove ancestral clones', RmLs
     print 'tumor ls for each clone', Keep2TuLs
     Pruned = self.PruneTree(OriginalNwk, KeepLs)
     Pruned_Root = self.RootTree(Pruned)
     return Pruned_Root, Keep2TuLs
 def __init__(self, seqs_with_ancestor, tsp_list, CNV_info, freq_cutoff,
              ReadCountTable):
     self.CutOff = freq_cutoff
     if seqs_with_ancestor != {}:
         Align = MegaAlignment()
         self.ini_seq_builder = seqs_with_ancestor
         self.ini_clone_order, self.ini_clone_seq = Align.name2seq(
             self.ini_seq_builder)
         self.tsp_list = tsp_list
         self.make_readcount()
         self._CNV_file = CNV_info
         self.ReadCountTable = ReadCountTable
         self.SNVnum = len(ReadCountTable[ReadCountTable.keys()[0]])
         self.CNVnum = len(CNV_info[CNV_info.keys()[0]])
示例#25
0
    def compare_good_posi_number(self, Initial, After, IniSeq_buil,
                                 AftSeq_buil):
        IniCou = self.count_good_posi(Initial)
        AftCou = self.count_good_posi(After)
        Align = MegaAlignment()
        CloLs, IniSeq_dic = Align.name2seq(IniSeq_buil)
        CloLs, AftSeq_dic = Align.name2seq(AftSeq_buil)
        ShareIni = Align.GetSharePosi1(IniSeq_dic, 'A')
        ShareAft = Align.GetSharePosi1(AftSeq_dic, 'A')
        print IniCou, AftCou, len(ShareIni), len(ShareAft)
        if IniCou > AftCou or len(ShareAft) > len(ShareIni): AfterGood = 'n'
        else: AfterGood = 'y'

        return AfterGood
示例#26
0
    def find_new_clone(self, new_seq_buil, old_seq_buil):
        Align = MegaAlignment()
        Ls, New_dic = Align.name2seq(new_seq_buil)
        Ls, Old_dic = Align.name2seq(old_seq_buil)
        #   print 'old list',Old_dic.keys(),	 '\nnew list',New_dic.keys()
        Iden = 'y'
        for Clo in New_dic:
            if Clo != '#hg19':
                NewSeq = New_dic[Clo]
                Redun = Align.find_redundant(NewSeq, Old_dic)
                if Redun == []:
                    Iden = 'n'
                #   print 'new seq',Clo

        return Iden
示例#27
0
    def Compute_PP(self):
        Align = MegaAlignment()	
        tree_analyzer = TreeAnalizer()  
        PP_builder = MegaPP() 		
        Input=self.Tree_rooted
        print 'input for inferring missing',Input
        Meg=self.InMeg
        NameOrder, self.Cell2megSeq=Align.name2seq_with_normal(Meg)
        id = 'All_alignment' 
        status = PP_builder.do_mega_pp(self.InMeg, self.Tree_rooted, id)
        if status == True:
                    self.Cell2PP = PP_builder.retrieve_pp_states() 		

        else:
                    print 'failed to run megaPP'						
示例#28
0
    def adjust_cell_genotype1(self):
        Align = MegaAlignment()
        tree_builder = MegaML()
        tree_analyzer = TreeAnalizer()
        status = tree_builder.do_mega_ml(self.InMeg, 'Noresun')
        if status == True:
            tree1 = tree_builder.newick_trees
        else:
            print('failed to run megaML')
        Tree_Rooted1 = tree_analyzer.RootTree_rootBottom(tree1, 'Normal')

        InferAncestor = MegaAncestor()
        InferAncestor.alignment_file = self.InMeg
        InferAncestor.input_tree_file = Tree_Rooted1

        self.ancestor_states, self.offspring2ancestor, cell2code, self.code2cell = InferAncestor.retrieve_ancestor_states(
        )
        ancestor2offspring, self.node2cellclade = InferAncestor.report_anc2dec_lin(
        )
        for code in self.code2cell:
            if self.code2cell[code].find('Node_') == -1:
                self.node2cellclade[code] = [self.code2cell[code]]

        self.Cellclade_withSupport2SupportCount = self.count_support3()
        self.Clone2CellLs = self.get_clone3()
示例#29
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
示例#30
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