@follows( runMacsMerged )
@transform( "macs/merged/*/treat/*.merged_treat_afterfiting_all.wig.gz", suffix(".wig.gz"), ".macs.norm.wig.gz" )
def normaliseWig( infile, outfile ):
    track = P.snip( os.path.basename(infile), ".merged_treat_afterfiting_all.wig.gz" )
    to_cluster = USECLUSTER
    dbhandle = sqlite3.connect( PARAMS["database"] )
    cc = dbhandle.cursor()
    query = '''SELECT sum(PF_HQ_ALIGNED_READS)
               FROM picard_align_stats
               WHERE track LIKE "%(track)s%%"''' % locals()
    cc.execute( query )
    total_aligned_reads = cc.fetchone()[0]
    norm = total_aligned_reads/1e7
    cc.close()
    
    # Read in wig and divide each value by norm
    outs = gzip.open( outfile, "wb" )
    ins = gzip.open( infile, "rb" )
    for line in ins:
        if re.match("^\d+", line):
            p, s = line.split()
            pos = int(p)
            score = float(s)
            norm_score = score/norm
            outs.write("%i\t%0.2f\n" % (pos, norm_score) )
        else:
            outs.write(line)
    ins.close()
    outs.close()
            
############################################################
############################################################
############################################################
## BUILD INTERVALS USING CONTROL SAMPLE
Test for Delete an existing zone
dataset/ETHPy150Open CGATOxford/cgat/obsolete/pipeline_proj012_chipseq.py/normaliseWig--crossover with--dataset/ETHPy150Open saltstack/salt/tests/unit/modules/firewalld_test.py/FirewalldTestCase.test_delete_zone