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()
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 __init__(self, cluster_information, original_seq, tumor_seq, tsp_list, clone_frequency_cutoff, CNV_info, ReadCountTable): self.Tu2Cluster = cluster_information self.CNV_info = CNV_info self.ReadCountTable = ReadCountTable Align = MegaAlignment() self.OriAncOrder, self.OriAnc2Seq0 = Align.name2seq(original_seq) self.TOrder, self.T2Seq = Align.name2seq(tumor_seq) self.SharePosi = Align.GetSharePosi1(self.OriAnc2Seq0, 'T') self.all_tsp = tsp_information(tsp_list) self.CloFreCutOff = clone_frequency_cutoff self.v_obs = self.all_tsp.tumor2alt_frequency() identical_seq_list = Align.identify_similar_seq(tumor_seq, 0) self.identical_seq = Align.make_similar_seq_dic(identical_seq_list) self.freq_cutoff = self.CloFreCutOff
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
def BranchDecClone(self, seq_list, clone_frequency, Tu2CNV): Align = MegaAlignment() TumorSampleExtract = tsp_information(self.tsp_list) CloFreAna = CloneFrequencyAnalizer() CloOrder, Clo2Seq = Align.name2seq(seq_list) Align.save_mega_alignment_to_file('Test.meg', seq_list) tree_builder = MegaMP() tree_builder.mao_file = self.mao_file id = 'branchdec_mega_alignment' status = tree_builder.do_mega_mp(seq_list, id) if status == True: seqs_with_ancestor, tree, nade_map, mask_seq, Good_posi_info = tree_builder.alignment_least_back_parallel_muts( True ) # True will execute code to remove redundant seqs (True is default) else: print 'failed to run megaMP' BadPosiLs = [] #multiple mutations BadPosi2ChnageCloLs = {} for c in Good_posi_info: Posi_Inf = Good_posi_info[c] if Posi_Inf != ['Good']: if Posi_Inf[0] == 'ToWild': BadPosiLs.append(c) BadPosi2ChnageCloLs[c] = Posi_Inf[1][0] print 'bad positions', BadPosiLs #,BadPosi2ChnageCloLs if BadPosiLs != []: NewT2C2F = {} NewT2Cls = {} for Tu in clone_frequency: NewC2F = {} single_tsp_list = TumorSampleExtract.make_single_tsp_list(Tu) CloFreDic = clone_frequency[Tu] CNV = Tu2CNV[Tu[2:]] Tu = Tu[2:] TuSeq = self.tumor2seq['#' + Tu] NewCloLs = [] NewCloLs1 = [] for Clo in CloFreDic: #original hit clo for the tumor ChangeOptions = 'n' # print Tu,CloFreDic if CloFreDic[Clo] > 0: CSeq0 = Clo2Seq['#' + Clo] ChangePosi = [] #list to fix multiple mutaitons NewBadPosi = [ ] #remove fixed multiple mutations from BadExtMutPosi for Bad in BadPosi2ChnageCloLs: if BadPosi2ChnageCloLs[Bad].count( '#' + Clo) != 0 and (CNV[Bad] == 'normal' or CNV[Bad] == 'Bad-normal'): Change = 'n' for Oth in CloFreDic: #find multiple mutations at the external branch if Oth != Clo and CloFreDic[Oth] > 0: Soth = Clo2Seq['#' + Oth] if Soth[Bad] == 'T' and BadPosi2ChnageCloLs[ Bad].count('#' + Oth) == 0: Change = 'y' if Change == 'y': ChangePosi.append(Bad) else: NewBadPosi.append(Bad) print 'change positions', Tu, ChangePosi if ChangePosi != []: #fix multiple mutaitons # print 'hhh' CutCloSeq = Align.ModSeq(CSeq0, ChangePosi, 'A', self.Len) NewCloLs.append(Clo + 'Cut' + Tu) NewC2F[Clo + 'Cut' + Tu] = CloFreDic[Clo] Clo2Seq['#' + Clo + 'Cut' + Tu] = CutCloSeq ChangeOptions = 'y' if ChangeOptions == 'n': NewC2F[Clo] = 1 NewT2C2F[Tu] = NewC2F # print Clo2Seq hitseq_align, hitclone_frequency = CloFreAna.ListHitCloAndSeq( NewT2C2F, Clo2Seq) outSeqMaj, outSeqAmb, NewT2C2F = Align.CombSimClo( hitseq_align, hitclone_frequency, 0.0) # print outSeqMaj, NewT2C2F return outSeqMaj, NewT2C2F else: return seq_list, clone_frequency
AnalyzeTree = TreeAnalizer() OutFile = OutputWrite() Align = MegaAlignment() CloFreAna = CloneFrequencyAnalizer() Format = FormatInput() if parser.parse() == False: print(parser.messages) else: tsp_list = parser.get_tumor_sample_profile_list() CNV_information = parser_cnv.get_tumor_cnv_profile(params.cnv_data_file) original_align_builder = FreqToMegaSeq() original_align_builder.initialize( tsp_list, True) #True to remove duplicates; False to keep duplicates num_sites = tsp_list.num_read_counts() all_tsp = tsp_information(tsp_list) v_obs = all_tsp.tumor2alt_frequency() total_read, alt_read, ReadCount_table = all_tsp.tumor2read_count() tumor_seqs = original_align_builder.get_mega_allalignment() initial_seq0 = original_align_builder.get_mega_alignment() initial_seq, A1, A2 = OutFile.ReNameCloFreMeg(initial_seq0, {}, 'number') CNV_information_test = Format.add_low_quality_SNV_info( CNV_information, total_read, alt_read, total_read_cut, mutant_read_cut) print('add initial ancestor') id = 'mega_alignment' # id will be used internally for file names status = tree_builder.do_mega_mp(initial_seq, id) if status != True: print( 'CloneFinder cannot make inferences, because samples do not have evolutionary structure.' ) else: