def main(): d = build_dict() ############################ # TODO: Build a priority queue based on d priority_queue = PriorityQueue() for ch, count in d.items(): tree = Tree(None, ch, None) priority_queue.enqueue((tree, count)) #priority_queue.traversal() ############################ tree = encoding(priority_queue) print(decoding(tree, '1010101101010100010100110100000101010101100111'))
def encoding(pq): """ :param pq: PriorityQueue, containing all the ch we need to encode :return: Tree, a binary tree that has all the ch encoded """ while True: left = pq.dequeue() right = pq.dequeue() new_value = left.value[1] + right.value[1] tree = Tree(left.value[0], new_value, right.value[0]) if pq.length() == 0: return tree else: pq.enqueue((tree, new_value))
(gt_E, gt_D, D, gt_T) = tg.generate() gensNames = list(str(i) for i in range(M)) print(gensNames) C_num = D.shape[1] G_num = D.shape[0] ### Run dl = list(d for d in D) root = [n for n, d in gt_T.in_degree() if d == 0][0] print('ROOT:', root) logfile.write('ROOT:{}\n'.format(root)) T = Tree(gensNames, D, data_list=dl, root=str(root), alpha=alpha, beta=beta, logfile=logfile) T.set_ground_truth(gt_D, gt_E, gt_T=gt_T) T.randomize() for i in range(step_num): if T.next(): break # T.plot_all_results() T.save_mats(prefix_dir) logfile.close() break # except:
edges = [('DNM3', 'ITGAD'), ('ITGAD', 'BTLA'), ('BTLA', 'PAMK3'), ('PAMK3', 'FCHSD2'), ('FCHSD2', 'LSG1'), ('LSG1', 'DCAF8L1'), ('DCAF8L1', 'PIK3CA'), ('PIK3CA', 'CASP3'), ('CASP3', 'TRIM58'), ('TRIM58', 'TCP11'), ('TCP11', 'MARCH11'), ('MARCH11', 'DUSP12'), ('DUSP12', 'PPP2RE'), ('PPP2RE', 'ROPN1B'), ('ROPN1B', 'PITRM1'), ('PITRM1', 'FBN2'), ('FBN2', 'PRDM9'), ('FBN2', 'GPR64'), ('PRDM9', 'CABP2'), ('PRDM9', 'ZEHX4'), ('PRDM9', 'H1ENT'), ('PRDM9', 'WDR16'), ('CABP2', 'TRIB2'), ('ZEHX4', 'DKEZ'), ('WDR16', 'GLCE'), ('GLCE', 'CALD1'), ('CABP2', 'C15orf23'), ('CABP2', 'CNDP1'), ('CNDP1', 'CXXX1'), ('CNDP1', 'c1orf223'), ('CXXX1', 'FUBP3'), ('c1orf223', 'TECTA'), ('GPR64', 'MUTHY'), ('MUTHY', 'SEC11A'), ('SEC11A', 'KIAA1539'), ('SEC11A', 'RABGAP1L'), ('RABGAP1L', 'ZNE318'), ('KIAA1539', 'FGFR2'), ('FGFR2', 'PLXNA2')] dl = list(d for d in D) SNT = Tree(gensNames, D=D, data_list=dl, name='Paper Tree') SNT.set_edges(edges, remove_edges=True) _.print_bold('SCITE Navis\'s Tree Error:', SNT.get_best_error()) SNT.plot_best_T('paper_tree') ### Run dl = list(d for d in D) T = Tree(gensNames, D=D, data_list=dl) # edges = [('PIK3CA', 'c1orf223'),('PIK3CA', 'TCP11'),('DNM3', 'ITGAD'),('TRIM58', 'DUSP12'),('DCAF8L1', 'FCHSD2'),('DCAF8L1', 'GLCE'),('FBN2', 'PPP2RE'),('FCHSD2', 'LSG1'),('CASP3', 'PITRM1'),('CASP3', 'RABGAP1L'),('ITGAD', 'DCAF8L1'),('PPP2RE', 'ROPN1B'),('LSG1', 'PIK3CA'),('ROPN1B', 'MARCH11'),('BTLA', 'FBN2'),('DUSP12', 'BTLA'),('MARCH11', 'CASP3'),('MARCH11', 'CALD1'),('TCP11', 'TRIM58'),('TCP11', 'CNDP1'),('PITRM1', 'PRDM9'),('PITRM1', 'ZEHX4'),('PITRM1', 'MUTHY'),('PITRM1', 'CXXX1'),('PRDM9', 'CABP2'),('PRDM9', 'PAMK3'),('MUTHY', 'FGFR2'),('GPR64', 'TRIB2'),('SEC11A', 'C15orf23'),('SEC11A', 'PLXNA2'),('C15orf23', 'H1ENT'),('DKEZ', 'FUBP3'),('FUBP3', 'WDR16'),('WDR16', 'GPR64'),('RABGAP1L', 'TECTA'),('RABGAP1L', 'ZNE318'),('RABGAP1L', 'KIAA1539'),('RABGAP1L', 'SEC11A'),('GLCE', 'DKEZ')] # T.set_edges(edges, remove_edges=True) T.randomize() T.plot_best_T('sn_initial_tree') # T.set_edges(edges, remove_edges=True) for i in range(10):