
    DUff                     v   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d dlZd dlZd dl	Z	d dl
Z	d dlZ		 d dlZn# e$ r Y nw xY wddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dZi Zd5d
Zd Zd5dZd6dZd Z G d de          Z G d de          Z G d de          Zd Z d Z!d Z"d Z#d Z$d Z%d Z&d Z'd7dZ(d Z)	 	 	 	 	 d8d!Z*d" Z+d# Z,d$ Z-d% Z.d dlZ ej/        d&ej0                  Z1d' Z2 G d( d)e3          Z4 G d* d+e3          Z5d9d,Z6	 	 	 	 	 d:d0Z7d;d1Z8	 d;d2Z9d3 Z:d4 Z; ej<        e(           dS )<    N   )settings)	filenames)genome_registry)logger)create_interval_from_list c                 <    ddl m} |                    |            dS )aY  
    Explicitly set path to `BEDTools` installation dir.

    If BEDTools is not available on your system path, specify the path to the
    dir containing the BEDTools executables (intersectBed, subtractBed, etc)
    with this function.

    To reset and use the default system path, call this function with no
    arguments or use path="".
    r   pathsN)r
   r   _set_bedtools_pathpathr   s     O/var/www/html/software/conda/lib/python3.11/site-packages/pybedtools/helpers.pyset_bedtools_pathr      s0     	T"""""    c                  6    ddl m}  |                                 S )z4
    Returns the currently-set path to bedtools
    r   r   )r
   r   _get_bedtools_pathr   s    r   get_bedtools_pathr   .   s(     ##%%%r   c                 <    ddl m} |                    |            dS )z
    Explicitly set path to `R` installation dir.

    If R is not available on the path, then it can be explicitly
    specified here.

    Use path="" to reset to default system path.
    r   r   N)r
   r   _set_R_pathr   s     r   
set_R_pathr   7   s0     	dr   Fc                    t           j        r| sdS t          t           j                  dk    s| r	 t	          j        t          j                            t           j	        d          dg          
                    d                                          }|rt          d|z             dt           _        ||}t          j        d|          }|s"t          d	                    |                    |                    d
          }d |                    d          D             t           _        t           j        d         dk    ot           j        d
         dk    t           _        t           j        d         dk    ot           j        d
         dk    t           _        dS # t          j        $ r1 t           j	        rdt           j	        z  }nd}t-          d|z            w xY wdS )z
    Checks installation as well as version (based on whether or not "bedtools
    intersect" works, or just "intersectBed")
    Tr   bedtools	--versionzutf-8zFound bedtools version '%s'Nz^bedtools [^0-9]*([0-9][0-9.]*)z(Cannot identify version number from "{}"r   c                 ,    g | ]}t          |          S  )int.0is     r   
<listcomp>z'_check_for_bedtools.<locals>.<listcomp>h   s    (G(G(GAQ(G(G(Gr   .         (tried path '%s')r
   zmPlease make sure you have installed BEDTools(https://github.com/arq5x/bedtools) and that it's on the path. %s)r   _bedtools_installedlenbedtools_version
subprocesscheck_outputosr   join_bedtools_pathdecoderstripprintresearch
ValueErrorformatgroupsplit_v_2_27_plus_v_2_15_plusCalledProcessErrorOSError)force_checkverboseoverridevmvvadd_msgs          r   _check_for_bedtoolsrE   E   s   
 # K tH%&&!+++-	'W\\("9:FFT     93a7888+/H( #
 	;Q??A W !K!R!RST!U!UVVVB(G(G#(G(G(GH% )!,1Xh6OPQ6RVX6X !
 )!,1Xh6OPQ6RVX6X !!! , 		 		 		& -0GG')01  		K 	,+s   E*F A Gc                  F   	 t          j        t          j                            t
          j        d          dgt           j        t           j                  } dt
          _        d S # t          $ r1 t
          j        rdt
          j        z  }nd}t          d|z            w xY w)NRr   )stdoutstderrTr(   r
   z1Please install R and ensure it is on your path %s)r,   Popenr.   r   r/   r   _R_pathPIPE_R_installedr=   r6   )prD   s     r   _check_for_RrO   ~   s    XW\\(*C00+>??
 
 

 !% X X X 	)H,<<GGGLwVWWWXs   A!A% %;B c                       e Zd ZdZdS )Errorz'Base class for this module's exceptionsN)__name__
__module____qualname____doc__r   r   r   rQ   rQ      s        11Dr   rQ   c                       e Zd ZdS )pybedtoolsErrorN)rR   rS   rT   r   r   r   rW   rW      s        Dr   rW   c                       e Zd Zd Zd ZdS )BEDToolsErrorc                 V    t          |          | _        t          |          | _        d S N)strcmdmsg)selfr]   r^   s      r   __init__zBEDToolsError.__init__   s     s88s88r   c                 6    d| j         z   dz   dz   | j        z   }|S )Nz
Command was:

	
z
Error message was:
)r]   r^   )r_   rB   s     r   __str__zBEDToolsError.__str__   s9    "h '' h	 	
 r   N)rR   rS   rT   r`   rc   r   r   r   rY   rY      s2              r   rY   c                     t          | d          5 }|                    d          }|dk    r	 d d d            dS 	 d d d            n# 1 swxY w Y   dS )Nrb   s   TF)openread)fnfstarts      r   isGZIPrl      s    	b$ 1q		O##       #               5s   AAAc                 H   t          | d          5 }|                    d          }ddd           n# 1 swxY w Y   t          |          dk     rdS t          j        d|          }|\  }}}}}}	}
}}}}|dk    r&|dk    r |dk    r|d	k    r|d
k    r|dk    r|dk    rdS dS )z@
    Reads a filename to see if it's a BGZIPed file or not.
    re   r'   NFBBBBiBBHBBB            B   C   r%   T)rg   rh   r*   structunpack_from)ri   fh
header_strheaderid1id2cmflgmtimexflos_xlensi1si2slens                  r   isBGZIPr      s    
b$ !2WWR[[
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! :uz::F?E<Cb#uc3c3	CZZ1WWAXXBYYBYYQYYt5s   377c                    t          j        | d          5 }t          |           r9|                    d                                          dk    r	 ddd           dS ddd           n# 1 swxY w Y   t          |           rdS dS )z
    Returns True if the file is both BGZIPed and the compressed contents have
    start with the magic number `BAM\x01`, or if the file is CRAM format (see
    isCRAM()).
    re   rr   zBAMNT)gziprg   r   rh   r1   isCRAMri   in_s     r   isBAMr      s     
2t		 2;; 	CHHQKK..00I==                       bzz t s   <A++A/2A/c                     t          | d          5 }|                    d                              d          dk    r	 ddd           dS 	 ddd           dS # 1 swxY w Y   dS )zS
    Returns True if the file starts with the bytes for the characters "CRAM".
    re   rr   ignore)errorsCRAMNT)rg   rh   r1   r   s     r   r   r      s     
b$ 388A;;X..&88       8                 s   /AA"Ac                     t                                           D ]%\  }}	 |j        | k    r|c S # t          $ r Y "w xY wt	          d| z            )zx
    Returns the bedtool object with tagged with *tag*.  Useful for tracking
    down bedtools you made previously.
    ztag "%s" not found)_tagsitems_tagAttributeErrorr6   )tagkeyitems      r   find_taggedr      ss    
 [[]]  	T	yC   	 	 	D	
)C/
0
00s   0
==c                     d}|rYd}g }| D ]D}t          |t                    r|                    |           d}/|                    |           E|}|d d          } |Y| S )NTF)
isinstancelistextendappend)xnestedcheck_again	flattenedelements        r   _flatten_listr      s    F
 	 	* 	*G'4(( *  )))"  ))))aaaL   Hr   c                     t           j                            |           sd| z  }t          |          | t          _        dS )z
    Set the directory for temp files.

    Useful for clusters that use a /scratch partition rather than a /tmp dir.
    Convenience function to simply set tempfile.tempdir.
    z-The tempdir you specified, %s, does not existN)r.   r   existsFileNotFoundErrortempfiletempdir)r   errstrs     r   set_tempdirr     s@     7>>'"" (@7J'''Hr   c                  (    t          j                    S )z2
    Gets the current tempdir for the module.
    )r   
gettempdirr   r   r   get_tempdirr     s        r   c                    t           j        rdS t          j        D ]G}| rt	          d|           t
          j                            |          rt          j        |           H|rWt          j	        t
          j        
                    t                      d                    }|D ]}t          j        |           dS dS )z
    Deletes all temp files from the current session (or optionally *all*             sessions)

    If *verbose*, reports what it's doing

    If *remove_all*, then ALL files matching "pybedtools.*.tmp" in the temp dir
    will be deleted.
    Nremovingzpybedtools.*.tmp)r   KEEP_TEMPFILESr   	TEMPFILESr3   r.   r   r   unlinkglobr/   r   )r?   
remove_allri   fnss       r   cleanupr     s      !   	"*b!!!7>>" 	IbMMM i[]]4FGGHH 	 	BIbMMMM 	 	r   c                 4   t           j        st                       t           j        s| gS 	 t           j        |          } n0# t
          $ r# | t           j        v r	 t          | | dz             w xY wt          j	        
                    t           j        d          | gS )Nz!not a recognized BEDTools programr   )r   r)   rE   r;   _prog_namesKeyError
_new_namesrY   r.   r   r/   r0   )	prog_names    r   _version_2_15_plus_namesr   -  s    '   {X(3		 X X X+++Iy3V'VWWWX GLL0*==yIIs	   > -A+Tc                 `   |du}|du }| dd         }g } |                      t          |d                              |                      |dd                    	 |r|rt          j        d           t          j        dd                    |                      t          j        | t
          j        t
          j        t
          j        t                    }	|r2|D ].}
|	j	        
                    |
                                           /n|D ]}
|	j	        
                    |
           |	j	                                         |rd |	j        D             }nd	 |	j        D             }d}|r|st          j        d
           t          j        dd                    |                      t          |d          }t          j        | |t
          j        t
          j        t                    }	t          |d          r+|	                    |                                          \  }}nH|D ].}|	j	        
                    |                                           /|	                                \  }}|}|                                 |s|rt          j        d           t          j        dd                    |                      t          j        | t
          j        t
          j        t                    }	|rd |	j        D             }nd |	j        D             }d}|s|st          j        d|           t%          t'          t(          |                     } t          j        dd                    |                      t          |d          }t          j        | |t
          j        t                    }	|	                                \  }}|}|                                 |Vt+          |t,                    r|                    d          } ||          r!t0          j        
                    |           d}|rt+          |t,                    r|                    d          }t5          |          dk    r>d|dd                                         v r t0          j        
                    |           n"t9          t          j        |           |          n# t<          t>          f$ r}tA          tC          |          dtE          j#        |j$                             tA          dt          j        |           z             dd|z  fddd}tA          d           tA          dd                    ||j$                           z              t=          d          d}~ww xY w|S )a  
    Use subprocess.Popen to call BEDTools and catch any errors.

    Output goes to *tmpfn*, or, if None, output stays in subprocess.PIPE and
    can be iterated over.

    *stdin* is an optional file-like object that will be sent to
    subprocess.Popen.

    Prints some useful help upon getting common errors.

    *check_stderr* is a function that takes the stderr string as input and
    returns True if it's OK (that is, it's not really an error).  This is
    needed, e.g., for calling fastaFromBed which will report that it has to
    make a .fai for a fasta file.

    *decode_output* should be set to False when you are iterating over a BAM
    file, where the data represent binary rather than text data.
    Nr   r   z:helpers.call_bedtools(): input is stream, output is streamz helpers.call_bedtools(): cmds=%s )rH   rI   stdinbufsizec              3   @   K   | ]}|                     d           V  dS UTF-8Nr1   r    s     r   	<genexpr>z call_bedtools.<locals>.<genexpr>w  .      >>!((7++>>>>>>r   c              3      K   | ]}|V  d S r[   r   r    s     r   r   z call_bedtools.<locals>.<genexpr>y  "      ..!......r   z8helpers.call_bedtools(): input is stream, output is filewbrh   z<helpers.call_bedtools(): input is filename, output is streamrH   rI   r   c              3   @   K   | ]}|                     d           V  dS r   r   r    s     r   r   z call_bedtools.<locals>.<genexpr>  r   r   c              3      K   | ]}|V  d S r[   r   r    s     r   r   z call_bedtools.<locals>.<genexpr>  r   r   zChelpers.call_bedtools(): input is filename, output is filename (%s)UTF_8   WARNINGz: zThe command was:

	%s
)z&* Did you spell the command correctly?z1* Do you have BEDTools installed and on the path?z<* Do you have permission to write to the output file ("%s")?)zM* Too many files open -- please submit a bug report so that this can be fixed)z* Broken pipe -- if you passed a BedTool object that was created using a generator function, please try saving it to disk first using the .saveas() method before calling this bedtools command. See issue #49 for more.)r%             zThings to check:z
	z*See above for commands that gave the error)%r   r   r   debugr/   r,   rJ   rL   BUFSIZEr   writeencodecloserH   rg   hasattrcommunicaterh   r   mapr\   r   bytesr1   sysrI   r*   upperrY   list2cmdliner=   IOErrorr3   typer.   strerrorerrno)cmdstmpfnr   check_stderrdecode_outputencode_inputinput_is_streamoutput_is_stream
_orig_cmdsrN   lineoutputrI   outfilerH   r   errproblemss                     r   call_bedtoolsr   ;  s   6 4'O}aaaJDKK(A77888KK
122HD 	/ 	LO   L;SXXd^^LLL !! o  A  (! 1 1DGMM$++--00001 " ( (DGMM$'''' GMMOOO />>QX>>>..QX...F  	#3 	LSTTTL;SXXd^^LLL5$''G ! o  A uf%% 1!"uzz||!<!<! 1 1DGMM$++--0000!"FMMOOO  	#3 	LQ   L;SXXd^^LLL Z_Z_g  A  />>QX>>>..QX...F  	'7 	L#  
 C''DL;SXXd^^LLL5$''G WZ_g  A ]]__NFFFMMOOO
 #&%(( 0w//|F## 
  ((( 	K &%(( 0w//6{{RI1B1B1D1D$D$D
  ((((#J$;D$A$A6JJJW D D D$s))))R[%;%;%;<===*Z-DT-J-JJKKK
-/45
 
, 	 !!!fv{{8CI#6777888BCCC9D< Ms   RS   V+1B5V&&V+c                     t          | t                    r|                     d          } |                     d          rdS |                     d          rdS dS )zj
    If stderr created by fastaFromBed starts with 'index file', then don't
    consider it an error.
    r   z
index fileTr   F)r   r   r1   
startswith)r   s    r   _check_sequence_stderrr     s^    
 !U HHW||L!! t||I t5r   c                 V    t          |                     |||||dd|                    S )z
    Helper function that list-ifies the output from randomintersection, s.t.
    it can be pickled across a multiprocess Pool.
    FN)intersect_kwargsshuffle_kwargsreport_iterationsr   	processes_orig_processes)r   randomintersection)_selfother
iterationsr   r   r   r   r   s           r   _call_randomintersectr     sF       -)/+ 	! 		
 		
  r   c                  <   | D ]}t          |j        t                    rt          j        |j                   n.t          |j        d          r|j                                         t          |j        d          r|j                            t                     dS )zw
    Single function that can be used to get rid of a BedTool, whether it's a
    streaming or file-based version.
    r   throwN)	r   ri   r\   r.   r   r   r   r   StopIteration)argsr   s     r   close_or_deleter    s    
  & &adC   	IadOOOOQT7## 	DJJLLL14!! 	&DJJ}%%%& &r   c            	         t          j                    } t          j        ddddt	          |           g          }d}|                                D ]/}|dd                                          r|d         dk    r|dz  }0|S )Nlsofz-wz-Ffz-pr   r   rj   )r.   getpidr,   r-   r\   
splitlinesisdigit)pidprocsnprocsr"   s       r   
n_open_fdsr  #  s    
)++C#VT5$C$IJJEF  QRR5==?? 	qts{{aKFMr   zT
    (?P<chrom>.+):
    (?P<start>\d+)-
    (?P<stop>\d+)
    (?:\[(?P<strand>.)\])?c           
         t          | t                    rt                              |           }|                    d          rat          |                    d          |                    d          |                    d          dd|                    d          g          S t          |                    d          |                    d          |                    d          g          S | S )z
    Convert string of the form "chrom:start-stop" or "chrom:start-stop[strand]"
    to an interval.

    Assumes zero-based coords.

    If it's already an interval, then return it as-is.
    strandchromrk   stopr$   0)r   r\   coord_rer5   r8   r   )srB   s     r   string_to_intervalr  9  s     !S OOA778 	,GGG$$GGG$$GGFOOGGH%%	 	 	 -!!1777#3#3QWWV__E   Hr   c                        e Zd Zd Zd Zd ZdS )FisherOutputc                    t          |t                    r!t          |                                          }t	          |d          rd                    d |D                       }ddddddd}|| _        |                                }|D ]}d|v r\|                                	                    d          \  }}}}t          |          |d         d	<   t          |          |d         d
<   d|v r\|                                	                    d          \  }}}}t          |          |d         d	<   t          |          |d         d
<   || _        |d         	                                \  }	}
}}t          |	          | _        t          |
          | _        t          |          | _        t          |          | _        dS )a  
        fisher returns text results like::

            # Contingency Table
            #_________________________________________
            #           | not in -b    | in -b        |
            # not in -a | 3137160615   | 503          |
            #     in -a | 100          | 46           |
            #_________________________________________
            # p-values for fisher's exact test
            left	right	two-tail	ratio
            1.00000	0.00000	0.00000	2868973.922

        nextr
   c              3      K   | ]}|V  d S r[   r   r    s     r   r   z(FisherOutput.__init__.<locals>.<genexpr>i  s      ~~a~~~~~~r   N)	not in -bin -b)	not in -ain -ar  |r  r  z	    in -ar  r	   )r   r\   rg   rh   r   r/   textr  stripr9   r   tablefloat	left_tail
right_tailtwo_tailratio)r_   r  kwargsr!  linesr"   _in_bnot_in_bleftrightr%  r&  s                r   r`   zFisherOutput.__init__W  s    a 	QA1f 	&~~1~~~%%A'+d;;#'$77
 
 	 		4 		4Aa'(wwyys';';$4125h--k";/.1$iik"7+a'(wwyys';';$41.1(mmg{+*-d))gw'
',Ry'8'8$eXut,,h5\\


r   c                     | j         S r[   )r  r_   s    r   rc   zFisherOutput.__str__  s
    yr   c                 P    d| j         j        dt          |           d| j        S )N<z at z>
)	__class__rR   idr  r/  s    r   __repr__zFisherOutput.__repr__  s*     #'>#:#:#:BtHHHHdiiPPr   N)rR   rS   rT   r`   rc   r4  r   r   r   r  r  V  sG        (" (" ("T  Q Q Q Q Qr   r  c                       e Zd Zd ZdS )SplitOutputc                    ddl m} t          |t                    r!t	          |                                          }t          |d          rd                    d |D                       }|| _        g | _	        g | _
        g | _        g | _        |                                D ]}|                                }| j
                            |d                    | j                            t!          |d                              | j                            t!          |d                              | j	                             ||d                              dS )	a)  
        Handles output from bedtools split, which sends a report of files to
        stdout. This class parses that list into something more convenient to
        use within pybedtools.

        Most useful is probably the .bedtools attribute, which is a list of
        BedTool objects.
        r   )BedToolr  r
   c              3      K   | ]}|V  d S r[   r   r    s     r   r   z'SplitOutput.__init__.<locals>.<genexpr>  s"      //1Q//////r   r   r%   N)bedtoolr8  r   r\   rg   rh   r   r/   r  r   filesnbasescountsr  r9   r   r   )r_   r   r'  r8  r   tokss         r   r`   zSplitOutput.__init__  sQ    	%$$$$$fc"" 	)&\\&&((F66"" 	0WW///////F 	  
  %%'' 	3 	3D::<<DJd1g&&&Ks47||,,,Ks47||,,,M  a!1!12222	3 	3r   N)rR   rS   rT   r`   r   r   r   r6  r6    s#        $3 $3 $3 $3 $3r   r6  c                     	 t           j                            d|           }dS # t           j        j        $ r
}Y d }~nd }~ww xY wdS )Nzhttp://genome.ucsc.edutimeoutTF)urllibrequesturlopenerrorURLError)rA  responser   s      r   internet_onrH    s[    >))*BG)TTt<    5s   !% AAmysqlfetchChromSizesgenome-mysql.cse.ucsc.educ                    t          |          st          d          |dd|z   ddd| z  g}g }i }	 t          j        |t          j        t          j        t
                    }	|	                                \  }
}|r?t          |           t          d	           t          t          j        |                     |
	                                d
d         }|D ]W}t          |t                    r|                    d          }|                                \  }}dt          |          f||<   X|t          ||           nL# t           $ r?}|j        dk    r)|                    d                    |                     n Y d}~nd}~ww xY w	 || g}t          j        |t          j        t          j        t
                    }	|	                                \  }
}|rPdt)          |          vr?t          |           t          d	           t          t          j        |                     |
	                                }|D ]W}t          |t                    r|                    d          }|                                \  }}dt          |          f||<   X|t          ||           n7# t           $ r*}|j        dk    r|                    d           Y d}~nd}~ww xY w|st!          |          |S )a  
    Download chrom size info for *genome* from UCSC and returns the dictionary.

    Parameters
    ----------

    genome : str
        Name of the genome assembly (e.g., "hg38")

    saveas : str
        Filename to save output to. Dictionary will still be returned.

    mysql, fetchchromsizes : str
        Paths to MySQL and fetchChromSizes.

    timeout : float
        How long to wait for a response; mostly used for testing.

    host_url : str
        URL of UCSC mirror MySQL server.
    r@  zVIt appears you don't have an internet connection -- unable to get chromsizes from UCSCz--user=genomez--host=z-Az-ez$select chrom, size from %s.chromInfor   zCommands were:
r   Nr   r   r%   zCan't find mysql at path {0}zINFO: trying WGETz"Can't find path to fetchChromsizes)rH  r6   r,   rJ   rL   r   r   r3   r   r  r   r   r1   r9   r   chromsizes_to_filer=   r   r   r7   r\   )genomesaveasrI  fetchchromsizesrA  host_urlr   failuresdrN   rH   rI   r(  r   r  sizer   s                    r   get_chromsizes_from_ucscrU    s8   : w''' 
4
 
 	

 	H.7D H
A'
 
 
  	3&MMM$%%%:*400222!!##ABB' 	& 	&D$&& ,{{7++**,,KE43t99~AeHHq&)))   9>>OO:AA%HHIIII JIIII
B('
 
 
  	7"#f++55f()))z.t44666!!## 	& 	&D$&& ,{{7++**,,KE43t99~AeHHq&))) B B B9>>OO@AAAB   hHs1   DE 
F5F		FDJ1 1
K%; K  K%c                    |?t          j        ddd          }|j        }t          j                            |           |}t          | t                    rt          |           } t          |d          }| 
                                D ]8\  }}|dz   t          |d                   z   d	z   }|                    |           9|                                 |S )
z
    Converts a *chromsizes* dictionary to a file.  If *fn* is None, then a
    tempfile is created (which can be deleted with pybedtools.cleanup()).

    Returns the filename.
    Nzpybedtools.z.tmpF)prefixsuffixdeletewt	r   rb   )r   NamedTemporaryFilenamer   r   r   r   r\   
chromsizesrg   r   r   r   )chrom_sizesri   r   foutr  boundsr   s          r   rM  rM    s     
z+ 
 
 
 
""5)))+s## . --D>>D$**,,  vt|c&)nn,t3

4JJLLLIr   c                 D   dt           j        vrdS i }	 t          j        |           }t	          |d          sdS t          |j                  D ]-}|                                \  }}dt          |          f||<   .|t          ||           n# t          $ r Y dS w xY w|S )a  
    Get chrom size info for *genome* from genomepy, if genomepy is installed.

    Parameters
    ----------

    genome : str
        Name of the genome assembly (e.g., "hg38")

    saveas : str
        Filename to save output to. Dictionary will still be returned.
    genomepyN
sizes_filer   )r   modulesrc  Genomer   rg   rd  r9   r   rM  r   )rN  rO  rS  gr   r  rT  s          r   get_chromsizes_from_genomepyrh  5  s     $$t
AOF##q,'' 	4&& 	& 	&D**,,KE43t99~AeHHq&)))   tt Hs   $B AB 
BBc                     	 t          t          |           S # t          $ r' t          |           }|t	          |           cY S |cY S w xY w)a|  
    Looks for a *genome* already included in the genome registry; if not found
    it first tries to look it up via genomepy. If genomepy is not installed, or
    if this lookup fails then it looks it up on UCSC.  Returns the dictionary of
    chromsize tuples where each tuple has (start,stop).

    Chromsizes are described as (start, stop) tuples to allow randomization
    within specified regions; e. g., you can make a chromsizes dictionary that
    represents the extent of a tiling array.

    Example usage:

        >>> dm3_chromsizes = chromsizes('dm3')
        >>> for i in sorted(dm3_chromsizes.items()):
        ...     print(i)
        ('chr2L', (0, 23011544))
        ('chr2LHet', (0, 368872))
        ('chr2R', (0, 21146708))
        ('chr2RHet', (0, 3288761))
        ('chr3L', (0, 24543557))
        ('chr3LHet', (0, 2555491))
        ('chr3R', (0, 27905053))
        ('chr3RHet', (0, 2517507))
        ('chr4', (0, 1351857))
        ('chrM', (0, 19517))
        ('chrU', (0, 10049037))
        ('chrUextra', (0, 29004656))
        ('chrX', (0, 22422827))
        ('chrXHet', (0, 204112))
        ('chrYHet', (0, 347038))


    )getattrr   r   rh  rU  )rN  r^  s     r   r^  r^  Y  sf    D///   1&99
+F33333s    *AAAc                     t           j                            t           j                            t           j                            t
                                        } | t           j                            | d          gS )zE
    Returns a list of include directories with BEDTools headers
    include)r.   r   abspathr/   dirname__file__)rn  s    r   get_includesrp    sN     goobgll27??8+D+DEEFFGRW\\'95566r   )r
   )FFN)FF)NNNTT)r   )NrI  rJ  NrK  r[   )=r   r.   r   r   r,   r   ru   atexitr4   rB  urllib.errorurllib.requestrc  ImportErrorr
   r   r   r   r   	cbedtoolsr   r   r   r   r   r   rE   rO   	ExceptionrQ   rW   rY   rl   r   r   r   r   r   r   r   r   r   r   r   r   r  r  compileVERBOSEr  r  objectr  r6  rH  rU  rM  rh  r^  rp  registerr   r   r   <module>r{     s,   



 				          				         	OOOO 	 	 	D	                         0 0 0 0 0 0

# # # # & & &   6 6 6 6rX X X 	 	 	 	 	I 	 	 		 	 	 	 	e 	 	 	    E        4     1 1 1  "
 
 
! ! !   .J J J  
m m m m`    8& & &   
			2:
 J   :/Q /Q /Q /Q /Q6 /Q /Q /Qd%3 %3 %3 %3 %3& %3 %3 %3P    
%(a a a aH   2 ! ! ! !H) ) )X7 7 7      s   7 ??