3
y^                 @   sl   d dl mZmZmZmZ d dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZejeZG dd dZdS )    )absolute_importdivisionprint_functionunicode_literalsNc               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
Compact_graph_prunerc             C   s   d S )N )selfr   r   X/broad/hptmp/bhaas/trinityrnaseq/Analysis/SuperTranscripts/pylib/Compact_graph_pruner.py__init__   s    zCompact_graph_pruner.__init__c             C   sL   |j  }x>|D ]6}|j rt|j |krtjdj| |j| qW d S )Nz9Compact_graph_pruner.remove_burrs - pruning burr node: {})get_all_nodesis_burrlenget_seqloggerdebugformat
prune_node)r   tgraphmax_burr_lengthnodesnoder   r   r	   remove_burrs   s
    
z!Compact_graph_pruner.remove_burrsc             C   sL   | j ||}x:|D ]2}|j }x$|D ]}|j|j  |j| q$W qW dS )a  
        bubble structure:

             X1
            /          ---A    B--
            \  /
             X2


        keep X1 or X2, ideally based on which is in a more highly expressed isoform structure.

        A node in a bubble is defined as:
        - has single parent and single child
        - the parents of child(A) and the children of the parent(B) are identical. (simple bubble structure)
        
        N)_get_bubblespopadd_transcriptsget_transcriptsr   )r   r   max_bubble_node_lengthbubble_node_listsZbubble_node_list	repr_nodeZsister_bubble_noder   r   r	   pop_small_bubbles&   s    

z&Compact_graph_pruner.pop_small_bubblesc             C   sf  t jd t }t }xH|j D ]:}||kr2q"t|j dkrDq"t|j dkrVq"|j j }|j j }|j |j @ }t|dk rq"t }	xL|D ]D}
t|
j dkrqt|
j dkrqt|
j	 |krq|	j
|
 qW t|	dk rq"t jdj||	| d}x|	D ]}||krd}qW |r,q"x&|	D ]}d||< t jdj| q2W |j
|	 q"W |S )Nz$Compact_graph_pruner::_get_bubbles()      zFound bubble: {} -- {} -- {}FTzGCompact_graph_pruner::_get_bubbles(): node {} identifed within a bubble)r   r   listdictr   r   get_prev_nodesget_next_nodesr   r   appendr   )r   r   r   r   Znode_found_in_bubbler   Zchild_node_AZparent_node_BZbubble_nodesZselected_bubble_nodesZbubble_nodeZseen_bubble_node_alreadyZselected_bubble_noder   r   r	   r   F   sL    





z!Compact_graph_pruner._get_bubblesN)__name__
__module____qualname__r
   r   r   r   r   r   r   r	   r      s    r   )
__future__r   r   r   r   ossysreloggingTGraphTNodeTGLOBALS	getLoggerr'   r   r   r   r   r   r	   <module>   s   
