
    DUf                        d dl Z d dlZd dlmZ d dlZddlmZ ddlmZ ddl	m
Z
mZmZmZ ddlmZ dd	lmZmZ dd
lmZ d Z ej                     ej        dd           ej        ddddde           ej        ddde ed          d           ej        ddd           ej        dddd !           ej        d"d#e$           ej        d%d&d'd(           ej        d)d*d+           ej        d,d-ed.           ej        d/d0dd !          d1                                                                                                                                     ZdS )2    N)ceil   )apilock)HIGLASS_TILE_DIMlegacy_zoomifypreferred_sequencezoomify_cooler)parse_cooler_uri   )cli
get_loggerparse_field_paramc                    ddl m } t          t                    }| g } nt          j        |           } |                    d|             |D ]}|dz   t          |          z   }dt          j        |          	                                v r@|
                    d|            	 |                    |g| d           t# t          $ r}|j        }|d	}|d	k    r|Y d }~d }~ww xY wd S )
Nr   balanceBalancing args: z::resolutions/weightz#Balancing zoom level with bin size coolerargs	prog_namer   )r   r   __name__shlexsplitdebugstrr   Coolerbinsinfomain
SystemExitcode)	r   resolutionsoutfilebalance_cmdloggerresurie	exit_codes	            O/var/www/html/software/conda/lib/python3.11/site-packages/cooler/cli/zoomify.pyinvoke_balancer/      s6   //////!!F|{4  
LL*D**+++  ((3s883sz#++----?#??@@@
	3,,(CCCC 	 	 	I 	A~~ ~~~~	 s   'C
C)C$$C)cool_uri	COOL_PATH)metavarz--nprocz-nz-pzcNumber of processes to use for batch processing chunks of pixels [default: 1, i.e. no process pool])helpdefaulttypez--chunksizez-cz*Number of pixels allocated to each processg    cAT)r3   r5   r4   show_defaultz--resolutionsz-rak  Comma-separated list of target resolutions. Use suffixes B or N to specify a progression: B for binary (geometric steps of factor 2), N for nice (geometric steps of factor 10 interleaved with steps of 2 and 5). Examples: 1000B=1000,2000,4000,8000,... 1000N=1000,2000,5000,10000,... 5000N=5000,10000,25000,50000,... 4DN is an alias for 1000,2000,5000N [default: B])r3   z	--balancez3Apply balancing to each zoom level. Off by default.F)r3   is_flagr4   z--balance-argszAdditional arguments to pass to cooler balance. To deal with space ambiguity, use quotes to pass multiple arguments, e.g. ``--balance-args '--nproc 8 --ignore-diags 3'``. Note that nproc for balancing must be specified independently of zoomify arguments.)r3   r5   z
--base-uriz-izAOne or more additional base coolers to aggregate from, if needed.)r3   multiplez--outz-ozOutput file or URIz--fieldzSpecify the names of value columns to merge as '<name>'. Repeat the ``--field`` option for each one. Use '<name>:dtype=<dtype>' to specify the dtype. Include ',agg=<agg>' to specify an aggregation function different from 'sum'.)r3   r5   r8   z--legacyz5Use the legacy layout of integer-labeled zoom levels.c
                 `	   t          t                    }
t          |           \  }}|	|                    dd          }nt          |	          \  }}|
                    d|  d           |
                    d| d           |r?t          | |||t                    \  }}|rdd	lm} |g }nt          j	        |          }|

                    d
|            t          t          |                                                    D ]\  }}|dz   t          |          z   }|t          |          k    r)dt          j        |                                          v rV|
                    d| d|            	 |                    |g|d           # t&          $ r}|j        }|d}|dk    r|Y d}~d}~ww xY wdS dS t          j        |           }|j        j                                        }|j        r,t3          t5          |t6          z                      }|j        }np|                                ddg         dd         }|d         |d         z
                                  }t3          t5          ||z  t6          z                      }d}|d}g |}}d |	                    d          D             D ]4}d|v s
d|v r||k     rt;          j        d           |dk    rt?          ||d          }n|dk    rt?          ||d          }n|dk    rddgt?          d|d          }n|                     d          r:t3          |	                    d          d                   }t?          ||d          }n_|                     d          r:t3          |	                    d          d                   }t?          ||d          }nt3          |          g}|!                    |           6tE          |          r^d |D             }tG          | \  }}} }!t          |          }d  tG          ||           D             } d! tG          ||!          D             }!nd"gdd}!} }tI          | gt          |          ||||t          || |!#	  	         |rtK          |||           dS dS )$zu
    Generate a multi-resolution cooler file by coarsening.

    COOL_PATH : Path to a COOL file or Cooler URI.

    Nz.coolz.mcoolzRecursively aggregating ""zWriting to "r   r   r   r   z::r   zBalancing zoom level z, bin size r   r   r   startendbc                 Z    g | ](}|                                                                 )S  )striplower).0ss     r.   
<listcomp>zzoomify.<locals>.<listcomp>   s*    BBB!AGGIIOO%%BBB    ,nzWMap is already < 256 x 256. Provide resolutions explicitly if you want to coarsen more.nicebinary4dni  i  i  c                 0    g | ]}t          |d           S )F)includes_colnumr   )rB   args     r.   rD   zzoomify.<locals>.<listcomp>   s3          BE!#u===     rE   c                     i | ]
\  }}|||S Nr?   )rB   coldts      r.   
<dictcomp>zzoomify.<locals>.<dictcomp>   s    TTT'#rR^c2^^^rE   c                     i | ]
\  }}|||S rO   r?   )rB   rP   fs      r.   rR   zzoomify.<locals>.<dictcomp>   s    KKKfc1Q]3]]]rE   count)nprocr   columnsdtypesagg)&r   r   r   replacer"   r	   r   r   r   r   r   reversedlistitemsr   r   r    r!   r#   r$   r%   
chromsizesvaluessumbinsizeintr   r   meanwarningswarnr
   endswithextendlenzipr   r/   )"r0   rV   	chunksizer&   r   balance_argsfieldlegacybase_urioutr)   infile_r'   n_zoomszoom_levelsr(   levelr*   r+   r,   r-   clrgenome_lengthmaxrescurresr!   mean_fragsizerstringrfield_specifiersrW   rX   rY   s"                                     r.   zoomifyr}   1   sm   f !!F **IFA
{..(33%c**

KK7H777888
KK)w)))*** g?-guid 
  
  
  	 777777#!${<88LL:L::;;;&tK,=,=,?,?'@'@AA    
sns5zz1CLL((3:c??#7#7#9#999 KEKKcKKLLL
 $$3*>*>($SSSS!       !I ($%	 A~~ &~~~~ #	  	    & j""-1133 ; 	m.>>??@@F[FF88::w./2D!%[4=8>>@@Mmm;>NNOOPPFF K  ";WBBw}}S/A/ABBB 	" 	"CczzSCZZFVOO>   czz&vvv>>&vvx@@4K"4T66"J"JKc"" #))C..+,,&sFF;;c"" #))C..+,,&sFH==XXJq!!!!u:: 	9   IN      '*+;&<#GQ7mmGTTS&-A-ATTTFKKGS(9(9KKKCC %,9dDSVG 	'X'
	
 
	
 
	
 
	
  	?<g>>>>>	? 	?s   =F
F?"F::F?)r   rd   mathr   click r   parallelr   reducer   r	   r
   r   utilr   r   r   _utilr   r/   commandargumentoptionrb   r   r}   r?   rE   r.   <module>r      s                                   $ # # # # #         $ $ $ $ $ $  : 
K000
)	   	5	CII   
	 	 	 	>	   
J 
   	L	   gt"6777
L 
   	@	  D? D?   87   	 	   10 BD? D? D?rE   