Esempio n. 1
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
Esempio n. 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