@follows( dedup )
@files( [ (("%s/bam/%s.norm.bam" % (x, x.asFile()), "%s/bam/%s.norm.bam" % (getControl(x), getControl(x).asFile())), 
           "%s/zinba/%s.peaks" % (x, x.asFile()) ) for x in TRACKS ] )
def runZinba( infiles, outfile ):
    infile, controlfile = infiles
    to_cluster = False

    track = P.snip( os.path.basename(infile), ".norm.bam" )
    control = P.snip( os.path.basename(controlfile), ".norm.bam" )
    inputdir = os.path.dirname(outfile)
    frag_len = PARAMS['zinba_fragment_size']
    mappability = PARAMS['zinba_mappability']
    genome = PARAMS['zinba_genome']

    try: os.mkdir( track )
    except OSError: pass
    try: os.mkdir( '''%(track)s/zinba''' % locals() )
    except OSError: pass
    try: os.mkdir( '''%(track)s/zinba/map_ext%(frag_len)s''' % locals() )
    except OSError: pass

    # convert bam to bed
    statement = '''bamToBed -i %(infile)s > %(track)s/zinba/%(track)s.bed; 
                   bamToBed -i %(controlfile)s > %(track)s/zinba/%(control)s.bed; '''
    P.run()

    # Run Zinba
    R.library( 'zinba' )
    R( '''generateAlignability( mapdir='%(mappability)s', outdir='%(track)s/zinba/map_ext%(frag_len)s', athresh=1, extension=%(frag_len)s, twoBitFile='%(genome)s' )''' % locals() )
    R( '''basealigncount( inputfile='%(track)s/zinba/%(track)s.bed', outputfile='%(track)s/zinba/%(track)s.basecount', extension=%(frag_len)s, filetype='bed', twoBitFile='%(genome)s' )'''  % locals() )
    R( '''zinba( refinepeaks=1, seq='%(track)s/zinba/%(track)s.bed', input='%(track)s/zinba/%(control)s.bed', filetype='bed',  align='%(track)s/zinba/map_ext%(frag_len)s', twoBit='%(genome)s', outfile='%(track)s/zinba/%(track)s', extension=%(frag_len)s, basecountfile='%(track)s/zinba/%(track)s.basecount', numProc=4, threshold=0.01, broad=FALSE, printFullOut=1, interaction=FALSE, mode='peaks', FDR=TRUE) '''  % locals() )

############################################################
Run Zinba for peak detection.
dataset/ETHPy150Open CGATOxford/cgat/obsolete/zinba.py/runZinba