@transform( getPredictedCGIIntervals, suffix(".cgi_only.bed"), ".cgi_only.bed.load")
def loadPredictedCGIIntervals(infile, outfile):
    track = P.snip( os.path.basename( infile ), ".cgi_only.bed" ).replace(".replicated","")
    table = P.snip( os.path.basename( infile ), ".cgi_only.bed" ).replace(".","_").replace("-","_")
    expt_track = track + "-agg"
    replicates = EXPERIMENTS[expt_track]

    # Write header to output file
    tmpfile = tempfile.NamedTemporaryFile(delete=False)
    headers = ( "contig","start","stop","interval_id","nPeaks","PeakCenter","Length","AvgVal","PeakVal","nProbes" )
    tmpfile.write( "\t".join(headers) + "\n" )
    contig,start,end,interval_id,npeaks,peakcenter,length,avgval,peakval,nprobes = "",0,0,0,0,0,0,0,0,0

    # setup files
    samfiles, offsets = [], []
    for t in replicates:
        fn = "../bam/%s.norm.bam" % t
        assert os.path.exists( fn ), "could not find bamfile %s for track %s" % ( fn, str(t))
        samfiles.append( pysam.Samfile( fn,  "rb" ) )
        fn = "../macs/with_input/%s.macs" % t
        if os.path.exists( fn ):
            offsets.append( PIntervals.getPeakShiftFromMacs( fn ) )

    # Loop over input Bed file and calculate stats for merged intervals
    c = E.Counter()
    for line in open(infile, "r"):
        c.input += 1
        contig, start, end, interval_id = line[:-1].split()[:4]
        start, end = int(start), int(end)
        #interval_id = c.input
        npeaks, peakcenter, length, avgval, peakval, nprobes = PIntervals.countPeaks( contig, start, end, samfiles, offsets )
        if nprobes == 0:
            c.skipped_reads += 1
        c.output += 1
        tmpfile.write( "\t".join( map( str, (contig,start,end,interval_id,npeaks,peakcenter,length,avgval,peakval,nprobes) )) + "\n" )
    tmpfile.close()
    tmpfilename = tmpfile.name
    tablename = "%s_predicted_cgi_not_cap" % table
    
    statement = '''python %(scriptsdir)s/csv2db.py %(csv2db_options)s
                       --database=%(database)s
                       --index=contig,start 
                       --table=%(tablename)s
                       --allow-empty
                   < %(tmpfilename)s > %(outfile)s '''
    P.run()
    os.unlink( tmpfile.name )
    #L.info( "%s\n" % str(c) )
    
############################################################
## Load external bed file stats
Base absolute path of container.
dataset/ETHPy150Open CGATOxford/cgat/obsolete/pipeline_proj007.py/loadPredictedCGIIntervals--crossover with--dataset/ETHPy150Open ryan-roemer/django-cloud-browser/cloud_browser/cloud/fs.py/FilesystemContainer.base_path