Exemplo n.º 1
0
    def remove_tumor_and_rename_decomposed(
            self, tumor2seqs_with_decompose, seqs_with_ancestor, tumor_seqs,
            REP, clone_frequency_for_seqs_with_ancestor):
        Align = MegaAlignment()
        SeqOrderIni, IniMeg2Seq = Align.name2seq(seqs_with_ancestor)
        TuLs, TuMeg2Seq = Align.name2seq(tumor_seqs)
        SNVNum = len(TuMeg2Seq[TuLs[0]])
        IdenLs = Align.identify_similar_seq(tumor_seqs, 0)
        Tu2IdenTu = Align.make_similar_seq_dic(IdenLs)
        outAllSeq = ['MEGA', '!Title SNVs;', '!Format datatype=dna;', ' ']
        RmCloLs = []
        for Tu in tumor2seqs_with_decompose:
            DeComCloLs = tumor2seqs_with_decompose[Tu]
            if DeComCloLs != []:
                IdenTu = Tu2IdenTu['T-' + Tu]
                RmCloLs += IdenTu
        RmCloLs = list(set(RmCloLs))
        Done = []
        for Tu in tumor2seqs_with_decompose:
            DeComCloLs = tumor2seqs_with_decompose[Tu]
            if RmCloLs.count(Tu) == 0:
                if Done.count('#' + Tu) == 0:
                    outAllSeq += ['#' + Tu, TuMeg2Seq['#' + Tu]]
                    Done.append('#' + Tu)
            if DeComCloLs != []:
                DecomCloOrder, Clu2Seq = Align.name2seq(DeComCloLs)
                for Clu in Clu2Seq:
                    Seq = Clu2Seq[Clu]
                    TuClu = Clu[1:].split('Clu')[0]
                    Code = TuClu in RmCloLs
                    if Code != True and Clu.find('#Node') == -1:
                        if Clu.find('#Clu') != -1:
                            Clu = '#' + Tu + Clu[1:] + 'REP' + str(REP)
                        if Done.count(Clu) == 0:
                            outAllSeq += [Clu, Seq]
                            Done.append(Clu)
            else:

                HitCloLs = clone_frequency_for_seqs_with_ancestor['T-' + Tu]
                for Clo in HitCloLs:
                    if HitCloLs[Clo] > 0:
                        TuClo = Clo.split('Clu')[0]
                        Code = TuClo in RmCloLs
                        if Code != True and Clo[:4] != 'Node':
                            if Done.count('#' + Clo) == 0:
                                outAllSeq += ['#' + Clo, IniMeg2Seq['#' + Clo]]
                                Done.append('#' + Clo)

        outAllSeq_without_redindant = Align.RmRedunSeq(outAllSeq)
        outAllSeq_without_redindant += ['#hg19', ('A' * SNVNum)]
        return outAllSeq_without_redindant
Exemplo n.º 2
0
    def AdjDecClo(self, ID, SeqLs, NodeMap, BackFor, Tree):
        Align = MegaAlignment()
        Ao, Anc2Seq = Align.name2seq(SeqLs)
        Len = len(Anc2Seq[Ao[0]])
        outNew = ['MEGA', '!Title SNVs;', '!Format datatype=dna;', ' ']

        Clu2Change = {}
        for Name in Anc2Seq:
            if Name.find('Clu') != -1:
                Clu2Change[Name] = {}
        Posi = 0
        while Posi < Len:
            i = BackFor[Posi]
            if i != ['Good']:
                Change = i[0]
                ChangeCloLs = i[1][0]  #list
                #  print i,Posi
                A = i[1][0][0].split('Clu')[0]
                B = i[1][1][0].split('Clu')[0]
                # print A,B
                if (len(i[1][0]) == 1 and len(i[1][1]) == 1
                        and i[1][0][0].find('Clu') == -1
                        and i[1][1][0].find('Clu') != -1):
                    ChangeCloLs = i[1][1]  #list
                    if A == B: ChangeCloLs = i[1][0]
                else:
                    ChangeCloLs = i[1][0]  #list
                    if A == B: ChangeCloLs = i[1][1]
                #print ChangeCloLs
                if Change == 'ToMut':  #BC>0: #back
                    for Clo in ChangeCloLs:
                        # if Clo.find('Clu')!=-1:
                        if Clu2Change.has_key(Clo) != True:
                            Clu2Change[Clo] = {}
                        Clu2Change[Clo][Posi] = 'T'
                if Change == 'ToWild':  #MC>0: #multi
                    for Clo in ChangeCloLs:
                        # if Clo.find('Clu')!=-1:
                        if Clu2Change.has_key(Clo) != True:
                            Clu2Change[Clo] = {}
                        Clu2Change[Clo][Posi] = 'A'

            Posi += 1

    #   print Clu2Change
#     open('AAA','r').readlines()
        for Clo in Anc2Seq:

            if Clo.find('#Node') == -1:
                TreeAna = TreeAnalizer()
                BraLen = TreeAna.Get_branch_lenghth(Tree, Clo[1:])
                #  if Clo.find('Clu')!=-1 and BraLen>=1:
                if BraLen >= 1 and Clu2Change.has_key(Clo):
                    Change = Clu2Change[Clo]

                    CluSeq = Anc2Seq[Clo]
                    Len = len(CluSeq)
                    c = 0
                    NewSeq = ''
                    while c < Len:
                        Code = c in Change
                        if Code == True: NewSeq += Change[c]
                        else: NewSeq += CluSeq[c]
                        c += 1
                    outNew += [Clo, NewSeq]
                else:
                    outNew += [Clo, Anc2Seq[Clo]]
        outNew_without_redundant_seq = Align.RmRedunSeq(outNew)
        outNew_without_redundant_seq += ['#hg19', 'A' * len(Anc2Seq[Clo])]
        #   open('AA','r').readlines()
        return outNew_without_redundant_seq