@follows( mkdir("gene-profile") )
@transform( copyCapseqReplicatedBedFiles, regex(r"(\S+).replicated.bed"), r"gene-profile/\1.replicated.transcript-profile.all.png" )
def getReplicatedTranscriptProfile(infile, outfile):
    to_cluster = USECLUSTER
    track = P.snip( os.path.basename(infile), ".replicated.bed" )
    expt_track = track + "-agg"
    replicates = EXPERIMENTS[expt_track]
    tss_file = os.path.join( PARAMS["geneset_dir"], PARAMS["geneset_gene_profile"])
    ofp = "gene-profile/" + track + ".replicated.transcript-profile.all"
    # setup files
    samfiles, offsets = [], []
    for t in replicates:
        fn = "../bam/%s.norm.bam" % t.asFile()
        assert os.path.exists( fn ), "could not find bamfile %s for track %s" % ( fn, str(t))
        samfiles.append( fn )
        fn = "../macs/with_input/%s.macs" % t.asFile()
        if os.path.exists( fn ):
            offsets.append( PIntervals.getPeakShiftFromMacs( fn ) )
    bamfiles = " ".join( ("--bamfile=%s" % x) for x in samfiles )
    shifts =  " ".join( ("--shift=%s" % y)  for y in offsets )
    statement = '''python %(scriptsdir)s/bam2geneprofile.py 
                       %(bamfiles)s 
                       %(shifts)s 
                       --gtffile=%(tss_file)s
                       --output-filename-pattern=%(ofp)s
                       --reporter=transcript
                       --method=geneprofile
                       --normalization=total-sum
                       --normalize-profile=area
                       --normalize-profile=counts
                       --normalize-profile=none'''
    P.run()

############################################################
Build transcript profile from BAM files
dataset/ETHPy150Open CGATOxford/cgat/obsolete/pipeline_proj007.py/getReplicatedTranscriptProfile