
    DUf                     2    d dl Z d dlZ	 	 	 	 	 	 ddZddZdS )	    N      Fc	                    t          | t                    rt          j        |           } t          | j        t                    s|                                 } t          j        t          j        |                    }	|d|                                 z  }d| j        |	|d|z  d|z  d|z  g}
|r|
	                    d           |r|
	                    d           |r|
	                    d	|z             t          j        |
t          j        t          j        
          }|                                \  }}|j        r+t          dd                    |
          d|d|          |S )a  
    Converts a BedTool object to a bigBed format and returns the new filename.

    `x` is a BedTool object

    `genome` is an assembly string

    `output` is the name of the bigBed file to create.

    Other args are passed to bedToBigBed.  In particular, `bedtype` (which
    becomes the "-type=" argument) is automatically handled for you if it is
    kept as the default None.

    Assumes that a recent version of bedToBigBed from UCSC is on the path.
    Nzbed%sbedToBigBedz-blockSize=%sz-itemsPerSlot=%sz-type=%sz-uncz-tabz-as=%sstdoutstderrcmds:  
stderr:
stdout:)
isinstancestr
pybedtoolsBedToolfnsaveaschromsizes_to_file
chromsizesfield_countappend
subprocessPopenPIPEcommunicate
returncode
ValueErrorjoin)xgenomeoutput	blockSizeitemsPerSlotbedtype_asunctabr   cmdspr   r	   s                 V/var/www/html/software/conda/lib/python3.11/site-packages/pybedtools/contrib/bigbed.pybigbedr+      si   4 !S "q!!adC   HHJJ.z/DV/L/LMMJAMMOO+	)#\)WD  F
 F
 $HsN###jojoNNNA]]__NFF| 
j03O
 
 	
 M    c                 H   d| g}||                     d|g           ||                     d|g           ||                     d|g           ||                     d|g           t          j                                        }|                    |           t          j        |t
          j        t
          j                  }|                                \  }}	|j	        r+t          dd                    |          d	|	d
|          t          j        |          S )NbigBedToBedz-chromz-startz-endz	-maxItemsr   r
   r   r   r   )extendr   r   _tmpr   r   r   r   r   r   r   r   )
r   chromstartendmaxItemsr(   outfnr)   r   r	   s
             r*   bigbed_to_bedr6   ?   s   2DXu%&&&Xu%&&&
VSM"""[(+,,,##%%EKKjojoNNNA]]__NFF| 
j03O
 
 	
 e$$$r,   )r   r   NNFF)NNNN)r   r   r+   r6    r,   r*   <module>r8      sd            7 7 7 7t% % % % % %r,   