³ò
È‡-Hc           @   s  d  d k  Z  d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d „  Z d „  Z	 d „  Z
 d „  Z e d j o‘e e  i ƒ d j o! d e  i d	 GHe  i d
 ƒ n e  i d
 Z e	 ƒ  Z e Z e ƒ  Z d Ge e ƒ GHd GHg  Z e D] Z e d e q [ Z e
 e i e e g e ƒ ƒ d GHg  Z e D]- Z e D]  Z e d e e e e e f qPqF[ Z e
 e i e e g e ƒ ƒ d GHg  Z e D]E Z e d d i g  Z e D] Z  e d e  e f qÅ[ ƒ e f q¨[ Z e
 e i e e g e ƒ ƒ n d S(   iÿÿÿÿNc         C   s'   |  GH| p t  i |  d t ƒn d  S(   Nt   shell(   t
   subprocesst   callt   True(   t   cmdt   dryrun(    (    s=   /home2/jsr59/Work/Mappability_Map/new_code/ParallelCompile.pyt   run   s    c          C   sO   t  i d ƒ }  t i d ƒ } g  } | D] } | |  i | ƒ i d ƒ q) ~ S(   Ns   (.+)\.fas   *.fai   (   t   ret   compilet   globt   matcht   group(   t   patt   flt   _[1]t   f(    (    s=   /home2/jsr59/Work/Mappability_Map/new_code/ParallelCompile.pyt   get_fa_basenames	   s    c         C   sZ   t  } x0 |  D]( } | d  j o t } t | ƒ GHq q W| o d GHt i d ƒ n d  S(   Ns   Failure, quittingi   (   t   Falset   NoneR   t   strt   syst   exit(   t   lt   quitt   e(    (    s=   /home2/jsr59/Work/Mappability_Map/new_code/ParallelCompile.pyt
   chkResults   s     c          C   s
  d }  t  i i |  ƒ p t  i |  ƒ n d } d t i ƒ  i d d ƒ } d t  i j ow g  } t t  i d ƒ D] } | | i	 ƒ  qt ~ } t
 i i d t d d	 d
 | d t
 i i d | d |  d | ƒ } n4 t
 i i d t d d	 d
 | d d d |  d | ƒ } | S(   s\   This function sets up the parallel environment, and returns a handle to it, called a sleigh.s&   /home2/jsr59/Work/Mappability_Map/logss*   /home2/jsr59/Work/Mappability_Map/new_codes   JOEL_%s_%%04dt    t   _t   PBS_NODEFILEt   verboset   nwsHosts   bulldogi.wss.yale.edut   wsNameTemplatet   launcht   nodeListt   logDirt
   modulePatht   workerCounti   (   t   ost   patht   isdirt   mkdirt   timet   ctimet   replacet   environt   opent   stript   nwst   sleight   SleighR   t   sshcmd(   t   logdirt
   modulepatht   wsnametemplateR   t   nt   nlt   s(    (    s=   /home2/jsr59/Work/Mappability_Map/new_code/ParallelCompile.pyt   setup_sleigh   s    4	t   __main__i   s   usage %s <merlen>i    i   R8   s$   Step 1, convert each fa file to hashs   chr2hash %s.fas4   Step 2, find counts for cross product of chromosomess3   oligoFindPLFFile %s.fa %s.fa %s 0 0 1 1 > %sx%s.outs   Step 3, merge countss   mergeOligoCounts %s > %sb.outR   s	   %sx%s.out(!   R   R	   R   R   R%   t
   nws.sleighR/   R)   R   R   R   R9   t   __name__t   lent   argvR   t   merlent   fasR   R   R8   R   R   t   fat   jobst   eachElemt   _[2]t   fa2t   fa1t   _[3]t   joint   _[4]R   (    (    (    s=   /home2/jsr59/Work/Mappability_Map/new_code/ParallelCompile.pys   <module>   s,   T			
			%AY