@follows(copyCapseqReplicatedBedFiles, mkdir("liver_vs_testes") )
@files( (PARAMS["compare_liver_pattern"]+".replicated.bed", PARAMS["compare_testes_pattern"]+".replicated.bed"), "liver_vs_testes/liver.testes.venn" )
def liverTestesVenn(infiles, outfile):
    liver, testes = infiles
    liver_name = P.snip( os.path.basename(liver), ".bed" )
    testes_name = P.snip( os.path.basename(testes), ".bed" )
    to_cluster = True
    
    statement = '''cat %(liver)s %(testes)s | mergeBed -i stdin | awk 'OFS="\\t" {print $1,$2,$3,"merged"NR}' > liver_vs_testes/liver.testes.merge.bed;
                   echo "Total merged intervals" > %(outfile)s; 
                   cat liver_vs_testes/liver.testes.merge.bed | wc -l >> %(outfile)s; 
                   echo "Liver & testes" >> %(outfile)s; 
                   intersectBed -a liver_vs_testes/liver.testes.merge.bed -b %(liver)s -u | intersectBed -a stdin -b %(testes)s -u > liver_vs_testes/liver.testes.shared.bed; 
                   cat liver_vs_testes/liver.testes.shared.bed | wc -l >> %(outfile)s; 
                   echo "Testes only" >> %(outfile)s; 
                   intersectBed -a liver_vs_testes/liver.testes.merge.bed -b %(liver)s -v > liver_vs_testes/%(testes_name)s.liver.testes.unique.bed; 
                   cat liver_vs_testes/%(testes_name)s.liver.testes.unique.bed | wc -l >> %(outfile)s; 
                   echo "Liver only" >> %(outfile)s; 
                   intersectBed -a liver_vs_testes/liver.testes.merge.bed -b %(testes)s -v > liver_vs_testes/%(liver_name)s.liver.testes.unique.bed; 
                   cat liver_vs_testes/%(liver_name)s.liver.testes.unique.bed | wc -l >> %(outfile)s;                   
                   sed -i '{N;s/\\n/\\t/g}' %(outfile)s; '''
    P.run()

############################################################
identify interval overlap between liver and testes. Merge intervals first.
dataset/ETHPy150Open CGATOxford/cgat/obsolete/pipeline_proj007.py/liverTestesVenn