@follows(loadLiverTestesShared, loadLiverTestesUnique, loadLiverTestesMerge)
@merge( "liver_vs_testes/*.liver.testes.unique.bed", "liver_vs_testes/liver.testes.merge.sort.bed")
def exportLiverTestesMergeWithSort( infiles, outfile):
    # Connect to DB
    dbhandle = sqlite3.connect( PARAMS["database"] )
    tracks = []
    for infile in infiles:
        t = P.snip(os.path.basename(infile), ".liver.testes.unique.bed").replace("-","_").replace(".","_")
        tracks.append(t)
    # Extract data from db
    cc = dbhandle.cursor()
    query = '''SELECT m.contig, m.start, m.end, m.interval_id, 
               "sh_" || substr('000000' || (m.end-m.start), -6, 6)  as sort
               FROM liver_testes_merged_intervals m, liver_testes_shared_intervals s 
               WHERE m.interval_id=s.interval_id ''' % locals()
    for i, t in enumerate(tracks):
        query += '''UNION 
                    SELECT m.contig, m.start, m.end, m.interval_id, 
                    "a%(i)s_" || substr('000000' || (m.end-m.start), -6, 6)  as sort
                    FROM liver_testes_merged_intervals m, %(t)s_liver_testes_unique_intervals u%(i)s 
                    WHERE m.interval_id=u%(i)s.interval_id ''' % locals()
    print query
    cc.execute( query )
    # Write to file
    outs = open( outfile, "w")
    for result in cc:
        pre = ""
        for r in result:
            outs.write("%s%s" % (pre, str(r)) )
            pre = "\t"
        outs.write("\n")
    cc.close()
    outs.close()

############################################################
############################################################
## Analyse liver/testes tissue specific intervals
Return info about a container
dataset/ETHPy150Open CGATOxford/cgat/obsolete/pipeline_proj007.py/exportLiverTestesMergeWithSort--crossover with--dataset/ETHPy150Open saltstack/salt/salt/modules/nspawn.py/info