The goal of this analysis is to identify conserved versus human-specific tDMRs

Introduction

# Import libraries

library("ggplot2")
## Warning: package 'ggplot2' was built under R version 3.4.4
library("VennDiagram")
## Warning: package 'VennDiagram' was built under R version 3.4.4
## Loading required package: grid
## Loading required package: futile.logger
library("plyr")
library("dplyr")
## Warning: package 'dplyr' was built under R version 3.4.4
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:plyr':
## 
##     arrange, count, desc, failwith, id, mutate, rename, summarise,
##     summarize
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library("bedr")
## 
## 
## ######################
## #### bedr v1.0.4 ####
## ######################
## 
## checking binary availability...
##   * Checking path for bedtools... PASS
##     /usr/local/bin/bedtools
##   * Checking path for bedops... FAIL
##   * Checking path for tabix... FAIL
## tests and examples will be skipped on R CMD check if binaries are missing
library("RColorBrewer")
getwd()
## [1] "/Users/laurenblake/Desktop/Regulatory_Evol/ashlar-trial/analysis"
colors <- colorRampPalette(c(brewer.pal(9, "Blues")[1],brewer.pal(9, "Blues")[9]))(100)
pal <- c(brewer.pal(9, "Set1"), brewer.pal(8, "Set2"), brewer.pal(12, "Set3"))


# Import the data

# Human tDMRs
humans_heart_kidney_DMRs <- read.delim("../data/humans_heart_kidney_DMRs.txt")
humans_heart_liver_DMRs <- read.delim("../data/humans_heart_liver_DMRs.txt")
humans_heart_lung_DMRs <- read.delim("../data/humans_heart_lung_DMRs.txt")
humans_liver_lung_DMRs <- read.delim("../data/humans_liver_lung_DMRs.txt")
humans_liver_kidney_DMRs <- read.delim("../data/humans_liver_kidney_DMRs.txt")
humans_lung_kidney_DMRs <- read.delim("../data/humans_lung_kidney_DMRs.txt")

levels(humans_lung_kidney_DMRs[,1])
##  [1] "chr1"  "chr10" "chr11" "chr12" "chr13" "chr14" "chr15" "chr16"
##  [9] "chr17" "chr18" "chr19" "chr2"  "chr20" "chr21" "chr22" "chr3" 
## [17] "chr4"  "chr5"  "chr6"  "chr7"  "chr8"  "chr9"  "chrX"
#count(humans_lung_kidney_DMRs[,1])

# Chimp tDMRs
chimps_heart_kidney_DMRs <- read.delim("../data/chimps_heart_kidney_DMRs.txt")
chimps_heart_liver_DMRs <- read.delim("../data/chimps_heart_liver_DMRs.txt")
chimps_heart_lung_DMRs <- read.delim("../data/chimps_heart_lung_DMRs.txt")
chimps_liver_lung_DMRs <- read.delim("../data/chimps_liver_lung_DMRs.txt")
chimps_liver_kidney_DMRs <- read.delim("../data/chimps_liver_kidney_DMRs.txt")
chimps_lung_kidney_DMRs <- read.delim("../data/chimps_lung_kidney_DMRs.txt")

levels(chimps_lung_kidney_DMRs[,1])
##  [1] "chr1"                  "chr10"                
##  [3] "chr11"                 "chr11_gl000202_random"
##  [5] "chr12"                 "chr13"                
##  [7] "chr14"                 "chr15"                
##  [9] "chr16"                 "chr17"                
## [11] "chr18"                 "chr19"                
## [13] "chr2"                  "chr20"                
## [15] "chr21"                 "chr22"                
## [17] "chr3"                  "chr4"                 
## [19] "chr5"                  "chr6"                 
## [21] "chr7"                  "chr8"                 
## [23] "chr9"                  "chrX"
#count(chimps_lung_kidney_DMRs[,1])

# Rhesus tDMRs

rhesus_heart_kidney_DMRs <- read.delim("../data/rhesus_heart_kidney_DMRs.txt")
rhesus_heart_liver_DMRs <- read.delim("../data/rhesus_heart_liver_DMRs.txt")
rhesus_heart_lung_DMRs <- read.delim("../data/rhesus_heart_lung_DMRs.txt")
rhesus_liver_lung_DMRs <- read.delim("../data/rhesus_liver_lung_DMRs.txt")
rhesus_liver_kidney_DMRs <- read.delim("../data/rhesus_liver_kidney_DMRs.txt")
rhesus_lung_kidney_DMRs <- read.delim("../data/rhesus_lung_kidney_DMRs.txt")

levels(rhesus_heart_kidney_DMRs[,1])
##  [1] "chr1"                  "chr10"                
##  [3] "chr11"                 "chr11_gl000202_random"
##  [5] "chr12"                 "chr13"                
##  [7] "chr14"                 "chr15"                
##  [9] "chr16"                 "chr17"                
## [11] "chr17_gl000204_random" "chr18"                
## [13] "chr19"                 "chr2"                 
## [15] "chr20"                 "chr21"                
## [17] "chr22"                 "chr3"                 
## [19] "chr4"                  "chr5"                 
## [21] "chr6"                  "chr7"                 
## [23] "chr8"                  "chr9"                 
## [25] "chrX"
#count(rhesus_lung_kidney_DMRs[,1])

Get human, chimp, and rhesus autosomal tDMRs and perform heart specific analysis as an example

# Human heart-liver

# columns to pull
pull_col <- c(1:3, 16)

# make bed style format
humans_heart_liver_DMRs_bed <- humans_heart_liver_DMRs[,pull_col]

# Get DMRs on the autosomal chromosomes only
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed[which(humans_heart_liver_DMRs_bed[,1] != "chrX"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

summary(humans_heart_liver_DMRs_bed_noX[,3] - humans_heart_liver_DMRs_bed_noX[,2])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     5.0   255.0   473.0   584.5   795.0  4797.0
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr11_gl000202_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr17_gl000204_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

sort_humans_heart_liver_DMRs_bed <- bedr.sort.region(humans_heart_liver_DMRs_bed_noX)
## SORTING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Overlapping regions can cause unexpected results.
# Human heart-lung

# columns to pull
pull_col <- c(1:3, 16)

# make bed style format
humans_heart_liver_DMRs_bed <- humans_heart_lung_DMRs[,pull_col]

# Get DMRs on the autosomal chromosomes only
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed[which(humans_heart_liver_DMRs_bed[,1] != "chrX"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr11_gl000202_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr17_gl000204_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

sort_humans_heart_lung_DMRs_bed <- bedr.sort.region(humans_heart_liver_DMRs_bed_noX)
## SORTING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Overlapping regions can cause unexpected results.
# human heart-kidney

# columns to pull
pull_col <- c(1:3, 16)

# make bed style format
humans_heart_liver_DMRs_bed <- humans_heart_kidney_DMRs[,pull_col]

# Get DMRs on the autosomal chromosomes only
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed[which(humans_heart_liver_DMRs_bed[,1] != "chrX"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr11_gl000202_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr17_gl000204_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

summary(humans_heart_liver_DMRs_bed_noX[,3] - humans_heart_liver_DMRs_bed_noX[,2])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     6.0   261.0   486.0   594.7   831.0  4630.0
sort_humans_heart_kidney_DMRs_bed <- bedr.sort.region(humans_heart_liver_DMRs_bed_noX, check.chr = FALSE)
## SORTING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Overlapping regions can cause unexpected results.
# human liver-lung

# columns to pull
pull_col <- c(1:3, 16)

# make bed style format
humans_heart_liver_DMRs_bed <- humans_liver_lung_DMRs[,pull_col]

# Get DMRs on the autosomal chromosomes only
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed[which(humans_heart_liver_DMRs_bed[,1] != "chrX"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

summary(humans_heart_liver_DMRs_bed_noX[,3] - humans_heart_liver_DMRs_bed_noX[,2])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     5.0   228.0   427.0   540.7   738.0  4768.0
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr11_gl000202_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr17_gl000204_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

sort_humans_liver_lung_DMRs_bed <- bedr.sort.region(humans_heart_liver_DMRs_bed_noX)
## SORTING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Overlapping regions can cause unexpected results.
# human liver-kidney

# columns to pull
pull_col <- c(1:3, 16)

# make bed style format
humans_heart_liver_DMRs_bed <- humans_liver_kidney_DMRs[,pull_col]

# Get DMRs on the autosomal chromosomes only
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed[which(humans_heart_liver_DMRs_bed[,1] != "chrX"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

summary(humans_heart_liver_DMRs_bed_noX[,3] - humans_heart_liver_DMRs_bed_noX[,2])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##       4     242     449     553     759    4245
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr11_gl000202_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr17_gl000204_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

sort_humans_liver_kidney_DMRs_bed <- bedr.sort.region(humans_heart_liver_DMRs_bed_noX)
## SORTING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Overlapping regions can cause unexpected results.
# human lung-kidney

# columns to pull
pull_col <- c(1:3, 16)

# make bed style format
humans_heart_liver_DMRs_bed <- humans_lung_kidney_DMRs[,pull_col]

# Get DMRs on the autosomal chromosomes only
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed[which(humans_heart_liver_DMRs_bed[,1] != "chrX"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr11_gl000202_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr17_gl000204_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])
summary(humans_heart_liver_DMRs_bed_noX[,3] - humans_heart_liver_DMRs_bed_noX[,2])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     5.0   241.0   445.0   544.4   757.0  3732.0
sort_humans_lung_kidney_DMRs_bed <- bedr.sort.region(humans_heart_liver_DMRs_bed_noX)
## SORTING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Overlapping regions can cause unexpected results.

Heart specific

Heart specific in humans

# 25% overlap

heart_liver_heart_lung_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_heart_lung_DMRs_bed), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b315541e7b4.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316ea21cb5.bed -wao -f 0.25 -F 0.25
heart_liver_heart_kidney_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_heart_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316baf481f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31b8ff262.bed -wao -f 0.25 -F 0.25
heart_liver_liver_lung_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_liver_lung_DMRs_bed), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3110a8da45.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b315b0ec18.bed -wao -f 0.25 -F 0.25
heart_liver_liver_kidney_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_liver_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b317b0d1c0a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b314513e46a.bed -wao -f 0.25 -F 0.25
heart_liver_lung_kidney_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_lung_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31274be0e2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3169a8c3c7.bed -wao -f 0.25 -F 0.25
colnames(heart_liver_heart_lung_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(heart_liver_heart_kidney_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(heart_liver_liver_kidney_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(heart_liver_liver_lung_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(heart_liver_lung_kidney_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

head(heart_liver_heart_lung_only_75)
##                     chr  start    end direction chr.b start.b  end.b
## chr1:715109-715282 chr1 715109 715282     hyper     .      -1     -1
## chr1:766879-767252 chr1 766879 767252      hypo  chr1  766672 767252
## chr1:800313-801775 chr1 800313 801775      hypo     .      -1     -1
## chr1:871334-871812 chr1 871334 871812      hypo  chr1  871135 871870
## chr1:896748-896792 chr1 896748 896792      hypo     .      -1     -1
## chr1:908583-909092 chr1 908583 909092      hypo     .      -1     -1
##                    direction.b overlap
## chr1:715109-715282           .       0
## chr1:766879-767252        hypo     373
## chr1:800313-801775           .       0
## chr1:871334-871812        hypo     478
## chr1:896748-896792           .       0
## chr1:908583-909092           .       0
head(heart_liver_heart_kidney_only_75)
##    chr  start    end direction chr.b start.b  end.b direction.b overlap
## 1 chr1 715109 715282     hyper     .      -1     -1           .       0
## 2 chr1 766879 767252      hypo  chr1  766672 767180        hypo     301
## 3 chr1 800313 801775      hypo  chr1  800829 801915        hypo     946
## 4 chr1 871334 871812      hypo  chr1  871301 871870        hypo     478
## 5 chr1 896748 896792      hypo     .      -1     -1           .       0
## 6 chr1 908583 909092      hypo     .      -1     -1           .       0
head(heart_liver_liver_kidney_only_75)
##    chr  start    end direction chr.b start.b  end.b direction.b overlap
## 1 chr1 715109 715282     hyper  chr1  715109 715282        hypo     173
## 2 chr1 766879 767252      hypo     .      -1     -1           .       0
## 3 chr1 800313 801775      hypo     .      -1     -1           .       0
## 4 chr1 871334 871812      hypo     .      -1     -1           .       0
## 5 chr1 896748 896792      hypo     .      -1     -1           .       0
## 6 chr1 908583 909092      hypo     .      -1     -1           .       0
head(heart_liver_liver_lung_only_75)
##    chr  start    end direction chr.b start.b  end.b direction.b overlap
## 1 chr1 715109 715282     hyper  chr1  715109 715282        hypo     173
## 2 chr1 766879 767252      hypo     .      -1     -1           .       0
## 3 chr1 800313 801775      hypo     .      -1     -1           .       0
## 4 chr1 871334 871812      hypo     .      -1     -1           .       0
## 5 chr1 896748 896792      hypo     .      -1     -1           .       0
## 6 chr1 908583 909092      hypo     .      -1     -1           .       0
head(heart_liver_lung_kidney_only_75)
##    chr  start    end direction chr.b start.b end.b direction.b overlap
## 1 chr1 715109 715282     hyper     .      -1    -1           .       0
## 2 chr1 766879 767252      hypo     .      -1    -1           .       0
## 3 chr1 800313 801775      hypo     .      -1    -1           .       0
## 4 chr1 871334 871812      hypo     .      -1    -1           .       0
## 5 chr1 896748 896792      hypo     .      -1    -1           .       0
## 6 chr1 908583 909092      hypo     .      -1    -1           .       0
human_heart_liver_DMR <- left_join(heart_liver_heart_lung_only_75, heart_liver_heart_kidney_only_75, by= c("chr", "start")) %>% left_join(., heart_liver_liver_lung_only_75, by=c("chr", "start")) %>% left_join(., heart_liver_liver_kidney_only_75, by=c("chr", "start")) %>% left_join(., heart_liver_lung_kidney_only_75, by=c("chr", "start"))


human_DMR_heart_specific_25 <- human_heart_liver_DMR[which(human_heart_liver_DMR[,9] > 0 & human_heart_liver_DMR[,16] > 0 & human_heart_liver_DMR[,23] < 1 & human_heart_liver_DMR[,30] < 1 & human_heart_liver_DMR[,37] < 1),]

dim(human_DMR_heart_specific_25)
## [1] 2949   37
# Same direction

human_DMR_heart_specific_25 <- human_DMR_heart_specific_25[which(human_DMR_heart_specific_25[,4] == human_DMR_heart_specific_25[,8]),]

human_DMR_heart_specific_25 <- human_DMR_heart_specific_25[which(human_DMR_heart_specific_25[,4] == human_DMR_heart_specific_25[,11]),]

human_DMR_heart_specific_25 <- human_DMR_heart_specific_25[which(human_DMR_heart_specific_25[,4] == human_DMR_heart_specific_25[,15]),]

## 50% overlap 

heart_liver_heart_lung_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_heart_lung_DMRs_bed), method = "intersect",  params = "-wao -f 0.5 -F 0.5", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3156aed87a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31345cfccd.bed -wao -f 0.5 -F 0.5
heart_liver_heart_kidney_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_heart_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.5 -F 0.5", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b311ac7e706.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317c313750.bed -wao -f 0.5 -F 0.5
heart_liver_liver_lung_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_liver_lung_DMRs_bed), method = "intersect",  params = "-wao -f 0.5 -F 0.5", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b313ee8c25e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31169ec12e.bed -wao -f 0.5 -F 0.5
heart_liver_liver_kidney_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_liver_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.5 -F 0.5", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b313f562e64.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317090084c.bed -wao -f 0.5 -F 0.5
heart_liver_lung_kidney_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_lung_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.5 -F 0.5", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31730ba491.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b313204bc56.bed -wao -f 0.5 -F 0.5
human_heart_liver_DMR <- cbind(heart_liver_heart_lung_only_75, heart_liver_heart_kidney_only_75, heart_liver_liver_lung_only_75, heart_liver_liver_kidney_only_75, heart_liver_lung_kidney_only_75)

human_DMR_heart_specific_50 <- human_heart_liver_DMR[which(human_heart_liver_DMR[,9] > 0 & human_heart_liver_DMR[,18] > 0 & human_heart_liver_DMR[,27] < 1 & human_heart_liver_DMR[,36] < 1 & human_heart_liver_DMR[,45] < 1),]

dim(human_DMR_heart_specific_50)
## [1] 2136   45
human_DMR_heart_specific_50 <- human_DMR_heart_specific_50[which(human_DMR_heart_specific_50[,4] == human_DMR_heart_specific_50[,8]),]

human_DMR_heart_specific_50 <- human_DMR_heart_specific_50[which(human_DMR_heart_specific_50[,4] == human_DMR_heart_specific_50[,13]),]

human_DMR_heart_specific_50 <- human_DMR_heart_specific_50[which(human_DMR_heart_specific_50[,4] == human_DMR_heart_specific_50[,17]),]




heart_liver_heart_lung_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_heart_lung_DMRs_bed), method = "intersect",  params = "-wao -f 0.75 -F 0.75", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b311bd2c077.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31790c1619.bed -wao -f 0.75 -F 0.75
heart_liver_heart_kidney_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_heart_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.75 -F 0.75", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31416d4a81.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b313759add4.bed -wao -f 0.75 -F 0.75
heart_liver_liver_lung_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_liver_lung_DMRs_bed), method = "intersect",  params = "-wao -f 0.75 -F 0.75", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31182d7808.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316b2cea75.bed -wao -f 0.75 -F 0.75
heart_liver_liver_kidney_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_liver_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.75 -F 0.75", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b315137d3f6.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b315cf45dfc.bed -wao -f 0.75 -F 0.75
heart_liver_lung_kidney_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_lung_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.75 -F 0.75", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316fa9a3fd.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31f3473c5.bed -wao -f 0.75 -F 0.75
human_heart_liver_DMR <- cbind(heart_liver_heart_lung_only_75, heart_liver_heart_kidney_only_75, heart_liver_liver_lung_only_75, heart_liver_liver_kidney_only_75, heart_liver_lung_kidney_only_75)

human_DMR_heart_specific_75 <- human_heart_liver_DMR[which(human_heart_liver_DMR[,9] > 0 & human_heart_liver_DMR[,18] > 0 & human_heart_liver_DMR[,27] < 1 & human_heart_liver_DMR[,36] < 1 & human_heart_liver_DMR[,45] < 1),]

dim(human_DMR_heart_specific_75)
## [1] 1004   45

Heart specific in chimps

# Chimp heart-liver

# columns to pull
pull_col <- c(1:3, 16)

# make bed style format
humans_heart_liver_DMRs_bed <- chimps_heart_liver_DMRs[,pull_col]

# Get DMRs on the autosomal chromosomes only
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed[which(humans_heart_liver_DMRs_bed[,1] != "chrX"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

summary(humans_heart_liver_DMRs_bed_noX[,3] - humans_heart_liver_DMRs_bed_noX[,2])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     5.0   266.0   498.0   617.6   849.0  4950.0
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr11_gl000202_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr17_gl000204_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

sort_chimps_heart_liver_DMRs_bed <- bedr.sort.region(humans_heart_liver_DMRs_bed_noX)
## SORTING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Overlapping regions can cause unexpected results.
# Chimp heart-lung

# columns to pull
pull_col <- c(1:3, 16)

# make bed style format
humans_heart_liver_DMRs_bed <- chimps_heart_lung_DMRs[,pull_col]

# Get DMRs on the autosomal chromosomes only
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed[which(humans_heart_liver_DMRs_bed[,1] != "chrX"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr11_gl000202_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr17_gl000204_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

sort_chimps_heart_lung_DMRs_bed <- bedr.sort.region(humans_heart_liver_DMRs_bed_noX)
## SORTING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Overlapping regions can cause unexpected results.
# chimp heart-kidney

# columns to pull
pull_col <- c(1:3, 16)

# make bed style format
humans_heart_liver_DMRs_bed <- chimps_heart_kidney_DMRs[,pull_col]

# Get DMRs on the autosomal chromosomes only
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed[which(humans_heart_liver_DMRs_bed[,1] != "chrX"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr11_gl000202_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr17_gl000204_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

summary(humans_heart_liver_DMRs_bed_noX[,3] - humans_heart_liver_DMRs_bed_noX[,2])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     4.0   247.0   463.0   565.2   788.0  4173.0
sort_chimps_heart_kidney_DMRs_bed <- bedr.sort.region(humans_heart_liver_DMRs_bed_noX, check.chr = FALSE)
## SORTING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Overlapping regions can cause unexpected results.
# Chimp liver-lung

# columns to pull
pull_col <- c(1:3, 16)

# make bed style format
humans_heart_liver_DMRs_bed <- chimps_liver_lung_DMRs[,pull_col]

# Get DMRs on the autosomal chromosomes only
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed[which(humans_heart_liver_DMRs_bed[,1] != "chrX"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

summary(humans_heart_liver_DMRs_bed_noX[,3] - humans_heart_liver_DMRs_bed_noX[,2])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     5.0   247.0   459.0   577.9   793.0  5105.0
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr11_gl000202_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr17_gl000204_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

sort_chimps_liver_lung_DMRs_bed <- bedr.sort.region(humans_heart_liver_DMRs_bed_noX)
## SORTING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Overlapping regions can cause unexpected results.
# chimp liver-kidney

# columns to pull
pull_col <- c(1:3, 16)

# make bed style format
humans_heart_liver_DMRs_bed <- chimps_liver_kidney_DMRs[,pull_col]

# Get DMRs on the autosomal chromosomes only
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed[which(humans_heart_liver_DMRs_bed[,1] != "chrX"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

summary(humans_heart_liver_DMRs_bed_noX[,3] - humans_heart_liver_DMRs_bed_noX[,2])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##       4     245     464     571     785    4733
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr11_gl000202_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr17_gl000204_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

sort_chimps_liver_kidney_DMRs_bed <- bedr.sort.region(humans_heart_liver_DMRs_bed_noX)
## SORTING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Overlapping regions can cause unexpected results.
# chimp lung-kidney

# columns to pull
pull_col <- c(1:3, 16)

# make bed style format
humans_heart_liver_DMRs_bed <- chimps_lung_kidney_DMRs[,pull_col]

# Get DMRs on the autosomal chromosomes only
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed[which(humans_heart_liver_DMRs_bed[,1] != "chrX"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr11_gl000202_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr17_gl000204_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])
summary(humans_heart_liver_DMRs_bed_noX[,3] - humans_heart_liver_DMRs_bed_noX[,2])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     4.0   230.0   430.0   523.8   727.2  3703.0
sort_chimps_lung_kidney_DMRs_bed <- bedr.sort.region(humans_heart_liver_DMRs_bed_noX)
## SORTING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Overlapping regions can cause unexpected results.
# 25% overlap

heart_liver_heart_lung_only_75 <- bedr(input = list(a = sort_chimps_heart_liver_DMRs_bed, b = sort_chimps_heart_lung_DMRs_bed), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3130002599.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b312e06a7eb.bed -wao -f 0.25 -F 0.25
heart_liver_heart_kidney_only_75 <- bedr(input = list(a = sort_chimps_heart_liver_DMRs_bed, b = sort_chimps_heart_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31483a43ce.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b314dc7394e.bed -wao -f 0.25 -F 0.25
heart_liver_liver_lung_only_75 <- bedr(input = list(a = sort_chimps_heart_liver_DMRs_bed, b = sort_chimps_liver_lung_DMRs_bed), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3139e701f4.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b315b4cefc0.bed -wao -f 0.25 -F 0.25
heart_liver_liver_kidney_only_75 <- bedr(input = list(a = sort_chimps_heart_liver_DMRs_bed, b = sort_chimps_liver_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b313c88f0d9.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31ac2861b.bed -wao -f 0.25 -F 0.25
heart_liver_lung_kidney_only_75 <- bedr(input = list(a = sort_chimps_heart_liver_DMRs_bed, b = sort_chimps_lung_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31566c261a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b312928e3f0.bed -wao -f 0.25 -F 0.25
colnames(heart_liver_heart_lung_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(heart_liver_heart_kidney_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(heart_liver_liver_lung_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(heart_liver_liver_kidney_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(heart_liver_lung_kidney_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

human_heart_liver_DMR <- left_join(heart_liver_heart_lung_only_75, heart_liver_heart_kidney_only_75, by= c("chr", "start")) %>% left_join(., heart_liver_liver_lung_only_75, by=c("chr", "start")) %>% left_join(., heart_liver_liver_kidney_only_75, by=c("chr", "start")) %>% left_join(., heart_liver_lung_kidney_only_75, by=c("chr", "start"))


chimp_DMR_heart_specific_25 <- human_heart_liver_DMR[which(human_heart_liver_DMR[,9] > 0 & human_heart_liver_DMR[,16] > 0 & human_heart_liver_DMR[,23] < 1 & human_heart_liver_DMR[,30] < 1 & human_heart_liver_DMR[,37] < 1),]

dim(chimp_DMR_heart_specific_25)
## [1] 1705   37
##### 50% overlap 

heart_liver_heart_lung_only_75 <- bedr(input = list(a = sort_chimps_heart_liver_DMRs_bed, b = sort_chimps_heart_lung_DMRs_bed), method = "intersect",  params = "-wao -f 0.5 -F 0.5", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316c78316e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311aaf99a1.bed -wao -f 0.5 -F 0.5
heart_liver_heart_kidney_only_75 <- bedr(input = list(a = sort_chimps_heart_liver_DMRs_bed, b = sort_chimps_heart_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.5 -F 0.5", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31605263c8.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311da0f73b.bed -wao -f 0.5 -F 0.5
heart_liver_liver_lung_only_75 <- bedr(input = list(a = sort_chimps_heart_liver_DMRs_bed, b = sort_chimps_liver_lung_DMRs_bed), method = "intersect",  params = "-wao -f 0.5 -F 0.5", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31351d7293.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317e28305c.bed -wao -f 0.5 -F 0.5
heart_liver_liver_kidney_only_75 <- bedr(input = list(a = sort_chimps_heart_liver_DMRs_bed, b = sort_chimps_liver_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.5 -F 0.5", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3161a5fa12.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31165babf8.bed -wao -f 0.5 -F 0.5
heart_liver_lung_kidney_only_75 <- bedr(input = list(a = sort_chimps_heart_liver_DMRs_bed, b = sort_chimps_lung_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.5 -F 0.5", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31a6c3b73.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3134c4c9e1.bed -wao -f 0.5 -F 0.5
human_heart_liver_DMR <- cbind(heart_liver_heart_lung_only_75, heart_liver_heart_kidney_only_75, heart_liver_liver_lung_only_75, heart_liver_liver_kidney_only_75, heart_liver_lung_kidney_only_75)

chimp_DMR_heart_specific_50 <- human_heart_liver_DMR[which(human_heart_liver_DMR[,9] > 0 & human_heart_liver_DMR[,18] > 0 & human_heart_liver_DMR[,27] < 1 & human_heart_liver_DMR[,36] < 1 & human_heart_liver_DMR[,45] < 1),]

dim(chimp_DMR_heart_specific_50)
## [1] 1232   45
##### 75% overlap 

heart_liver_heart_lung_only_75 <- bedr(input = list(a = sort_chimps_heart_liver_DMRs_bed, b = sort_chimps_heart_lung_DMRs_bed), method = "intersect",  params = "-wao -f 0.75 -F 0.75", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b314a289bbc.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31307b315c.bed -wao -f 0.75 -F 0.75
heart_liver_heart_kidney_only_75 <- bedr(input = list(a = sort_chimps_heart_liver_DMRs_bed, b = sort_chimps_heart_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.75 -F 0.75", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b314afc9d99.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31b0c7350.bed -wao -f 0.75 -F 0.75
heart_liver_liver_lung_only_75 <- bedr(input = list(a = sort_chimps_heart_liver_DMRs_bed, b = sort_chimps_liver_lung_DMRs_bed), method = "intersect",  params = "-wao -f 0.75 -F 0.75", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b313190b004.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3132378731.bed -wao -f 0.75 -F 0.75
heart_liver_liver_kidney_only_75 <- bedr(input = list(a = sort_chimps_heart_liver_DMRs_bed, b = sort_chimps_liver_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.75 -F 0.75", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b319df3921.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3116a62e4a.bed -wao -f 0.75 -F 0.75
heart_liver_lung_kidney_only_75 <- bedr(input = list(a = sort_chimps_heart_liver_DMRs_bed, b = sort_chimps_lung_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.75 -F 0.75", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3141fa179d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3167f0be70.bed -wao -f 0.75 -F 0.75
human_heart_liver_DMR <- cbind(heart_liver_heart_lung_only_75, heart_liver_heart_kidney_only_75, heart_liver_liver_lung_only_75, heart_liver_liver_kidney_only_75, heart_liver_lung_kidney_only_75)

chimp_DMR_heart_specific_75 <- human_heart_liver_DMR[which(human_heart_liver_DMR[,9] > 0 & human_heart_liver_DMR[,18] > 0 & human_heart_liver_DMR[,27] < 1 & human_heart_liver_DMR[,36] < 1 & human_heart_liver_DMR[,45] < 1),]

dim(chimp_DMR_heart_specific_75)
## [1] 569  45

Heart specific in rhesus

# Chimp heart-liver

# columns to pull
pull_col <- c(1:3, 16)

# make bed style format
humans_heart_liver_DMRs_bed <- rhesus_heart_liver_DMRs[,pull_col]

# Get DMRs on the autosomal chromosomes only
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed[which(humans_heart_liver_DMRs_bed[,1] != "chrX"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

summary(humans_heart_liver_DMRs_bed_noX[,3] - humans_heart_liver_DMRs_bed_noX[,2])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     4.0   276.2   524.0   658.6   906.0  6805.0
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr11_gl000202_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr17_gl000204_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

sort_rhesus_heart_liver_DMRs_bed <- bedr.sort.region(humans_heart_liver_DMRs_bed_noX)
## SORTING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Overlapping regions can cause unexpected results.
# Chimp heart-lung

# columns to pull
pull_col <- c(1:3, 16)

# make bed style format
humans_heart_liver_DMRs_bed <- rhesus_heart_lung_DMRs[,pull_col]

# Get DMRs on the autosomal chromosomes only
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed[which(humans_heart_liver_DMRs_bed[,1] != "chrX"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr11_gl000202_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr17_gl000204_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

sort_rhesus_heart_lung_DMRs_bed <- bedr.sort.region(humans_heart_liver_DMRs_bed_noX)
## SORTING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Overlapping regions can cause unexpected results.
# chimp heart-kidney

# columns to pull
pull_col <- c(1:3, 16)

# make bed style format
humans_heart_liver_DMRs_bed <- rhesus_heart_kidney_DMRs[,pull_col]

# Get DMRs on the autosomal chromosomes only
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed[which(humans_heart_liver_DMRs_bed[,1] != "chrX"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr11_gl000202_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr17_gl000204_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

summary(humans_heart_liver_DMRs_bed_noX[,3] - humans_heart_liver_DMRs_bed_noX[,2])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     6.0   262.0   493.0   602.1   834.0  5515.0
sort_rhesus_heart_kidney_DMRs_bed <- bedr.sort.region(humans_heart_liver_DMRs_bed_noX, check.chr = FALSE)
## SORTING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Overlapping regions can cause unexpected results.
# Chimp liver-lung

# columns to pull
pull_col <- c(1:3, 16)

# make bed style format
humans_heart_liver_DMRs_bed <- rhesus_liver_lung_DMRs[,pull_col]

# Get DMRs on the autosomal chromosomes only
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed[which(humans_heart_liver_DMRs_bed[,1] != "chrX"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

summary(humans_heart_liver_DMRs_bed_noX[,3] - humans_heart_liver_DMRs_bed_noX[,2])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     5.0   265.0   498.0   629.6   856.0  6475.0
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr11_gl000202_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr17_gl000204_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

sort_rhesus_liver_lung_DMRs_bed <- bedr.sort.region(humans_heart_liver_DMRs_bed_noX)
## SORTING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Overlapping regions can cause unexpected results.
# chimp liver-kidney

# columns to pull
pull_col <- c(1:3, 16)

# make bed style format
humans_heart_liver_DMRs_bed <- rhesus_liver_kidney_DMRs[,pull_col]

# Get DMRs on the autosomal chromosomes only
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed[which(humans_heart_liver_DMRs_bed[,1] != "chrX"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

summary(humans_heart_liver_DMRs_bed_noX[,3] - humans_heart_liver_DMRs_bed_noX[,2])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     4.0   269.0   508.0   635.4   879.0  5605.0
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr11_gl000202_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr17_gl000204_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

sort_rhesus_liver_kidney_DMRs_bed <- bedr.sort.region(humans_heart_liver_DMRs_bed_noX)
## SORTING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Overlapping regions can cause unexpected results.
# chimp lung-kidney

# columns to pull
pull_col <- c(1:3, 16)

# make bed style format
humans_heart_liver_DMRs_bed <- rhesus_lung_kidney_DMRs[,pull_col]

# Get DMRs on the autosomal chromosomes only
humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed[which(humans_heart_liver_DMRs_bed[,1] != "chrX"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr11_gl000202_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])

humans_heart_liver_DMRs_bed_noX <- humans_heart_liver_DMRs_bed_noX[which(humans_heart_liver_DMRs_bed_noX[,1] != "chr17_gl000204_random"),]

humans_heart_liver_DMRs_bed_noX[,1] <- as.character(humans_heart_liver_DMRs_bed_noX[,1])
humans_heart_liver_DMRs_bed_noX[,2] <- as.integer(humans_heart_liver_DMRs_bed_noX[,2])
humans_heart_liver_DMRs_bed_noX[,3] <- as.integer(humans_heart_liver_DMRs_bed_noX[,3])
summary(humans_heart_liver_DMRs_bed_noX[,3] - humans_heart_liver_DMRs_bed_noX[,2])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     6.0   241.0   458.0   560.6   771.0  3694.0
sort_rhesus_lung_kidney_DMRs_bed <- bedr.sort.region(humans_heart_liver_DMRs_bed_noX)
## SORTING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Overlapping regions can cause unexpected results.
# 25% overlap

heart_liver_heart_lung_only_75 <- bedr(input = list(a = sort_rhesus_heart_liver_DMRs_bed, b = sort_rhesus_heart_lung_DMRs_bed), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31774a08ae.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b312a1af6ef.bed -wao -f 0.25 -F 0.25
heart_liver_heart_kidney_only_75 <- bedr(input = list(a = sort_rhesus_heart_liver_DMRs_bed, b = sort_rhesus_heart_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31136d8933.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31522a97f7.bed -wao -f 0.25 -F 0.25
heart_liver_liver_lung_only_75 <- bedr(input = list(a = sort_rhesus_heart_liver_DMRs_bed, b = sort_rhesus_liver_lung_DMRs_bed), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3143db9e32.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311c76c6a6.bed -wao -f 0.25 -F 0.25
heart_liver_liver_kidney_only_75 <- bedr(input = list(a = sort_rhesus_heart_liver_DMRs_bed, b = sort_rhesus_liver_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b314451d7f2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3138140f5c.bed -wao -f 0.25 -F 0.25
heart_liver_lung_kidney_only_75 <- bedr(input = list(a = sort_rhesus_heart_liver_DMRs_bed, b = sort_rhesus_lung_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31287658e9.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b315d2fbc06.bed -wao -f 0.25 -F 0.25
colnames(heart_liver_heart_lung_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(heart_liver_heart_kidney_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(heart_liver_liver_lung_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(heart_liver_liver_kidney_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(heart_liver_lung_kidney_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

human_heart_liver_DMR <- left_join(heart_liver_heart_lung_only_75, heart_liver_heart_kidney_only_75, by= c("chr", "start")) %>% left_join(., heart_liver_liver_lung_only_75, by=c("chr", "start")) %>% left_join(., heart_liver_liver_kidney_only_75, by=c("chr", "start")) %>% left_join(., heart_liver_lung_kidney_only_75, by=c("chr", "start"))


rhesus_DMR_heart_specific_25 <- human_heart_liver_DMR[which(human_heart_liver_DMR[,9] > 0 & human_heart_liver_DMR[,16] > 0 & human_heart_liver_DMR[,23] < 1 & human_heart_liver_DMR[,30] < 1 & human_heart_liver_DMR[,37] < 1),]

dim(rhesus_DMR_heart_specific_25)
## [1] 1557   37
heart_liver_heart_lung_only_75 <- bedr(input = list(a = sort_rhesus_heart_liver_DMRs_bed, b = sort_rhesus_heart_lung_DMRs_bed), method = "intersect",  params = "-wao -f 0.5 -F 0.5", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b317e7dee2f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3117f36f55.bed -wao -f 0.5 -F 0.5
heart_liver_heart_kidney_only_75 <- bedr(input = list(a = sort_rhesus_heart_liver_DMRs_bed, b = sort_rhesus_heart_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.5 -F 0.5", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3164026ced.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317039e51b.bed -wao -f 0.5 -F 0.5
heart_liver_liver_lung_only_75 <- bedr(input = list(a = sort_rhesus_heart_liver_DMRs_bed, b = sort_rhesus_liver_lung_DMRs_bed), method = "intersect",  params = "-wao -f 0.5 -F 0.5", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31421ace09.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316588a7be.bed -wao -f 0.5 -F 0.5
heart_liver_liver_kidney_only_75 <- bedr(input = list(a = sort_rhesus_heart_liver_DMRs_bed, b = sort_rhesus_liver_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.5 -F 0.5", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3157140858.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317e4a2d14.bed -wao -f 0.5 -F 0.5
heart_liver_lung_kidney_only_75 <- bedr(input = list(a = sort_rhesus_heart_liver_DMRs_bed, b = sort_rhesus_lung_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.5 -F 0.5", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b317be28059.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b312e753cd2.bed -wao -f 0.5 -F 0.5
human_heart_liver_DMR <- cbind(heart_liver_heart_lung_only_75, heart_liver_heart_kidney_only_75, heart_liver_liver_lung_only_75, heart_liver_liver_kidney_only_75, heart_liver_lung_kidney_only_75)

rhesus_DMR_heart_specific_50 <- human_heart_liver_DMR[which(human_heart_liver_DMR[,9] > 0 & human_heart_liver_DMR[,18] > 0 & human_heart_liver_DMR[,27] < 1 & human_heart_liver_DMR[,36] < 1 & human_heart_liver_DMR[,45] < 1),]

dim(rhesus_DMR_heart_specific_50)
## [1] 1121   45
##### 75% overlap 


heart_liver_heart_lung_only_75 <- bedr(input = list(a = sort_rhesus_heart_liver_DMRs_bed, b = sort_rhesus_heart_lung_DMRs_bed), method = "intersect",  params = "-wao -f 0.75 -F 0.75", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b313763df9.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31107a7a45.bed -wao -f 0.75 -F 0.75
heart_liver_heart_kidney_only_75 <- bedr(input = list(a = sort_rhesus_heart_liver_DMRs_bed, b = sort_rhesus_heart_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.75 -F 0.75", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3115be818c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311907f48f.bed -wao -f 0.75 -F 0.75
heart_liver_liver_lung_only_75 <- bedr(input = list(a = sort_rhesus_heart_liver_DMRs_bed, b = sort_rhesus_liver_lung_DMRs_bed), method = "intersect",  params = "-wao -f 0.75 -F 0.75", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31153143cf.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31394dea5f.bed -wao -f 0.75 -F 0.75
heart_liver_liver_kidney_only_75 <- bedr(input = list(a = sort_rhesus_heart_liver_DMRs_bed, b = sort_rhesus_liver_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.75 -F 0.75", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3141b92915.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31d3a1d16.bed -wao -f 0.75 -F 0.75
heart_liver_lung_kidney_only_75 <- bedr(input = list(a = sort_rhesus_heart_liver_DMRs_bed, b = sort_rhesus_lung_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.75 -F 0.75", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3156860068.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316b94e0e1.bed -wao -f 0.75 -F 0.75
human_heart_liver_DMR <- cbind(heart_liver_heart_lung_only_75, heart_liver_heart_kidney_only_75, heart_liver_liver_lung_only_75, heart_liver_liver_kidney_only_75, heart_liver_lung_kidney_only_75)

rhesus_DMR_heart_specific_75 <- human_heart_liver_DMR[which(human_heart_liver_DMR[,9] > 0 & human_heart_liver_DMR[,18] > 0 & human_heart_liver_DMR[,27] < 1 & human_heart_liver_DMR[,36] < 1 & human_heart_liver_DMR[,45] < 1),]

dim(rhesus_DMR_heart_specific_75)
## [1] 553  45

Generalize the code with a function

### Write functions for identifying tissue-specific DMRs in a given species

# 25% overlap

tissue_specific_25_overlap <- function(DMR1_tissue_to_overlap, DMR2_tissue_to_overlap, DMR3_tissue_to_overlap, DMR4_no_overlap, DMR5_no_overlap, DMR6_no_overlap){
  
  # Translate variables to previously-used code
  sort_humans_heart_liver_DMRs_bed <- DMR1_tissue_to_overlap
  sort_humans_liver_lung_DMRs_bed <- DMR2_tissue_to_overlap
  sort_humans_liver_kidney_DMRs_bed <- DMR3_tissue_to_overlap
  sort_humans_heart_kidney_DMRs_bed <- DMR4_no_overlap
  sort_humans_heart_lung_DMRs_bed <- DMR5_no_overlap
  sort_humans_lung_kidney_DMRs_bed <- DMR6_no_overlap

  # Run bedtools to overlap  
heart_liver_heart_lung_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_liver_lung_DMRs_bed), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)

heart_liver_heart_kidney_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_liver_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)

heart_liver_liver_lung_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_heart_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)

heart_liver_liver_kidney_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_heart_lung_DMRs_bed), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)

heart_liver_lung_kidney_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_lung_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)


  # Convert to same name
colnames(heart_liver_heart_lung_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(heart_liver_heart_kidney_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(heart_liver_liver_lung_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(heart_liver_liver_kidney_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(heart_liver_lung_kidney_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

human_heart_liver_DMR <- left_join(heart_liver_heart_lung_only_75, heart_liver_heart_kidney_only_75, by= c("chr", "start")) %>% left_join(., heart_liver_liver_lung_only_75, by=c("chr", "start")) %>% left_join(., heart_liver_liver_kidney_only_75, by=c("chr", "start")) %>% left_join(., heart_liver_lung_kidney_only_75, by=c("chr", "start"))


DMR_tissue_specific_25 <- human_heart_liver_DMR[which(human_heart_liver_DMR[,9] > 0 & human_heart_liver_DMR[,16] > 0 & human_heart_liver_DMR[,23] < 1 & human_heart_liver_DMR[,30] < 1 & human_heart_liver_DMR[,37] < 1),]

  return(DMR_tissue_specific_25)
}

# 50% overlap

tissue_specific_50_overlap <- function(DMR1_tissue_to_overlap, DMR2_tissue_to_overlap, DMR3_tissue_to_overlap, DMR4_no_overlap, DMR5_no_overlap, DMR6_no_overlap){
  
  # Translate variables to previously-used code
  sort_humans_heart_liver_DMRs_bed <- DMR1_tissue_to_overlap
  sort_humans_liver_lung_DMRs_bed <- DMR2_tissue_to_overlap
  sort_humans_liver_kidney_DMRs_bed <- DMR3_tissue_to_overlap
  sort_humans_heart_kidney_DMRs_bed <- DMR4_no_overlap
  sort_humans_heart_lung_DMRs_bed <- DMR5_no_overlap
  sort_humans_lung_kidney_DMRs_bed <- DMR6_no_overlap

  # Run bedtools to overlap  
heart_liver_heart_lung_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_liver_lung_DMRs_bed), method = "intersect",  params = "-wao -f 0.5 -F 0.5", check.chr = FALSE)

heart_liver_heart_kidney_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_liver_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.5 -F 0.5", check.chr = FALSE)

heart_liver_liver_lung_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_heart_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.5 -F 0.5", check.chr = FALSE)

heart_liver_liver_kidney_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_heart_lung_DMRs_bed), method = "intersect",  params = "-wao -f 0.5 -F 0.5", check.chr = FALSE)

heart_liver_lung_kidney_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_lung_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.5 -F 0.5", check.chr = FALSE)


  # Convert to same name
colnames(heart_liver_heart_lung_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(heart_liver_heart_kidney_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(heart_liver_liver_lung_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(heart_liver_liver_kidney_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(heart_liver_lung_kidney_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

human_heart_liver_DMR <- left_join(heart_liver_heart_lung_only_75, heart_liver_heart_kidney_only_75, by= c("chr", "start")) %>% left_join(., heart_liver_liver_lung_only_75, by=c("chr", "start")) %>% left_join(., heart_liver_liver_kidney_only_75, by=c("chr", "start")) %>% left_join(., heart_liver_lung_kidney_only_75, by=c("chr", "start"))


DMR_tissue_specific_50 <- human_heart_liver_DMR[which(human_heart_liver_DMR[,9] > 0 & human_heart_liver_DMR[,16] > 0 & human_heart_liver_DMR[,23] < 1 & human_heart_liver_DMR[,30] < 1 & human_heart_liver_DMR[,37] < 1),]

  return(DMR_tissue_specific_50)
}



# 75% overlap

tissue_specific_75_overlap <- function(DMR1_tissue_to_overlap, DMR2_tissue_to_overlap, DMR3_tissue_to_overlap, DMR4_no_overlap, DMR5_no_overlap, DMR6_no_overlap){
  
  # Translate variables to previously-used code
  sort_humans_heart_liver_DMRs_bed <- DMR1_tissue_to_overlap
  sort_humans_liver_lung_DMRs_bed <- DMR2_tissue_to_overlap
  sort_humans_liver_kidney_DMRs_bed <- DMR3_tissue_to_overlap
  sort_humans_heart_kidney_DMRs_bed <- DMR4_no_overlap
  sort_humans_heart_lung_DMRs_bed <- DMR5_no_overlap
  sort_humans_lung_kidney_DMRs_bed <- DMR6_no_overlap

  # Run bedtools to overlap  
heart_liver_heart_lung_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_liver_lung_DMRs_bed), method = "intersect",  params = "-wao -f 0.75 -F 0.75", check.chr = FALSE)

heart_liver_heart_kidney_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_liver_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.75 -F 0.75", check.chr = FALSE)

heart_liver_liver_lung_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_heart_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.75 -F 0.75", check.chr = FALSE)

heart_liver_liver_kidney_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_heart_lung_DMRs_bed), method = "intersect",  params = "-wao -f 0.75 -F 0.75", check.chr = FALSE)

heart_liver_lung_kidney_only_75 <- bedr(input = list(a = sort_humans_heart_liver_DMRs_bed, b = sort_humans_lung_kidney_DMRs_bed), method = "intersect",  params = "-wao -f 0.75 -F 0.75", check.chr = FALSE)


  # Convert to same name
colnames(heart_liver_heart_lung_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(heart_liver_heart_kidney_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(heart_liver_liver_lung_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(heart_liver_liver_kidney_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(heart_liver_lung_kidney_only_75) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

human_heart_liver_DMR <- left_join(heart_liver_heart_lung_only_75, heart_liver_heart_kidney_only_75, by= c("chr", "start")) %>% left_join(., heart_liver_liver_lung_only_75, by=c("chr", "start")) %>% left_join(., heart_liver_liver_kidney_only_75, by=c("chr", "start")) %>% left_join(., heart_liver_lung_kidney_only_75, by=c("chr", "start"))


DMR_tissue_specific_75 <- human_heart_liver_DMR[which(human_heart_liver_DMR[,9] > 0 & human_heart_liver_DMR[,16] > 0 & human_heart_liver_DMR[,23] < 1 & human_heart_liver_DMR[,30] < 1 & human_heart_liver_DMR[,37] < 1),]

  return(DMR_tissue_specific_75)
}

Heart specific- all species

# Make a function to confirm direction. Note, this will be different for each tissue

heart_specific_direction <- function(filename_from_tissue_specific_overlap_function){
  filename_from_tissue_specific_overlap_function <- filename_from_tissue_specific_overlap_function[which(filename_from_tissue_specific_overlap_function[,4] == filename_from_tissue_specific_overlap_function[,8]),]
  filename_from_tissue_specific_overlap_function <- filename_from_tissue_specific_overlap_function[which(filename_from_tissue_specific_overlap_function[,4] == filename_from_tissue_specific_overlap_function[,11]),]
  filename_from_tissue_specific_overlap_function <- filename_from_tissue_specific_overlap_function[which(filename_from_tissue_specific_overlap_function[,4] == filename_from_tissue_specific_overlap_function[,15]),]
return(filename_from_tissue_specific_overlap_function)
  }
  
  
  
  
# Human heart specific

human_heart_specific_25 <- tissue_specific_25_overlap(sort_humans_heart_liver_DMRs_bed, sort_humans_heart_lung_DMRs_bed, sort_humans_heart_kidney_DMRs_bed, sort_humans_liver_lung_DMRs_bed, sort_humans_liver_kidney_DMRs_bed, sort_humans_lung_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3116bce9f4.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311ec9016.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3153831985.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b313c732715.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31198e5860.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31cf8d7ad.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31464f4caf.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316f6f22c.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3174c00b62.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3139b50ed4.bed -wao -f 0.25 -F 0.25
dim(human_heart_specific_25) # 2949
## [1] 2949   37
human_heart_specific_25 <- tissue_specific_25_overlap(sort_humans_heart_lung_DMRs_bed, sort_humans_heart_kidney_DMRs_bed, sort_humans_heart_liver_DMRs_bed, sort_humans_liver_lung_DMRs_bed, sort_humans_liver_kidney_DMRs_bed, sort_humans_lung_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3155969b9b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3159aecffd.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b314a8b167b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31d40faa3.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b313902b8f1.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3166eb89de.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3119bf5c4f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311527ca8d.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316598a0e3.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311982267d.bed -wao -f 0.25 -F 0.25
dim(human_heart_specific_25) #2969
## [1] 2969   37
human_heart_specific_25 <- tissue_specific_25_overlap(sort_humans_heart_kidney_DMRs_bed, sort_humans_heart_liver_DMRs_bed, sort_humans_heart_lung_DMRs_bed, sort_humans_liver_lung_DMRs_bed, sort_humans_liver_kidney_DMRs_bed, sort_humans_lung_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b317cfd358.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b315af859c6.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b312a1bee13.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316507f174.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3160388a34.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3120a89080.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b315425c5f8.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3178e48354.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b313e549ea7.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3168cc97b2.bed -wao -f 0.25 -F 0.25
dim(human_heart_specific_25) #2965
## [1] 2965   37
## 25% overlap
human_heart_specific_25 <- tissue_specific_25_overlap(sort_humans_heart_lung_DMRs_bed, sort_humans_heart_kidney_DMRs_bed, sort_humans_heart_liver_DMRs_bed, sort_humans_liver_lung_DMRs_bed, sort_humans_liver_kidney_DMRs_bed, sort_humans_lung_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b314ac601ad.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31362274f6.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31e8bf29c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3154234bea.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b314cc5c65e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b313c20cce2.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3164726552.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317a8ee9b0.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3151916346.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31479c44cc.bed -wao -f 0.25 -F 0.25
dim(human_heart_specific_25)
## [1] 2969   37
human_heart_specific_25 <- heart_specific_direction(human_heart_specific_25)
dim(human_heart_specific_25)
## [1] 2969   37
# Note: for recording #, consider using merged
#nrow(bedr.merge.region(human_DMR_heart_specific_25[,1:4]))


# 50% 

human_heart_specific_50 <- tissue_specific_50_overlap(sort_humans_heart_lung_DMRs_bed, sort_humans_heart_kidney_DMRs_bed, sort_humans_heart_liver_DMRs_bed, sort_humans_liver_lung_DMRs_bed, sort_humans_liver_kidney_DMRs_bed, sort_humans_lung_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31159f56a3.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311217c26.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3174d080b8.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317704bc58.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31e651d58.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3128357d9a.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b312d32c083.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3149291f05.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31688d7a16.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b312ad67ab.bed -wao -f 0.5 -F 0.5
dim(human_heart_specific_50)
## [1] 2134   37
human_heart_specific_50 <- heart_specific_direction(human_heart_specific_50)
dim(human_heart_specific_50)
## [1] 2133   37
# 75% 

human_heart_specific_75 <- tissue_specific_75_overlap(sort_humans_heart_lung_DMRs_bed, sort_humans_heart_kidney_DMRs_bed, sort_humans_heart_liver_DMRs_bed, sort_humans_liver_lung_DMRs_bed, sort_humans_liver_kidney_DMRs_bed, sort_humans_lung_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b313e6a93b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316458aef9.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31648d1e97.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b315617827a.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31bdabd24.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31412f941b.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316964e803.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316c329923.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b311f8d87f8.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3120724e26.bed -wao -f 0.75 -F 0.75
dim(human_heart_specific_75)
## [1] 993  37
human_heart_specific_75 <- heart_specific_direction(human_heart_specific_75)
dim(human_heart_specific_75)
## [1] 993  37
# Chimp heart specific- 25%

chimp_heart_specific_25 <- tissue_specific_25_overlap(sort_chimps_heart_lung_DMRs_bed, sort_chimps_heart_liver_DMRs_bed, sort_chimps_heart_kidney_DMRs_bed, sort_chimps_liver_lung_DMRs_bed, sort_chimps_liver_kidney_DMRs_bed, sort_chimps_lung_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31314100f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3133d82799.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3125fdf6f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31478748f0.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31604a2e25.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311b16c80e.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b311b32f10f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b314e6aa611.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b317161b353.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31664dbea3.bed -wao -f 0.25 -F 0.25
dim(chimp_heart_specific_25)
## [1] 1743   37
# Same direction

chimp_heart_specific_25 <- heart_specific_direction(chimp_heart_specific_25)
dim(chimp_heart_specific_25)
## [1] 1743   37
#nrow(bedr.merge.region(chimp_DMR_heart_specific_25[,1:4]))

# Chimp heart specific- 50%

chimp_heart_specific_50 <- tissue_specific_50_overlap(sort_chimps_heart_lung_DMRs_bed, sort_chimps_heart_liver_DMRs_bed, sort_chimps_heart_kidney_DMRs_bed, sort_chimps_liver_lung_DMRs_bed, sort_chimps_liver_kidney_DMRs_bed, sort_chimps_lung_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3127ce3872.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3134c398d.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b318906b1d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b314295e1f4.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b315c986d7e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3131cea8e3.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31118d23cd.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31397f1f1b.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b312d665a9a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3167062e21.bed -wao -f 0.5 -F 0.5
dim(chimp_heart_specific_50)
## [1] 1217   37
chimp_heart_specific_50 <- heart_specific_direction(chimp_heart_specific_50)
dim(chimp_heart_specific_50)
## [1] 1217   37
#nrow(bedr.merge.region(chimp_DMR_heart_specific_50[,1:4]))


# Chimp heart specific- 75%

chimp_heart_specific_75 <- tissue_specific_75_overlap(sort_chimps_heart_lung_DMRs_bed, sort_chimps_heart_liver_DMRs_bed, sort_chimps_heart_kidney_DMRs_bed, sort_chimps_liver_lung_DMRs_bed, sort_chimps_liver_kidney_DMRs_bed, sort_chimps_lung_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3122aabe87.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317710241.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b313e650467.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31375c3b4a.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3130be96d0.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31526679ba.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3134df3fbd.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31681e5195.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3120b2686f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317572d3a2.bed -wao -f 0.75 -F 0.75
dim(chimp_heart_specific_75)
## [1] 556  37
# Same direction
chimp_heart_specific_75 <- heart_specific_direction(chimp_heart_specific_75)
dim(chimp_heart_specific_75)
## [1] 556  37
# Rhesus heart specific- 25%

rhesus_heart_specific_25 <- tissue_specific_25_overlap(sort_rhesus_heart_lung_DMRs_bed, sort_rhesus_heart_liver_DMRs_bed, sort_rhesus_heart_kidney_DMRs_bed, sort_rhesus_liver_lung_DMRs_bed, sort_rhesus_liver_kidney_DMRs_bed, sort_rhesus_lung_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b311612e3d0.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b315170b2fc.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3170766af2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316c337082.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3145e18e3b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3148bba586.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b314047139.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31369e5e02.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31501a2e5f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317fc8b6e7.bed -wao -f 0.25 -F 0.25
dim(rhesus_heart_specific_25)
## [1] 1598   37
# Same direction

rhesus_heart_specific_25 <- heart_specific_direction(rhesus_heart_specific_25)
dim(rhesus_heart_specific_25)
## [1] 1597   37
# Rhesus heart specific- 50%

rhesus_heart_specific_50 <- tissue_specific_50_overlap(sort_rhesus_heart_lung_DMRs_bed, sort_rhesus_heart_liver_DMRs_bed, sort_rhesus_heart_kidney_DMRs_bed, sort_rhesus_liver_lung_DMRs_bed, sort_rhesus_liver_kidney_DMRs_bed, sort_rhesus_lung_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316bb52480.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3169f45a4c.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31592ee892.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3160c663ae.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b311da50f92.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317f24a073.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3114202fe0.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3177c819f9.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3145924561.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316c828453.bed -wao -f 0.5 -F 0.5
dim(rhesus_heart_specific_50)
## [1] 1148   37
# Same direction

rhesus_heart_specific_50 <- heart_specific_direction(rhesus_heart_specific_50)
dim(rhesus_heart_specific_50)
## [1] 1148   37
# Rhesus heart specific- 75%

rhesus_heart_specific_75 <- tissue_specific_75_overlap(sort_rhesus_heart_lung_DMRs_bed, sort_rhesus_heart_liver_DMRs_bed, sort_rhesus_heart_kidney_DMRs_bed, sort_rhesus_liver_lung_DMRs_bed, sort_rhesus_liver_kidney_DMRs_bed, sort_rhesus_lung_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3134dc86ba.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31305a6b60.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3122f2b779.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3154ea015f.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31e5957c7.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311acdb4a0.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31205a5962.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b315e23cbf7.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31e14c7a6.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31680e8e2b.bed -wao -f 0.75 -F 0.75
dim(rhesus_heart_specific_75)
## [1] 559  37
# Same direction

rhesus_heart_specific_75 <- heart_specific_direction(rhesus_heart_specific_75)
dim(rhesus_heart_specific_75)
## [1] 559  37

Liver specific- all species

# Make a function to confirm direction. Note, this will be different for each tissue

liver_specific_direction <- function(filename_from_tissue_specific_overlap_function){
  filename_from_tissue_specific_overlap_function <- filename_from_tissue_specific_overlap_function[which(filename_from_tissue_specific_overlap_function[,4] == filename_from_tissue_specific_overlap_function[,8]),]
  filename_from_tissue_specific_overlap_function <- filename_from_tissue_specific_overlap_function[which(filename_from_tissue_specific_overlap_function[,4] == filename_from_tissue_specific_overlap_function[,11]),]
  filename_from_tissue_specific_overlap_function <- filename_from_tissue_specific_overlap_function[which(filename_from_tissue_specific_overlap_function[,4] != filename_from_tissue_specific_overlap_function[,15]),]
return(filename_from_tissue_specific_overlap_function)
  }
  

  
  
# Human liver specific

human_liver_specific_25 <- tissue_specific_25_overlap(sort_humans_liver_kidney_DMRs_bed, sort_humans_liver_lung_DMRs_bed, sort_humans_heart_liver_DMRs_bed,  sort_humans_heart_kidney_DMRs_bed, sort_humans_heart_lung_DMRs_bed, sort_humans_lung_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31332e1df2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b312ce001a3.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3178684d40.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31380b7ce7.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b314d221d97.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b314f05ce1f.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3116474be1.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317816eea5.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31677abcd.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31174c6572.bed -wao -f 0.25 -F 0.25
dim(human_liver_specific_25) #3276
## [1] 3276   37
human_liver_specific_25 <- tissue_specific_25_overlap(sort_humans_liver_lung_DMRs_bed, sort_humans_liver_kidney_DMRs_bed, sort_humans_heart_liver_DMRs_bed,  sort_humans_heart_kidney_DMRs_bed, sort_humans_heart_lung_DMRs_bed, sort_humans_lung_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316a035066.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311fd84aa8.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3146a812a1.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3137766826.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316e6a3480.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b314e3a98d1.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316db2930.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b315f05f2b.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3134eb5c80.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b314523ddd4.bed -wao -f 0.25 -F 0.25
dim(human_liver_specific_25) #3293
## [1] 3293   37
human_liver_specific_25 <- tissue_specific_25_overlap(sort_humans_heart_liver_DMRs_bed, sort_humans_liver_lung_DMRs_bed, sort_humans_liver_kidney_DMRs_bed, sort_humans_heart_kidney_DMRs_bed, sort_humans_heart_lung_DMRs_bed, sort_humans_lung_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b317b3b95b7.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311076202.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3125506f25.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311b7ff11b.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b315485eec4.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31fecd0d6.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31310f441a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316b5a0b30.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b314f454fc7.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3126810fa8.bed -wao -f 0.25 -F 0.25
dim(human_liver_specific_25) #3280
## [1] 3280   37
## 25% overlap
human_liver_specific_25 <- tissue_specific_25_overlap(sort_humans_liver_lung_DMRs_bed, sort_humans_liver_kidney_DMRs_bed, sort_humans_heart_liver_DMRs_bed,  sort_humans_heart_kidney_DMRs_bed, sort_humans_heart_lung_DMRs_bed, sort_humans_lung_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31281b31a9.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3142879689.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b312c46ceb8.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311e57e08.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31655c0bf7.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b313d3793d1.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3174153f25.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31798e4db.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3168a7b420.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317521234e.bed -wao -f 0.25 -F 0.25
dim(human_liver_specific_25)
## [1] 3293   37
human_liver_specific_25 <- liver_specific_direction(human_liver_specific_25)
dim(human_liver_specific_25)
## [1] 3293   37
# Note: for recording #, consider using merged
#nrow(bedr.merge.region(human_DMR_heart_specific_25[,1:4]))


# 50% 

human_liver_specific_50 <- tissue_specific_50_overlap(sort_humans_liver_lung_DMRs_bed, sort_humans_liver_kidney_DMRs_bed, sort_humans_heart_liver_DMRs_bed,  sort_humans_heart_kidney_DMRs_bed, sort_humans_heart_lung_DMRs_bed, sort_humans_lung_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3162124324.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b312f6d866a.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3143c25b4b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311ae5c66a.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31582d557d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3172d8faf5.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b313e73df32.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31461c4ec6.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31376fa410.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3171301914.bed -wao -f 0.5 -F 0.5
dim(human_liver_specific_50)
## [1] 2497   37
human_liver_specific_50 <- liver_specific_direction(human_liver_specific_50)
dim(human_liver_specific_50)
## [1] 2497   37
# 75% 

human_liver_specific_75 <- tissue_specific_75_overlap(sort_humans_liver_lung_DMRs_bed, sort_humans_liver_kidney_DMRs_bed, sort_humans_heart_liver_DMRs_bed,  sort_humans_heart_kidney_DMRs_bed, sort_humans_heart_lung_DMRs_bed, sort_humans_lung_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b315713060.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31422f34d4.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3147109830.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316353ac84.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3173f3509.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316b1ece8e.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3138574ffb.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3162bec4a8.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b313e8a57fb.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b312a0fb7fd.bed -wao -f 0.75 -F 0.75
dim(human_liver_specific_75)
## [1] 1323   37
human_liver_specific_75 <- liver_specific_direction(human_liver_specific_75)
dim(human_liver_specific_75)
## [1] 1323   37
# Chimp heart specific- 25%

chimp_liver_specific_25 <- tissue_specific_25_overlap(sort_chimps_liver_lung_DMRs_bed, sort_chimps_liver_kidney_DMRs_bed, sort_chimps_heart_liver_DMRs_bed,  sort_chimps_heart_kidney_DMRs_bed, sort_chimps_heart_lung_DMRs_bed, sort_chimps_lung_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b313c9416b8.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b314418e088.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31249e1334.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3114bc50ed.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316315d2d2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3166215920.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b317d319c8f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b315d0fa49f.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3178d7a446.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b315a826a06.bed -wao -f 0.25 -F 0.25
dim(chimp_liver_specific_25)
## [1] 6377   37
chimp_liver_specific_25 <- liver_specific_direction(chimp_liver_specific_25)
dim(chimp_liver_specific_25)
## [1] 6377   37
# Chimp heart specific- 50%

chimp_liver_specific_50 <- tissue_specific_50_overlap(sort_chimps_liver_lung_DMRs_bed, sort_chimps_liver_kidney_DMRs_bed, sort_chimps_heart_liver_DMRs_bed,  sort_chimps_heart_kidney_DMRs_bed, sort_chimps_heart_lung_DMRs_bed, sort_chimps_lung_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3126759747.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317c2150b1.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316c66dcf.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b313411b3a9.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b317cddd49e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317e2eef28.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b315367ddc5.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3122e3ed71.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316ce033d8.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b314e8d748a.bed -wao -f 0.5 -F 0.5
dim(chimp_liver_specific_50)
## [1] 4959   37
chimp_liver_specific_50 <- liver_specific_direction(chimp_liver_specific_50)
dim(chimp_liver_specific_50)
## [1] 4959   37
# Chimp heart specific- 75%

chimp_liver_specific_75 <- tissue_specific_75_overlap(sort_chimps_liver_lung_DMRs_bed, sort_chimps_liver_kidney_DMRs_bed, sort_chimps_heart_liver_DMRs_bed,  sort_chimps_heart_kidney_DMRs_bed, sort_chimps_heart_lung_DMRs_bed, sort_chimps_lung_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316a3550b1.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31382fb633.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3137c51df7.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316bed37f8.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b313183da16.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b315a6e9595.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316149bb5.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b313310c6e1.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3140449cd3.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317eeb615a.bed -wao -f 0.75 -F 0.75
dim(chimp_liver_specific_75)
## [1] 2851   37
chimp_liver_specific_75 <- liver_specific_direction(chimp_liver_specific_75)
dim(chimp_liver_specific_75)
## [1] 2851   37
# Rhesus heart specific- 25%

rhesus_liver_specific_25 <- tissue_specific_25_overlap(sort_rhesus_liver_lung_DMRs_bed, sort_rhesus_liver_kidney_DMRs_bed, sort_rhesus_heart_liver_DMRs_bed,  sort_rhesus_heart_kidney_DMRs_bed, sort_rhesus_heart_lung_DMRs_bed, sort_rhesus_lung_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31722aa636.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3154b0fb93.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31691f47ae.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316c7cf8ed.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b311092a4c3.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316eb70e6.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31711bd96.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3134fbef3f.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b317c5e1b92.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3179a281ec.bed -wao -f 0.25 -F 0.25
dim(rhesus_liver_specific_25)
## [1] 11470    37
rhesus_liver_specific_25 <- liver_specific_direction(rhesus_liver_specific_25)
dim(rhesus_liver_specific_25)
## [1] 11470    37
# Rhesus heart specific- 50%

rhesus_liver_specific_50 <- tissue_specific_50_overlap(sort_rhesus_liver_lung_DMRs_bed, sort_rhesus_liver_kidney_DMRs_bed, sort_rhesus_heart_liver_DMRs_bed,  sort_rhesus_heart_kidney_DMRs_bed, sort_rhesus_heart_lung_DMRs_bed, sort_rhesus_lung_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b315a71d14.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b315fc28850.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3119069b7b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317ee64d1c.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b314becff30.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b313c074270.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316e362634.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31700414f9.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31642fdfe5.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b314f6950c5.bed -wao -f 0.5 -F 0.5
dim(rhesus_liver_specific_50)
## [1] 9549   37
rhesus_liver_specific_50 <- liver_specific_direction(rhesus_liver_specific_50)
dim(rhesus_liver_specific_50)
## [1] 9549   37
# Rhesus heart specific- 75%

rhesus_liver_specific_75 <- tissue_specific_75_overlap(sort_rhesus_liver_lung_DMRs_bed, sort_rhesus_liver_kidney_DMRs_bed, sort_rhesus_heart_liver_DMRs_bed,  sort_rhesus_heart_kidney_DMRs_bed, sort_rhesus_heart_lung_DMRs_bed, sort_rhesus_lung_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316b5dc35e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b313b10263e.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b312d54f015.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311f915e83.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3135387463.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31608e1ca.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3141306e6a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b312b44adef.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31689e9ca8.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31ad8bff1.bed -wao -f 0.75 -F 0.75
dim(rhesus_liver_specific_75)
## [1] 5949   37
rhesus_liver_specific_75 <- liver_specific_direction(rhesus_liver_specific_75)
dim(rhesus_liver_specific_75)
## [1] 5949   37

Lung specific- all species

# Make a function to confirm direction. Note, this will be different for each tissue

lung_specific_direction <- function(filename_from_tissue_specific_overlap_function){
  filename_from_tissue_specific_overlap_function <- filename_from_tissue_specific_overlap_function[which(filename_from_tissue_specific_overlap_function[,4] != filename_from_tissue_specific_overlap_function[,8]),]
  filename_from_tissue_specific_overlap_function <- filename_from_tissue_specific_overlap_function[which(filename_from_tissue_specific_overlap_function[,4] == filename_from_tissue_specific_overlap_function[,11]),]
  filename_from_tissue_specific_overlap_function <- filename_from_tissue_specific_overlap_function[which(filename_from_tissue_specific_overlap_function[,4] == filename_from_tissue_specific_overlap_function[,15]),]
return(filename_from_tissue_specific_overlap_function)
  }
  

  
  
# Human lung specific

human_lung_specific_25 <- tissue_specific_25_overlap(sort_humans_heart_lung_DMRs_bed, sort_humans_lung_kidney_DMRs_bed, sort_humans_liver_lung_DMRs_bed, sort_humans_heart_liver_DMRs_bed, sort_humans_liver_kidney_DMRs_bed, sort_humans_heart_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3144ed580a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31479142e9.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b312db8e802.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3139984bcd.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316015db21.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316ef23051.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3117d38f9.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b318ba4d6.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b315e820568.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311c9996b9.bed -wao -f 0.25 -F 0.25
dim(human_lung_specific_25) #479
## [1] 479  37
human_lung_specific_25 <- tissue_specific_25_overlap(sort_humans_lung_kidney_DMRs_bed, sort_humans_heart_lung_DMRs_bed, sort_humans_liver_lung_DMRs_bed,   sort_humans_heart_liver_DMRs_bed, sort_humans_liver_kidney_DMRs_bed, sort_humans_heart_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3123504a10.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316cf06b95.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3179e6f0d2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3140c95b69.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b311d1c03ed.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3143cc5833.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3123289315.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b312ecaaa99.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b314b238c93.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3169706853.bed -wao -f 0.25 -F 0.25
dim(human_lung_specific_25) #469
## [1] 469  37
human_lung_specific_25 <- tissue_specific_25_overlap(sort_humans_liver_lung_DMRs_bed, sort_humans_lung_kidney_DMRs_bed, sort_humans_heart_lung_DMRs_bed,    sort_humans_heart_liver_DMRs_bed, sort_humans_liver_kidney_DMRs_bed, sort_humans_heart_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316960cdb0.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3135b06b27.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316bfb6325.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317fbe63f1.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316555bcf1.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b313d77cb69.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31db704d6.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3156b9d334.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31191ec844.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31353c93c5.bed -wao -f 0.25 -F 0.25
dim(human_lung_specific_25) # 464
## [1] 464  37
## 25% overlap

human_lung_specific_25 <- tissue_specific_25_overlap(sort_humans_heart_lung_DMRs_bed, sort_humans_lung_kidney_DMRs_bed, sort_humans_liver_lung_DMRs_bed,   sort_humans_heart_liver_DMRs_bed, sort_humans_liver_kidney_DMRs_bed, sort_humans_heart_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b317dae714f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b313b6f4e10.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b312424af80.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3158d22461.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b311f0611e3.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3160dfbf67.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b312e164491.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31d6b6068.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3179466218.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31115c164f.bed -wao -f 0.25 -F 0.25
dim(human_lung_specific_25)
## [1] 479  37
human_lung_specific_25 <- lung_specific_direction(human_lung_specific_25)
dim(human_lung_specific_25)
## [1] 479  37
## 50% overlap

human_lung_specific_50 <- tissue_specific_50_overlap(sort_humans_heart_lung_DMRs_bed, sort_humans_lung_kidney_DMRs_bed, sort_humans_liver_lung_DMRs_bed,   sort_humans_heart_liver_DMRs_bed, sort_humans_liver_kidney_DMRs_bed, sort_humans_heart_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3135a2f6cb.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b312897c696.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3135fa31e5.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31e164120.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b317d239bce.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317eadc05d.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3160b9a294.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3137784567.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b313a1ed537.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31319f3619.bed -wao -f 0.5 -F 0.5
dim(human_lung_specific_50)
## [1] 267  37
human_lung_specific_50 <- lung_specific_direction(human_lung_specific_50)
dim(human_lung_specific_50)
## [1] 266  37
## 75% overlap

human_lung_specific_75 <- tissue_specific_75_overlap(sort_humans_heart_lung_DMRs_bed, sort_humans_lung_kidney_DMRs_bed, sort_humans_liver_lung_DMRs_bed,   sort_humans_heart_liver_DMRs_bed, sort_humans_liver_kidney_DMRs_bed, sort_humans_heart_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3139ab4465.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3163e709a4.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b311909fe77.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31a6d13d2.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3112c5a9e6.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31794cbb54.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31249ad634.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3149ff2987.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31309b754e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3166132efd.bed -wao -f 0.75 -F 0.75
dim(human_lung_specific_75)
## [1] 84 37
human_lung_specific_75 <- lung_specific_direction(human_lung_specific_75)
dim(human_lung_specific_75)
## [1] 84 37
## Chimp liver specific

## 25% overlap

chimp_lung_specific_25 <- tissue_specific_25_overlap(sort_chimps_heart_lung_DMRs_bed, sort_chimps_lung_kidney_DMRs_bed, sort_chimps_liver_lung_DMRs_bed,   sort_chimps_heart_liver_DMRs_bed, sort_chimps_liver_kidney_DMRs_bed, sort_chimps_heart_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b312dd0acf7.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317147d14d.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b311a2390e5.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3114f2dcee.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b312c4362f2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3168098574.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b314a447d85.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b314a94b216.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3165c64783.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b318aa6297.bed -wao -f 0.25 -F 0.25
dim(chimp_lung_specific_25)
## [1] 454  37
chimp_lung_specific_25 <- lung_specific_direction(chimp_lung_specific_25)
dim(chimp_lung_specific_25)
## [1] 453  37
## 50% overlap

chimp_lung_specific_50 <- tissue_specific_50_overlap(sort_chimps_heart_lung_DMRs_bed, sort_chimps_lung_kidney_DMRs_bed, sort_chimps_liver_lung_DMRs_bed,   sort_chimps_heart_liver_DMRs_bed, sort_chimps_liver_kidney_DMRs_bed, sort_chimps_heart_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3173283f3c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3132815855.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3161e9776c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31352641e.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31f94cc.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31630df6e0.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b311dad60c2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b312613faf7.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3156e44f94.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b313172cfe3.bed -wao -f 0.5 -F 0.5
dim(chimp_lung_specific_50)
## [1] 294  37
chimp_lung_specific_50 <- lung_specific_direction(chimp_lung_specific_50)
dim(chimp_lung_specific_50)
## [1] 294  37
## 75% overlap

chimp_lung_specific_75 <- tissue_specific_75_overlap(sort_chimps_heart_lung_DMRs_bed, sort_chimps_lung_kidney_DMRs_bed, sort_chimps_liver_lung_DMRs_bed,   sort_chimps_heart_liver_DMRs_bed, sort_chimps_liver_kidney_DMRs_bed, sort_chimps_heart_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316ea0cc40.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3124df7ab8.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b313d472b4e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31257b6c18.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3113b91a7c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31133de43f.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b313c63d50e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317e6888ef.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3144f97171.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b313b8e23a2.bed -wao -f 0.75 -F 0.75
dim(chimp_lung_specific_75)
## [1] 117  37
chimp_lung_specific_75 <- lung_specific_direction(chimp_lung_specific_75)
dim(chimp_lung_specific_75)
## [1] 117  37
# Rhesus lung specific

## 25% overlap

rhesus_lung_specific_25 <- tissue_specific_25_overlap(sort_rhesus_heart_lung_DMRs_bed, sort_rhesus_lung_kidney_DMRs_bed, sort_rhesus_liver_lung_DMRs_bed,   sort_rhesus_heart_liver_DMRs_bed, sort_rhesus_liver_kidney_DMRs_bed, sort_rhesus_heart_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31613b1cae.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b312c3a12d0.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3115f8b72c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b313bf2e4ee.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31162227a8.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311f69ddde.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31333cb35b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3133b938a0.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316b81a2bf.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311ffc67a.bed -wao -f 0.25 -F 0.25
dim(rhesus_lung_specific_25)
## [1] 530  37
rhesus_lung_specific_25 <- lung_specific_direction(rhesus_lung_specific_25)
dim(rhesus_lung_specific_25)
## [1] 526  37
## 50% overlap

rhesus_lung_specific_50 <- tissue_specific_50_overlap(sort_rhesus_heart_lung_DMRs_bed, sort_rhesus_lung_kidney_DMRs_bed, sort_rhesus_liver_lung_DMRs_bed,   sort_rhesus_heart_liver_DMRs_bed, sort_rhesus_liver_kidney_DMRs_bed, sort_rhesus_heart_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b312de1e8a6.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b315e230222.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b315e8afd97.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3134935192.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3142c62b8d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31737d18ac.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316bd5051a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b313e0f4b08.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3132fc7fb9.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31319e1974.bed -wao -f 0.5 -F 0.5
dim(rhesus_lung_specific_50)
## [1] 327  37
rhesus_lung_specific_50 <- lung_specific_direction(rhesus_lung_specific_50)
dim(rhesus_lung_specific_50)
## [1] 324  37
## 75% overlap

rhesus_lung_specific_75 <- tissue_specific_75_overlap(sort_rhesus_heart_lung_DMRs_bed, sort_rhesus_lung_kidney_DMRs_bed, sort_rhesus_liver_lung_DMRs_bed,   sort_rhesus_heart_liver_DMRs_bed, sort_rhesus_liver_kidney_DMRs_bed, sort_rhesus_heart_kidney_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b311f874974.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3138c5e869.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3145dd72ec.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b315d6b512f.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3139b2ef4f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317e87ed2e.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3140107713.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b314cf2fa76.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b317ebc3d29.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b315eb96de3.bed -wao -f 0.75 -F 0.75
dim(rhesus_lung_specific_75)
## [1] 157  37
rhesus_lung_specific_75 <- lung_specific_direction(rhesus_lung_specific_75)
dim(rhesus_lung_specific_75)
## [1] 153  37

Kidney specific- all species

# Make a function to confirm direction. Note, this will be different for each tissue

kidney_specific_direction <- function(filename_from_tissue_specific_overlap_function){
  filename_from_tissue_specific_overlap_function <- filename_from_tissue_specific_overlap_function[which(filename_from_tissue_specific_overlap_function[,4] == filename_from_tissue_specific_overlap_function[,8]),]
  filename_from_tissue_specific_overlap_function <- filename_from_tissue_specific_overlap_function[which(filename_from_tissue_specific_overlap_function[,4] == filename_from_tissue_specific_overlap_function[,11]),]
  filename_from_tissue_specific_overlap_function <- filename_from_tissue_specific_overlap_function[which(filename_from_tissue_specific_overlap_function[,4] == filename_from_tissue_specific_overlap_function[,15]),]
return(filename_from_tissue_specific_overlap_function)
  }
  

  
  
# Human kidney specific

human_kidney_specific_25 <- tissue_specific_25_overlap(sort_humans_lung_kidney_DMRs_bed, sort_humans_liver_kidney_DMRs_bed, sort_humans_heart_kidney_DMRs_bed, sort_humans_liver_lung_DMRs_bed, sort_humans_heart_liver_DMRs_bed,  sort_humans_heart_lung_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31683ac3f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31434c6fa2.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3126735e34.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31f4f7d98.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3135fd2c5c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b313bf7c41e.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316b8b45b9.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3144682c73.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3114103c21.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3154e91b5f.bed -wao -f 0.25 -F 0.25
dim(human_kidney_specific_25) # 3968
## [1] 3968   37
human_kidney_specific_25 <- tissue_specific_25_overlap(sort_humans_liver_kidney_DMRs_bed, sort_humans_heart_kidney_DMRs_bed, sort_humans_lung_kidney_DMRs_bed, sort_humans_liver_lung_DMRs_bed, sort_humans_heart_liver_DMRs_bed,  sort_humans_heart_lung_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3190db3fd.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31723dd243.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3123e38b25.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b313feef680.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3124fbe95a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3145994666.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3141ba0861.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3143531d3b.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3121235cad.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3111f2dd75.bed -wao -f 0.25 -F 0.25
dim(human_kidney_specific_25) # 3940
## [1] 3940   37
human_kidney_specific_25 <- tissue_specific_25_overlap(sort_humans_heart_kidney_DMRs_bed, sort_humans_lung_kidney_DMRs_bed, sort_humans_liver_kidney_DMRs_bed, sort_humans_liver_lung_DMRs_bed, sort_humans_heart_liver_DMRs_bed,  sort_humans_heart_lung_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b311fdb3bba.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3156febbe9.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b315978b71a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31598999c5.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31686e62f3.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b315aaac908.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31130ff929.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316ea81533.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3155ca15dd.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3140caaf7f.bed -wao -f 0.25 -F 0.25
dim(human_kidney_specific_25)  # 3962
## [1] 3962   37
## 25% overlap

human_kidney_specific_25 <- tissue_specific_25_overlap(sort_humans_lung_kidney_DMRs_bed, sort_humans_liver_kidney_DMRs_bed, sort_humans_heart_kidney_DMRs_bed, sort_humans_liver_lung_DMRs_bed, sort_humans_heart_liver_DMRs_bed,  sort_humans_heart_lung_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b315e76138b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3146f50fda.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3116d485dc.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3165996e8c.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3182da224.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b315889668.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b317e5bbfb5.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31a703e03.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b313ed6bd9e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316da1d03.bed -wao -f 0.25 -F 0.25
dim(human_kidney_specific_25)
## [1] 3968   37
human_kidney_specific_25 <- kidney_specific_direction(human_kidney_specific_25)
dim(human_kidney_specific_25)
## [1] 3967   37
## 50% overlap

human_kidney_specific_50 <- tissue_specific_50_overlap(sort_humans_lung_kidney_DMRs_bed, sort_humans_liver_kidney_DMRs_bed, sort_humans_heart_kidney_DMRs_bed, sort_humans_liver_lung_DMRs_bed, sort_humans_heart_liver_DMRs_bed,  sort_humans_heart_lung_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b313cb30663.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311aad4ca0.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3166e9b4e1.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b313c3b737b.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b315a6b8c34.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3164db3117.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31466e2ee2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3133ab495e.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b313ab8f45d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3145cf99d4.bed -wao -f 0.5 -F 0.5
dim(human_kidney_specific_50)
## [1] 3018   37
human_kidney_specific_50 <- kidney_specific_direction(human_kidney_specific_50)
dim(human_kidney_specific_50)
## [1] 3017   37
## 75% overlap

human_kidney_specific_75 <- tissue_specific_75_overlap(sort_humans_lung_kidney_DMRs_bed, sort_humans_liver_kidney_DMRs_bed, sort_humans_heart_kidney_DMRs_bed, sort_humans_liver_lung_DMRs_bed, sort_humans_heart_liver_DMRs_bed,  sort_humans_heart_lung_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31539fb526.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b312d6fdc54.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b314e3b4bbb.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3124ee90ba.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3168539127.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3146119f47.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316ca67a74.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b314e6880e6.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b314cd8aeec.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317df79ecc.bed -wao -f 0.75 -F 0.75
dim(human_kidney_specific_75)
## [1] 1532   37
human_kidney_specific_75 <- kidney_specific_direction(human_kidney_specific_75)
dim(human_kidney_specific_75)
## [1] 1531   37
# Chimp kidney specific

## 25% overlap

chimp_kidney_specific_25 <- tissue_specific_25_overlap(sort_chimps_lung_kidney_DMRs_bed, sort_chimps_liver_kidney_DMRs_bed, sort_chimps_heart_kidney_DMRs_bed, sort_chimps_liver_lung_DMRs_bed, sort_chimps_heart_liver_DMRs_bed,  sort_chimps_heart_lung_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b318992425.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316b0ab106.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3172bb4b0.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3120ad7adf.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b314fb4fb54.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31e8b9715.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b318d5bd53.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3115633adc.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b317015d160.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b312b7c2df5.bed -wao -f 0.25 -F 0.25
dim(chimp_kidney_specific_25)
## [1] 2304   37
chimp_kidney_specific_25 <- kidney_specific_direction(chimp_kidney_specific_25)
dim(chimp_kidney_specific_25)
## [1] 2302   37
## 50% overlap

chimp_kidney_specific_50 <- tissue_specific_50_overlap(sort_chimps_lung_kidney_DMRs_bed, sort_chimps_liver_kidney_DMRs_bed, sort_chimps_heart_kidney_DMRs_bed, sort_chimps_liver_lung_DMRs_bed, sort_chimps_heart_liver_DMRs_bed,  sort_chimps_heart_lung_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3126221967.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31216a079b.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3139090ecd.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31e42ead7.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3116f92b4e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31286bf4da.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b313265fd5b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3120ceb606.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3128986f70.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311bd24a45.bed -wao -f 0.5 -F 0.5
dim(chimp_kidney_specific_50)
## [1] 1734   37
chimp_kidney_specific_50 <- kidney_specific_direction(chimp_kidney_specific_50)
dim(chimp_kidney_specific_50)
## [1] 1729   37
## 75% overlap

chimp_kidney_specific_75 <- tissue_specific_75_overlap(sort_chimps_lung_kidney_DMRs_bed, sort_chimps_liver_kidney_DMRs_bed, sort_chimps_heart_kidney_DMRs_bed, sort_chimps_liver_lung_DMRs_bed, sort_chimps_heart_liver_DMRs_bed,  sort_chimps_heart_lung_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316b7ff468.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311f3e4590.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3124114074.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31581a4409.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3118fad72e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3159f547bb.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3137c17d76.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b315cc9c10a.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3138f9d000.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317e8e6e17.bed -wao -f 0.75 -F 0.75
dim(chimp_kidney_specific_75)
## [1] 855  37
chimp_kidney_specific_75 <- kidney_specific_direction(chimp_kidney_specific_75)
dim(chimp_kidney_specific_75)
## [1] 854  37
# Rhesus kidney specific

## 25% overlap

rhesus_kidney_specific_25 <- tissue_specific_25_overlap(sort_rhesus_lung_kidney_DMRs_bed, sort_rhesus_liver_kidney_DMRs_bed, sort_rhesus_heart_kidney_DMRs_bed, sort_rhesus_liver_lung_DMRs_bed, sort_rhesus_heart_liver_DMRs_bed,  sort_rhesus_heart_lung_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b312ac43298.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b315d45870a.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31554a2c1c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3169f83808.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3176d718c7.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3171068f44.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3175d43c18.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31477751f5.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316b581f3d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3138669714.bed -wao -f 0.25 -F 0.25
dim(rhesus_kidney_specific_25)
## [1] 3560   37
rhesus_kidney_specific_25 <- kidney_specific_direction(rhesus_kidney_specific_25)
dim(rhesus_kidney_specific_25)
## [1] 3555   37
## 50% overlap

rhesus_kidney_specific_50 <- tissue_specific_50_overlap(sort_rhesus_lung_kidney_DMRs_bed, sort_rhesus_liver_kidney_DMRs_bed, sort_rhesus_heart_kidney_DMRs_bed, sort_rhesus_liver_lung_DMRs_bed, sort_rhesus_heart_liver_DMRs_bed,  sort_rhesus_heart_lung_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3166616018.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31339e85e2.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b315ee24b53.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3138747d82.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3141a81c1b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3134b42f9.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b311e473d58.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3178630056.bed -wao -f 0.5 -F 0.5
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3168961142.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31600199ab.bed -wao -f 0.5 -F 0.5
dim(rhesus_kidney_specific_50)
## [1] 2686   37
rhesus_kidney_specific_50 <- kidney_specific_direction(rhesus_kidney_specific_50)
dim(rhesus_kidney_specific_50)
## [1] 2673   37
## 75% overlap

rhesus_kidney_specific_75 <- tissue_specific_75_overlap(sort_rhesus_lung_kidney_DMRs_bed, sort_rhesus_liver_kidney_DMRs_bed, sort_rhesus_heart_kidney_DMRs_bed, sort_rhesus_liver_lung_DMRs_bed, sort_rhesus_heart_liver_DMRs_bed,  sort_rhesus_heart_lung_DMRs_bed)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3136621d22.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3141232961.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b317c2a167c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31773e1bd0.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31a1f03fe.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31d30d34f.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3133ccbe10.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317cd3bec6.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b311185ac36.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3111daa7b4.bed -wao -f 0.75 -F 0.75
dim(rhesus_kidney_specific_75)
## [1] 1404   37
rhesus_kidney_specific_75 <- kidney_specific_direction(rhesus_kidney_specific_75)
dim(rhesus_kidney_specific_75)
## [1] 1397   37

Heart specific: Conserved versus human specific

### 25% overlap

human_chimp_heart_specific_25 <- bedr(input = list(a = human_heart_specific_25[,1:4], b = chimp_heart_specific_25[,1:4]), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3110304869.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3158de5e33.bed -wao -f 0.25 -F 0.25
# Human-chimp conserved

human_chimp_heart_specific_25_hs <- human_chimp_heart_specific_25[which(human_chimp_heart_specific_25[,9] == 0), ]
colnames(human_chimp_heart_specific_25_hs) <- c("chr", "start", "end")
human_chimp_heart_specific_25_conserved <- human_chimp_heart_specific_25[which(human_chimp_heart_specific_25[,9] > 0), ]

#write.table(human_chimp_heart_specific_25_hs[,1:4], "../data/human_chimp_heart_specific_25_hs.bed", quote = FALSE, row.names = FALSE, sep = "\t")

human_chimp_heart_specific_25_conserved <- human_chimp_heart_specific_25_conserved[which(human_chimp_heart_specific_25_conserved[,4] == human_chimp_heart_specific_25_conserved[,8]),]

#write.table(human_chimp_heart_specific_25_conserved[,1:4], "../data/human_chimp_heart_specific_25_conserved.bed", quote = FALSE, row.names = FALSE, sep = "\t")

# Human-chimp-rhesus 

human_rhesus_heart_specific_25 <- bedr(input = list(a = human_heart_specific_25[,1:4], b = rhesus_heart_specific_25[,1:4]), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31756369cd.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3126986cc5.bed -wao -f 0.25 -F 0.25
colnames(human_chimp_heart_specific_25) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(human_rhesus_heart_specific_25) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")


human_chimp_rhesus_heart_specific_25 <- left_join(human_chimp_heart_specific_25, human_rhesus_heart_specific_25, by= c("chr", "start")) 

# Human-chimp-rhesus conserved

human_chimp_rhesus_heart_specific_25_hs <- human_chimp_rhesus_heart_specific_25[which(human_chimp_rhesus_heart_specific_25[,9] == 0 & human_chimp_rhesus_heart_specific_25[,16] == 0), ]

#write.table(human_chimp_rhesus_heart_specific_25_hs[,1:4], "../data/human_chimp_rhesus_heart_specific_25_hs.bed", quote = FALSE, row.names = FALSE, sep = "\t")

human_chimp_rhesus_heart_specific_25_conserved <- human_chimp_rhesus_heart_specific_25[which(human_chimp_rhesus_heart_specific_25[,9] > 0 & human_chimp_rhesus_heart_specific_25[,16] > 0),]

human_chimp_rhesus_heart_specific_25_conserved <- human_chimp_rhesus_heart_specific_25_conserved[which(human_chimp_rhesus_heart_specific_25_conserved[,4] == human_chimp_rhesus_heart_specific_25_conserved[,8]),]

human_chimp_rhesus_heart_specific_25_conserved <- human_chimp_rhesus_heart_specific_25_conserved[which(human_chimp_rhesus_heart_specific_25_conserved[,11] == human_chimp_rhesus_heart_specific_25_conserved[,15]),]

#write.table(human_chimp_rhesus_heart_specific_25_conserved[,1:4], "../data/human_chimp_rhesus_heart_specific_25_conserved.bed", quote = FALSE, row.names = FALSE, sep = "\t")

# Make a Venn diagram of the overlap






### 50% overlap

human_chimp_heart_specific_50 <- bedr(input = list(a = human_DMR_heart_specific_50[,1:4], b = chimp_DMR_heart_specific_50[,1:4]), method = "intersect",  params = "-wao -f 0.50 -F 0.50", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b315e45429a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3114c624d0.bed -wao -f 0.50 -F 0.50
# Human-chimp conserved

human_chimp_heart_specific_50_hs <- human_chimp_heart_specific_50[which(human_chimp_heart_specific_50[,9] == 0), ]

human_chimp_heart_specific_50_conserved <- human_chimp_heart_specific_50[which(human_chimp_heart_specific_50[,9] > 0), ]

human_chimp_heart_specific_50_conserved <- human_chimp_heart_specific_50_conserved[which(human_chimp_heart_specific_50_conserved[,4] == human_chimp_heart_specific_50_conserved[,8]),]



# Human-chimp-rhesus 

human_rhesus_heart_specific_50 <- bedr(input = list(a = human_DMR_heart_specific_50[,1:4], b = rhesus_DMR_heart_specific_50[,1:4]), method = "intersect",  params = "-wao -f 0.50 -F 0.50", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b311d135f42.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3117925759.bed -wao -f 0.50 -F 0.50
human_chimp_rhesus_heart_specific_50 <- cbind(human_chimp_heart_specific_50, human_rhesus_heart_specific_50)

# Human-chimp-rhesus-conserved

human_chimp_rhesus_heart_specific_50_hs <- human_chimp_rhesus_heart_specific_50[which(human_chimp_rhesus_heart_specific_50[,9] == 0 & human_chimp_rhesus_heart_specific_50[,18] == 0), ]

human_chimp_rhesus_heart_specific_50_conserved <- human_chimp_rhesus_heart_specific_50[which(human_chimp_rhesus_heart_specific_50[,9] > 0 & human_chimp_rhesus_heart_specific_50[,18] > 0),]

human_chimp_rhesus_heart_specific_50_conserved <- human_chimp_rhesus_heart_specific_50_conserved[which(human_chimp_rhesus_heart_specific_50_conserved[,9] == human_chimp_rhesus_heart_specific_50_conserved[,18]),]

human_chimp_rhesus_heart_specific_50_conserved <- human_chimp_rhesus_heart_specific_50_conserved[which(human_chimp_rhesus_heart_specific_50_conserved[,9] == human_chimp_rhesus_heart_specific_50_conserved[,18]),]

#write.table(human_chimp_heart_specific_50_hs[,1:4], "../data/human_chimp_heart_specific_50_hs.bed", quote = FALSE, row.names = FALSE, sep = "\t")

summary(human_chimp_heart_specific_50_hs[,3]-human_chimp_heart_specific_50_hs[,2])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     6.0   411.2   661.0   726.1   974.8  4314.0
#write.table(human_chimp_heart_specific_50_conserved[,1:4], "../data/human_chimp_heart_specific_50_conserved.bed", quote = FALSE, row.names = FALSE, sep = "\t")

summary(human_chimp_heart_specific_50_conserved[,3]-human_chimp_heart_specific_50_conserved[,2])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   105.0   679.0   933.5   967.2  1245.2  3237.0
### 75% overlap

human_chimp_heart_specific_75 <- bedr(input = list(a = human_DMR_heart_specific_75[,1:4], b = chimp_DMR_heart_specific_75[,1:4]), method = "intersect",  params = "-wao -f 0.75 -F 0.75", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31302a6b01.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3155f54dc9.bed -wao -f 0.75 -F 0.75
# Human-chimp conserved

human_chimp_heart_specific_75_hs <- human_chimp_heart_specific_75[which(human_chimp_heart_specific_75[,9] == 0), ]

human_chimp_heart_specific_75_conserved <- human_chimp_heart_specific_75[which(human_chimp_heart_specific_75[,9] > 0), ]

human_chimp_heart_specific_75_conserved <- human_chimp_heart_specific_75_conserved[which(human_chimp_heart_specific_75_conserved[,4] == human_chimp_heart_specific_75_conserved[,8]),]

# Human-chimp-rhesus 

human_rhesus_heart_specific_75 <- bedr(input = list(a = human_DMR_heart_specific_75[,1:4], b = rhesus_DMR_heart_specific_75[,1:4]), method = "intersect",  params = "-wao -f 0.75 -F 0.75", check.chr = FALSE)
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3168d44e80.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316d6a3277.bed -wao -f 0.75 -F 0.75
human_chimp_rhesus_heart_specific_75 <- cbind(human_chimp_heart_specific_75, human_rhesus_heart_specific_75)

# Human-chimp-rhesus-conserved

human_chimp_rhesus_heart_specific_75_hs <- human_chimp_rhesus_heart_specific_75[which(human_chimp_rhesus_heart_specific_75[,9] == 0 & human_chimp_rhesus_heart_specific_75[,18] == 0), ]

human_chimp_rhesus_heart_specific_75_conserved <- human_chimp_rhesus_heart_specific_75[which(human_chimp_rhesus_heart_specific_75[,9] > 0 & human_chimp_rhesus_heart_specific_75[,18] > 0),]

dim(human_chimp_rhesus_heart_specific_75_conserved)
## [1]  3 18

General function for identifying conserved versus human-specific tDMRs

human_chimp_rhesus_hs_versus_overlap_25 <- function(human_DMR_tissue_specific, chimp_DMR_tissue_specific, rhesus_DMR_tissue_specific, put_human_specific, put_human_chimp_conserved, put_human_specific_in_hcr, put_human_chimp_rhesus_conserved){
  # Rename
  human_DMR_heart_specific_25 <- human_DMR_tissue_specific[,1:4]
  chimp_DMR_heart_specific_25 <- chimp_DMR_tissue_specific[,1:4]
  rhesus_DMR_heart_specific_25 <- rhesus_DMR_tissue_specific[,1:4]
  
  human_DMR_heart_specific_25 <- bedr.merge.region(human_DMR_heart_specific_25)
  chimp_DMR_heart_specific_25 <- bedr.merge.region(chimp_DMR_heart_specific_25)
  rhesus_DMR_heart_specific_25 <- bedr.merge.region(rhesus_DMR_heart_specific_25)
   
  # Find the human 
human_chimp_heart_specific_25 <- bedr(input = list(a = human_DMR_heart_specific_25, b = chimp_DMR_heart_specific_25), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)

human_chimp_heart_specific_25_hs <- human_chimp_heart_specific_25[which(human_chimp_heart_specific_25[,9] == 0), ]
colnames(human_chimp_heart_specific_25_hs) <- c("chr", "start", "end")

#write.table(human_chimp_heart_specific_25_hs[,1:4], put_human_specific, quote = FALSE, row.names = FALSE, sep = "\t")

# Human-chimp conserved

human_chimp_heart_specific_25_conserved <- human_chimp_heart_specific_25[which(human_chimp_heart_specific_25[,9] > 0), ]

human_chimp_heart_specific_25_conserved <- human_chimp_heart_specific_25_conserved[which(human_chimp_heart_specific_25_conserved[,4] == human_chimp_heart_specific_25_conserved[,8]),]

#write.table(human_chimp_heart_specific_25_conserved[,1:4], put_human_chimp_conserved, quote = FALSE, row.names = FALSE, sep = "\t")



# Human-chimp-rhesus 

human_rhesus_heart_specific_25 <- bedr(input = list(a = human_DMR_heart_specific_25[,1:4], b = rhesus_DMR_heart_specific_25[,1:4]), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)

colnames(human_chimp_heart_specific_25) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(human_rhesus_heart_specific_25) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")


human_chimp_rhesus_heart_specific_25 <- left_join(human_chimp_heart_specific_25, human_rhesus_heart_specific_25, by= c("chr", "start")) 

# Human-chimp-rhesus conserved

human_chimp_rhesus_heart_specific_25_hs <- human_chimp_rhesus_heart_specific_25[which(human_chimp_rhesus_heart_specific_25[,9] == 0 & human_chimp_rhesus_heart_specific_25[,16] == 0), ]

#write.table(human_chimp_rhesus_heart_specific_25_hs[,1:4], put_human_specific_in_hcr, quote = FALSE, row.names = FALSE, sep = "\t")

human_chimp_rhesus_heart_specific_25_conserved <- human_chimp_rhesus_heart_specific_25[which(human_chimp_rhesus_heart_specific_25[,9] > 0 & human_chimp_rhesus_heart_specific_25[,16] > 0),]

human_chimp_rhesus_heart_specific_25_conserved <- human_chimp_rhesus_heart_specific_25_conserved[which(human_chimp_rhesus_heart_specific_25_conserved[,4] == human_chimp_rhesus_heart_specific_25_conserved[,8]),]

human_chimp_rhesus_heart_specific_25_conserved <- human_chimp_rhesus_heart_specific_25_conserved[which(human_chimp_rhesus_heart_specific_25_conserved[,11] == human_chimp_rhesus_heart_specific_25_conserved[,15]),]

#write.table(human_chimp_rhesus_heart_specific_25_conserved[,1:4], put_human_chimp_rhesus_conserved, quote = FALSE, row.names = FALSE, sep = "\t")

  row_numbers <- cbind(nrow(human_chimp_heart_specific_25_hs), nrow(human_chimp_heart_specific_25_conserved), nrow(human_chimp_rhesus_heart_specific_25_hs), nrow(human_chimp_rhesus_heart_specific_25_conserved))
  
  return(row_numbers)

}

# 50% overlap

human_chimp_rhesus_hs_versus_overlap_50 <- function(human_DMR_tissue_specific, chimp_DMR_tissue_specific, rhesus_DMR_tissue_specific, put_human_specific, put_human_chimp_conserved, put_human_specific_in_hcr, put_human_chimp_rhesus_conserved){
  # Rename
  human_DMR_heart_specific_25 <- human_DMR_tissue_specific[,1:4]
  chimp_DMR_heart_specific_25 <- chimp_DMR_tissue_specific[,1:4]
  rhesus_DMR_heart_specific_25 <- rhesus_DMR_tissue_specific[,1:4]
  
  human_DMR_heart_specific_25 <- bedr.merge.region(human_DMR_heart_specific_25)
  chimp_DMR_heart_specific_25 <- bedr.merge.region(chimp_DMR_heart_specific_25)
  rhesus_DMR_heart_specific_25 <- bedr.merge.region(rhesus_DMR_heart_specific_25)
   
  # Find the human 
human_chimp_heart_specific_25 <- bedr(input = list(a = human_DMR_heart_specific_25, b = chimp_DMR_heart_specific_25), method = "intersect",  params = "-wao -f 0.50 -F 0.50", check.chr = FALSE)

human_chimp_heart_specific_25_hs <- human_chimp_heart_specific_25[which(human_chimp_heart_specific_25[,9] == 0), ]
colnames(human_chimp_heart_specific_25_hs) <- c("chr", "start", "end")

#write.table(human_chimp_heart_specific_25_hs[,1:4], put_human_specific, quote = FALSE, row.names = FALSE, sep = "\t")

# Human-chimp conserved

human_chimp_heart_specific_25_conserved <- human_chimp_heart_specific_25[which(human_chimp_heart_specific_25[,9] > 0), ]

human_chimp_heart_specific_25_conserved <- human_chimp_heart_specific_25_conserved[which(human_chimp_heart_specific_25_conserved[,4] == human_chimp_heart_specific_25_conserved[,8]),]

#write.table(human_chimp_heart_specific_25_conserved[,1:4], put_human_chimp_conserved, quote = FALSE, row.names = FALSE, sep = "\t")



# Human-chimp-rhesus 

human_rhesus_heart_specific_25 <- bedr(input = list(a = human_DMR_heart_specific_25[,1:4], b = rhesus_DMR_heart_specific_25[,1:4]), method = "intersect",  params = "-wao -f 0.50 -F 0.50", check.chr = FALSE)

colnames(human_chimp_heart_specific_25) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(human_rhesus_heart_specific_25) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")


human_chimp_rhesus_heart_specific_25 <- left_join(human_chimp_heart_specific_25, human_rhesus_heart_specific_25, by= c("chr", "start")) 

# Human-chimp-rhesus conserved

human_chimp_rhesus_heart_specific_25_hs <- human_chimp_rhesus_heart_specific_25[which(human_chimp_rhesus_heart_specific_25[,9] == 0 & human_chimp_rhesus_heart_specific_25[,16] == 0), ]

#write.table(human_chimp_rhesus_heart_specific_25_hs[,1:4], put_human_specific_in_hcr, quote = FALSE, row.names = FALSE, sep = "\t")

human_chimp_rhesus_heart_specific_25_conserved <- human_chimp_rhesus_heart_specific_25[which(human_chimp_rhesus_heart_specific_25[,9] > 0 & human_chimp_rhesus_heart_specific_25[,16] > 0),]

human_chimp_rhesus_heart_specific_25_conserved <- human_chimp_rhesus_heart_specific_25_conserved[which(human_chimp_rhesus_heart_specific_25_conserved[,4] == human_chimp_rhesus_heart_specific_25_conserved[,8]),]

human_chimp_rhesus_heart_specific_25_conserved <- human_chimp_rhesus_heart_specific_25_conserved[which(human_chimp_rhesus_heart_specific_25_conserved[,11] == human_chimp_rhesus_heart_specific_25_conserved[,15]),]

#write.table(human_chimp_rhesus_heart_specific_25_conserved[,1:4], put_human_chimp_rhesus_conserved, quote = FALSE, row.names = FALSE, sep = "\t")

  row_numbers <- cbind(nrow(human_chimp_heart_specific_25_hs), nrow(human_chimp_heart_specific_25_conserved), nrow(human_chimp_rhesus_heart_specific_25_hs), nrow(human_chimp_rhesus_heart_specific_25_conserved))
  
  return(row_numbers)

}


# 75% overlap

human_chimp_rhesus_hs_versus_overlap_75 <- function(human_DMR_tissue_specific, chimp_DMR_tissue_specific, rhesus_DMR_tissue_specific, put_human_specific, put_human_chimp_conserved, put_human_specific_in_hcr, put_human_chimp_rhesus_conserved){
  # Rename
  human_DMR_heart_specific_25 <- human_DMR_tissue_specific[,1:4]
  chimp_DMR_heart_specific_25 <- chimp_DMR_tissue_specific[,1:4]
  rhesus_DMR_heart_specific_25 <- rhesus_DMR_tissue_specific[,1:4]
  
  human_DMR_heart_specific_25 <- bedr.merge.region(human_DMR_heart_specific_25)
  chimp_DMR_heart_specific_25 <- bedr.merge.region(chimp_DMR_heart_specific_25)
  rhesus_DMR_heart_specific_25 <- bedr.merge.region(rhesus_DMR_heart_specific_25)
   
  # Find the human 
human_chimp_heart_specific_25 <- bedr(input = list(a = human_DMR_heart_specific_25, b = chimp_DMR_heart_specific_25), method = "intersect",  params = "-wao -f 0.75 -F 0.75", check.chr = FALSE)

human_chimp_heart_specific_25_hs <- human_chimp_heart_specific_25[which(human_chimp_heart_specific_25[,9] == 0), ]
colnames(human_chimp_heart_specific_25_hs) <- c("chr", "start", "end")

#write.table(human_chimp_heart_specific_25_hs[,1:4], put_human_specific, quote = FALSE, row.names = FALSE, sep = "\t")

# Human-chimp conserved

human_chimp_heart_specific_25_conserved <- human_chimp_heart_specific_25[which(human_chimp_heart_specific_25[,9] > 0), ]

human_chimp_heart_specific_25_conserved <- human_chimp_heart_specific_25_conserved[which(human_chimp_heart_specific_25_conserved[,4] == human_chimp_heart_specific_25_conserved[,8]),]

#write.table(human_chimp_heart_specific_25_conserved[,1:4], put_human_chimp_conserved, quote = FALSE, row.names = FALSE, sep = "\t")



# Human-chimp-rhesus 

human_rhesus_heart_specific_25 <- bedr(input = list(a = human_DMR_heart_specific_25[,1:4], b = rhesus_DMR_heart_specific_25[,1:4]), method = "intersect",  params = "-wao -f 0.75 -F 0.75", check.chr = FALSE)

colnames(human_chimp_heart_specific_25) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(human_rhesus_heart_specific_25) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")


human_chimp_rhesus_heart_specific_25 <- left_join(human_chimp_heart_specific_25, human_rhesus_heart_specific_25, by= c("chr", "start")) 

# Human-chimp-rhesus conserved

human_chimp_rhesus_heart_specific_25_hs <- human_chimp_rhesus_heart_specific_25[which(human_chimp_rhesus_heart_specific_25[,9] == 0 & human_chimp_rhesus_heart_specific_25[,16] == 0), ]

#write.table(human_chimp_rhesus_heart_specific_25_hs[,1:4], put_human_specific_in_hcr, quote = FALSE, row.names = FALSE, sep = "\t")

human_chimp_rhesus_heart_specific_25_conserved <- human_chimp_rhesus_heart_specific_25[which(human_chimp_rhesus_heart_specific_25[,9] > 0 & human_chimp_rhesus_heart_specific_25[,16] > 0),]

human_chimp_rhesus_heart_specific_25_conserved <- human_chimp_rhesus_heart_specific_25_conserved[which(human_chimp_rhesus_heart_specific_25_conserved[,4] == human_chimp_rhesus_heart_specific_25_conserved[,8]),]

human_chimp_rhesus_heart_specific_25_conserved <- human_chimp_rhesus_heart_specific_25_conserved[which(human_chimp_rhesus_heart_specific_25_conserved[,11] == human_chimp_rhesus_heart_specific_25_conserved[,15]),]

#write.table(human_chimp_rhesus_heart_specific_25_conserved[,1:4], put_human_chimp_rhesus_conserved, quote = FALSE, row.names = FALSE, sep = "\t")

  row_numbers <- cbind(nrow(human_chimp_heart_specific_25_hs), nrow(human_chimp_heart_specific_25_conserved), nrow(human_chimp_rhesus_heart_specific_25_hs), nrow(human_chimp_rhesus_heart_specific_25_conserved))
  
  return(row_numbers)

}
# Heart specific

human_chimp_rhesus_hs_versus_overlap_25(human_heart_specific_25, chimp_heart_specific_25, rhesus_heart_specific_25,  "../data/overlap_reg/human_chimp_heart_specific_25_hs.bed", "../data/overlap_reg/human_chimp_heart_specific_25_conserved.bed", "../data/overlap_reg/human_chimp_rhesus_heart_specific_25_hs.bed", "../data/overlap_reg/human_chimp_rhesus_heart_specific_25_conserved.bed")
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b31441bbcf5.bed -d 0 -c 4 -o collapse
##  * Collapsing 2969 --> 2964 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b3134afda00.bed -d 0 -c 4 -o collapse
##  * Collapsing 1743 --> 1741 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b3133de6383.bed -d 0 -c 4 -o collapse
##  * Collapsing 1597 --> 1594 regions... NOTE
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b314c3496aa.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311ae8b931.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3120e0e7d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316c8ec1b1.bed -wao -f 0.25 -F 0.25
##      [,1] [,2] [,3] [,4]
## [1,] 2509  455 2411   69
human_chimp_rhesus_hs_versus_overlap_50(human_heart_specific_50, chimp_heart_specific_50, rhesus_heart_specific_50,  "../data/overlap_reg/human_chimp_heart_specific_50_hs.bed", "../data/overlap_reg/human_chimp_heart_specific_50_conserved.bed", "../data/overlap_reg/human_chimp_rhesus_heart_specific_50_hs.bed", "../data/overlap_reg/human_chimp_rhesus_heart_specific_50_conserved.bed")
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b311283fa80.bed -d 0 -c 4 -o collapse
##  * Collapsing 2133 --> 2133 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b313e6f4efd.bed -d 0 -c 4 -o collapse
##  * Collapsing 1217 --> 1217 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b315e6316e4.bed -d 0 -c 4 -o collapse
##  * Collapsing 1148 --> 1148 regions... NOTE
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3139ad598f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b312ceac51b.bed -wao -f 0.50 -F 0.50
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3177acc004.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311fbabdfd.bed -wao -f 0.50 -F 0.50
##      [,1] [,2] [,3] [,4]
## [1,] 1874  259 1821   41
human_chimp_rhesus_hs_versus_overlap_75(human_heart_specific_75, chimp_heart_specific_75, rhesus_heart_specific_75,  "../data/overlap_reg/human_chimp_heart_specific_75_hs.bed", "../data/overlap_reg/human_chimp_heart_specific_75_conserved.bed", "../data/overlap_reg/human_chimp_rhesus_heart_specific_75_hs.bed", "../data/overlap_reg/human_chimp_rhesus_heart_specific_75_conserved.bed")
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b3153829fbe.bed -d 0 -c 4 -o collapse
##  * Collapsing 993 --> 993 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b3129f986ad.bed -d 0 -c 4 -o collapse
##  * Collapsing 556 --> 556 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b31768e6c33.bed -d 0 -c 4 -o collapse
##  * Collapsing 559 --> 559 regions... NOTE
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31175ec19.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311e8f76d4.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3154159d33.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31aee6294.bed -wao -f 0.75 -F 0.75
##      [,1] [,2] [,3] [,4]
## [1,]  947   46  932    3
# Liver specific

human_chimp_rhesus_hs_versus_overlap_25(human_liver_specific_25, chimp_liver_specific_25, rhesus_liver_specific_25,  "../data/overlap_reg/human_chimp_liver_specific_25_hs.bed", "../data/overlap_reg/human_chimp_liver_specific_25_conserved.bed", "../data/overlap_reg/human_chimp_rhesus_liver_specific_25_hs.bed", "../data/overlap_reg/human_chimp_rhesus_liver_specific_25_conserved.bed")
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b3175e86d3b.bed -d 0 -c 4 -o collapse
##  * Collapsing 3293 --> 3278 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b3137629714.bed -d 0 -c 4 -o collapse
##  * Collapsing 6377 --> 6361 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b31c0bc70c.bed -d 0 -c 4 -o collapse
##  * Collapsing 11470 --> 11433 regions... NOTE
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b317265e78f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316d9ef20e.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31513318ae.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b314aa1aab4.bed -wao -f 0.25 -F 0.25
##      [,1] [,2] [,3] [,4]
## [1,] 1952 1333 1585  516
human_chimp_rhesus_hs_versus_overlap_50(human_liver_specific_50, chimp_liver_specific_50, rhesus_liver_specific_50,  "../data/overlap_reg/human_chimp_liver_specific_50_hs.bed", "../data/overlap_reg/human_chimp_liver_specific_50_conserved.bed", "../data/overlap_reg/human_chimp_rhesus_liver_specific_50_hs.bed", "../data/overlap_reg/human_chimp_rhesus_liver_specific_50_conserved.bed")
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b315f279971.bed -d 0 -c 4 -o collapse
##  * Collapsing 2497 --> 2497 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b316e054294.bed -d 0 -c 4 -o collapse
##  * Collapsing 4959 --> 4959 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b313a3a011b.bed -d 0 -c 4 -o collapse
##  * Collapsing 9549 --> 9549 regions... NOTE
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316a352245.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3169a3a993.bed -wao -f 0.50 -F 0.50
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b312990d76d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31ad71e2c.bed -wao -f 0.50 -F 0.50
##      [,1] [,2] [,3] [,4]
## [1,] 1725  772 1510  233
human_chimp_rhesus_hs_versus_overlap_75(human_liver_specific_75, chimp_liver_specific_75, rhesus_liver_specific_75,  "../data/overlap_reg/human_chimp_liver_specific_75_hs.bed", "../data/overlap_reg/human_chimp_liver_specific_75_conserved.bed", "../data/overlap_reg/human_chimp_rhesus_liver_specific_75_hs.bed", "../data/overlap_reg/human_chimp_rhesus_liver_specific_75_conserved.bed")
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b316b8e67d5.bed -d 0 -c 4 -o collapse
##  * Collapsing 1323 --> 1323 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b312ec9d21c.bed -d 0 -c 4 -o collapse
##  * Collapsing 2851 --> 2851 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b312f28ad96.bed -d 0 -c 4 -o collapse
##  * Collapsing 5949 --> 5949 regions... NOTE
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3147f81a2d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317f70c5ab.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3118eee586.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31a5789f2.bed -wao -f 0.75 -F 0.75
##      [,1] [,2] [,3] [,4]
## [1,] 1111  212 1063   25
# Lung specific

human_chimp_rhesus_hs_versus_overlap_25(human_lung_specific_25, chimp_lung_specific_25, rhesus_lung_specific_25,  "../data/overlap_reg/human_chimp_lung_specific_25_hs.bed", "../data/overlap_reg/human_chimp_lung_specific_25_conserved.bed", "../data/overlap_reg/human_chimp_rhesus_lung_specific_25_hs.bed", "../data/overlap_reg/human_chimp_rhesus_lung_specific_25_conserved.bed")
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b31351f12e.bed -d 0 -c 4 -o collapse
##  * Collapsing 479 --> 478 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b312dac44fa.bed -d 0 -c 4 -o collapse
##  * Collapsing 453 --> 452 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b3155cb8d04.bed -d 0 -c 4 -o collapse
##  * Collapsing 526 --> 524 regions... NOTE
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31af8ff06.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b312dfcb228.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31403d66e6.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b313422fcab.bed -wao -f 0.25 -F 0.25
##      [,1] [,2] [,3] [,4]
## [1,]  427   51  415    6
human_chimp_rhesus_hs_versus_overlap_50(human_lung_specific_50, chimp_lung_specific_50, rhesus_lung_specific_50,  "../data/overlap_reg/human_chimp_lung_specific_50_hs.bed", "../data/overlap_reg/human_chimp_lung_specific_50_conserved.bed", "../data/overlap_reg/human_chimp_rhesus_lung_specific_50_hs.bed", "../data/overlap_reg/human_chimp_rhesus_lung_specific_50_conserved.bed")
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b316ffc3d10.bed -d 0 -c 4 -o collapse
##  * Collapsing 266 --> 266 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b312c6610f9.bed -d 0 -c 4 -o collapse
##  * Collapsing 294 --> 294 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b3131eb759e.bed -d 0 -c 4 -o collapse
##  * Collapsing 324 --> 324 regions... NOTE
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b317d47152f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3116be9d87.bed -wao -f 0.50 -F 0.50
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31261ad4d0.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311134f1bd.bed -wao -f 0.50 -F 0.50
##      [,1] [,2] [,3] [,4]
## [1,]  243   23  240    2
human_chimp_rhesus_hs_versus_overlap_75(human_lung_specific_75, chimp_lung_specific_75, rhesus_lung_specific_75,  "../data/overlap_reg/human_chimp_lung_specific_75_hs.bed", "../data/overlap_reg/human_chimp_lung_specific_75_conserved.bed", "../data/overlap_reg/human_chimp_rhesus_lung_specific_75_hs.bed", "../data/overlap_reg/human_chimp_rhesus_lung_specific_75_conserved.bed")
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b3117ddcf95.bed -d 0 -c 4 -o collapse
##  * Collapsing 84 --> 84 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b311289d90c.bed -d 0 -c 4 -o collapse
##  * Collapsing 117 --> 117 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b31616a4e6d.bed -d 0 -c 4 -o collapse
##  * Collapsing 153 --> 153 regions... NOTE
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3139543abf.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3179b88fcc.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3154dc0a01.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31c12f388.bed -wao -f 0.75 -F 0.75
##      [,1] [,2] [,3] [,4]
## [1,]   83    1   83    0
# Kidney specific

human_chimp_rhesus_hs_versus_overlap_25(human_kidney_specific_25, chimp_kidney_specific_25, rhesus_kidney_specific_25,  "../data/overlap_reg/human_chimp_kidney_specific_25_hs.bed", "../data/overlap_reg/human_chimp_kidney_specific_25_conserved.bed", "../data/overlap_reg/human_chimp_rhesus_kidney_specific_25_hs.bed", "../data/overlap_reg/human_chimp_rhesus_kidney_specific_25_conserved.bed")
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b313e4aa6b7.bed -d 0 -c 4 -o collapse
##  * Collapsing 3967 --> 3957 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b316337fe9b.bed -d 0 -c 4 -o collapse
##  * Collapsing 2302 --> 2300 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b312a04dd0c.bed -d 0 -c 4 -o collapse
##  * Collapsing 3555 --> 3547 regions... NOTE
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b315f760a7.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317f8439c6.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b315aca2767.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31570f7f7a.bed -wao -f 0.25 -F 0.25
##      [,1] [,2] [,3] [,4]
## [1,] 3063  897 2772  299
human_chimp_rhesus_hs_versus_overlap_50(human_kidney_specific_50, chimp_kidney_specific_50, rhesus_kidney_specific_50,  "../data/overlap_reg/human_chimp_kidney_specific_50_hs.bed", "../data/overlap_reg/human_chimp_kidney_specific_50_conserved.bed", "../data/overlap_reg/human_chimp_rhesus_kidney_specific_50_hs.bed", "../data/overlap_reg/human_chimp_rhesus_kidney_specific_50_conserved.bed")
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b3133e84bc9.bed -d 0 -c 4 -o collapse
##  * Collapsing 3017 --> 3017 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b316fb4cbf7.bed -d 0 -c 4 -o collapse
##  * Collapsing 1729 --> 1729 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b311e9588bb.bed -d 0 -c 4 -o collapse
##  * Collapsing 2673 --> 2673 regions... NOTE
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3159679425.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316a566949.bed -wao -f 0.50 -F 0.50
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b312584b0fb.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31342903de.bed -wao -f 0.50 -F 0.50
##      [,1] [,2] [,3] [,4]
## [1,] 2472  545 2279  141
human_chimp_rhesus_hs_versus_overlap_75(human_kidney_specific_75, chimp_kidney_specific_75, rhesus_kidney_specific_75,  "../data/overlap_reg/human_chimp_kidney_specific_75_hs.bed", "../data/overlap_reg/human_chimp_kidney_specific_75_conserved.bed", "../data/overlap_reg/human_chimp_rhesus_kidney_specific_75_hs.bed", "../data/overlap_reg/human_chimp_rhesus_kidney_specific_75_conserved.bed")
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b317ed5d11.bed -d 0 -c 4 -o collapse
##  * Collapsing 1531 --> 1531 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b311acb6721.bed -d 0 -c 4 -o collapse
##  * Collapsing 854 --> 854 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b3117f5d55c.bed -d 0 -c 4 -o collapse
##  * Collapsing 1397 --> 1397 regions... NOTE
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31119a6cd3.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3125261706.bed -wao -f 0.75 -F 0.75
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31661d6bf9.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b312fa36b01.bed -wao -f 0.75 -F 0.75
##      [,1] [,2] [,3] [,4]
## [1,] 1388  143 1341   19

Make plot

tissue_conserved_25_overlap <- function(DMR1_human, DMR1_chimp, DMR1_rhesus){

# Human-chimp/human-rhesus

human_chimp_DMR <- bedr(input = list(a = DMR1_human, b = DMR1_chimp), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)

human_chimp_DMR <- human_chimp_DMR[which(human_chimp_DMR[,6] != -1), ]

human_rhesus_DMR <- bedr(input = list(a = DMR1_human, b = DMR1_rhesus), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)

human_rhesus_DMR <- human_rhesus_DMR[which(human_rhesus_DMR[,6] != -1), ]

chimp_rhesus_DMR <- bedr(input = list(a = DMR1_chimp, b = DMR1_rhesus), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)

chimp_rhesus_DMR <- chimp_rhesus_DMR[which(chimp_rhesus_DMR[,6] != -1), ]

colnames(human_chimp_DMR) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(human_rhesus_DMR) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

colnames(chimp_rhesus_DMR) <- c("chr", "start", "end", "direction", "chr.b", "start.b", "end.b", "direction.b", "overlap")

human_chimp_DMR <- bedr.merge.region(human_chimp_DMR)
human_rhesus_DMR <- bedr.merge.region(human_rhesus_DMR)
chimp_rhesus_DMR <- bedr.merge.region(chimp_rhesus_DMR)

# Human-chimp-rhesus

human_chimp_rhesus1_DMR <- bedr(input = list(a = human_chimp_DMR, b = human_rhesus_DMR), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)

human_chimp_rhesus1a_DMR <- human_chimp_rhesus1_DMR[which(human_chimp_rhesus1_DMR[,6] != -1), ]

human_chimp_rhesus2_DMR <- bedr(input = list(a = human_chimp_rhesus1a_DMR[,1:4], b = chimp_rhesus_DMR), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)

human_chimp_rhesus2a_DMR <- human_chimp_rhesus2_DMR[which(human_chimp_rhesus2_DMR[,6] != -1), ]

nrow(human_chimp_rhesus2a_DMR)

# human_chimp_rhesus2a_DMR gives the number of H/C/R conserved tDMRs

# Conserved in only 2 species

human_chimp_only <- bedr(input = list(a = human_chimp_DMR, b = human_chimp_rhesus2a_DMR[,1:4]), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)

human_chimp_only <- human_chimp_only[which(human_chimp_only[,6] == -1), ]

nrow(human_chimp_only)

human_rhesus_only <- bedr(input = list(a = human_rhesus_DMR, b = human_chimp_rhesus2a_DMR[,1:4]), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)

human_rhesus_only <- human_rhesus_only[which(human_rhesus_only[,6] == -1), ]

nrow(human_rhesus_only)

chimp_rhesus_only <- bedr(input = list(a = chimp_rhesus_DMR, b = human_chimp_rhesus2a_DMR[,1:4]), method = "intersect",  params = "-wao -f 0.25 -F 0.25", check.chr = FALSE)

chimp_rhesus_only <- chimp_rhesus_only[which(chimp_rhesus_only[,6] == -1), ]

nrow(chimp_rhesus_only)

# Species-specific

human_specific <- nrow(DMR1_human) - nrow(human_chimp_only) - nrow(human_rhesus_only) - nrow(human_chimp_rhesus2a_DMR)

chimp_specific <- nrow(DMR1_chimp) - nrow(human_chimp_only) - nrow(chimp_rhesus_only) - nrow(human_chimp_rhesus2a_DMR)

rhesus_specific <- nrow(DMR1_rhesus) - nrow(human_rhesus_only) - nrow(chimp_rhesus_only) - nrow(human_chimp_rhesus2a_DMR)

combine <- cbind(human_specific, chimp_specific, rhesus_specific, nrow(human_chimp_only), nrow(human_rhesus_only), nrow(chimp_rhesus_only), nrow(human_chimp_rhesus2a_DMR))

colnames(combine) <- c("human_specific", "chimp_specific", "rhesus_specific", "hc", "hr", "cr", "hcr_conserved")

return(combine)
}

tissue_conserved_25_overlap(human_heart_specific_25[,1:4], chimp_heart_specific_25[,1:4], rhesus_heart_specific_25[,1:4])
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3171620842.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31767f9167.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3111fe2bc3.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317bd78ecb.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b315e58ce95.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3177e0359b.bed -wao -f 0.25 -F 0.25
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b31358e3dab.bed -d 0 -c 4 -o collapse
##  * Collapsing 457 --> 455 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b3168de3628.bed -d 0 -c 4 -o collapse
##  * Collapsing 168 --> 167 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b3164b15639.bed -d 0 -c 4 -o collapse
##  * Collapsing 142 --> 142 regions... NOTE
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b314f14e07e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3155a15d0.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b312bbf7bb1.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31290028a4.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b318a79717.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31178da31a.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31a06bfab.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31334fcee3.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3148b15ef9.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b314515240b.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific  hc  hr cr
## [1,]           2413           1212            1354 389 101 76
##      hcr_conserved
## [1,]            66
#  human_specific chimp_specific rhesus_specific  hc  hr cr hcr_conserved
#[1,]           2413           1212            1354   389 101 76            66


human_heart_specific_25_hypo <- human_heart_specific_25[which(human_heart_specific_25[,4] == "hypo"),]

chimp_heart_specific_25_hypo <- chimp_heart_specific_25[which(chimp_heart_specific_25[,4] == "hypo"),]

rhesus_heart_specific_25_hypo <- rhesus_heart_specific_25[which(rhesus_heart_specific_25[,4] == "hypo"),]


tissue_conserved_25_overlap(human_heart_specific_25_hypo[,1:4], chimp_heart_specific_25_hypo[,1:4], rhesus_heart_specific_25_hypo[,1:4])
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b315b32edde.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311497d98c.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31d84e7bd.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3153ad7f47.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b315a8fc9af.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316fea5477.bed -wao -f 0.25 -F 0.25
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b31cef13e4.bed -d 0 -c 4 -o collapse
##  * Collapsing 414 --> 413 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b3139dee9ca.bed -d 0 -c 4 -o collapse
##  * Collapsing 155 --> 154 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b31124a93b8.bed -d 0 -c 4 -o collapse
##  * Collapsing 128 --> 128 regions... NOTE
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3142d10514.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31665f62d2.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31eb84cbd.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3114026121.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b316cfc003d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31fb99357.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3125f17cd.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b314beea1c6.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b314fe217df.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31b75430c.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific  hc hr cr hcr_conserved
## [1,]           2094           1014            1175 351 92 66            62
# human_specific chimp_specific rhesus_specific  hc hr cr hcr_conserved
#[1,]           2094           1014            1175   351 92 66            62

dev.off()
## null device 
##           1
draw.triple.venn(nrow(human_heart_specific_25_hypo), nrow(chimp_heart_specific_25_hypo), nrow(rhesus_heart_specific_25_hypo), 351+62, 66+62, 92+62, 62,  main= "Heart versus kidney (hypomethylated)",  category = c("Human", "Chimp", "Rhesus macaque"), height=3000, width=3000, cex=2 , fill = pal[1:3], lty=1, cat.cex = 2, main.cex = 2)
## (polygon[GRID.polygon.1], polygon[GRID.polygon.2], polygon[GRID.polygon.3], polygon[GRID.polygon.4], polygon[GRID.polygon.5], polygon[GRID.polygon.6], text[GRID.text.7], text[GRID.text.8], text[GRID.text.9], text[GRID.text.10], text[GRID.text.11], text[GRID.text.12], text[GRID.text.13], text[GRID.text.14], text[GRID.text.15], text[GRID.text.16])
human_heart_specific_25_hypo <- human_heart_specific_25[which(human_heart_specific_25[,4] == "hyper"),]

chimp_heart_specific_25_hypo <- chimp_heart_specific_25[which(chimp_heart_specific_25[,4] == "hyper"),]

rhesus_heart_specific_25_hypo <- rhesus_heart_specific_25[which(rhesus_heart_specific_25[,4] == "hyper"),]


tissue_conserved_25_overlap(human_heart_specific_25_hypo[,1:4], chimp_heart_specific_25_hypo[,1:4], rhesus_heart_specific_25_hypo[,1:4])
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3175ae4893.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31337edd1f.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b313b2c4e08.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316169a88d.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b313634a289.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b318b6147b.bed -wao -f 0.25 -F 0.25
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b3144047cc7.bed -d 0 -c 4 -o collapse
##  * Collapsing 43 --> 42 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b3153caf3c2.bed -d 0 -c 4 -o collapse
##  * Collapsing 13 --> 13 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b314c7b09ff.bed -d 0 -c 4 -o collapse
##  * Collapsing 14 --> 14 regions... NOTE
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b317e15d3d5.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31375bf7e5.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31760a6746.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31786fc210.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31418ee386.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b312950220b.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3170e0a135.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31ce5b469.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3124ba4222.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31685f4c4e.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
## [1,]            319            198             179 38  9 10             4
#     human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
#[1,]            319            198             179 38  9 10             4

dev.off()
## null device 
##           1
draw.triple.venn(nrow(human_heart_specific_25_hypo), nrow(chimp_heart_specific_25_hypo), nrow(rhesus_heart_specific_25_hypo), 38+4, 10+4, 9+4, 4,  main= "Heart versus kidney (hypomethylated)",  category = c("Human", "Chimp", "Rhesus macaque"), height=3000, width=3000, cex=2 , fill = pal[1:3], lty=1, cat.cex = 2, main.cex = 2)
## (polygon[GRID.polygon.17], polygon[GRID.polygon.18], polygon[GRID.polygon.19], polygon[GRID.polygon.20], polygon[GRID.polygon.21], polygon[GRID.polygon.22], text[GRID.text.23], text[GRID.text.24], text[GRID.text.25], text[GRID.text.26], text[GRID.text.27], text[GRID.text.28], text[GRID.text.29], text[GRID.text.30], text[GRID.text.31], text[GRID.text.32])
tissue_conserved_25_overlap(human_liver_specific_25[,1:4], chimp_liver_specific_25[,1:4], rhesus_liver_specific_25[,1:4])
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b311aab5489.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311a1c787e.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3138e39d23.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3145850ec2.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3154e9679f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b313e498fda.bed -wao -f 0.25 -F 0.25
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b31364541e0.bed -d 0 -c 4 -o collapse
##  * Collapsing 1349 --> 1326 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b31608340e3.bed -d 0 -c 4 -o collapse
##  * Collapsing 891 --> 872 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Bedtools requires sorted input for merging!
##    Your data is being automatically sorted
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b3112b773b1.bed -d 0 -c 4 -o collapse
##  * Collapsing 1349 --> 1315 regions... NOTE
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3140e76f5b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316e163e2d.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3167fa973c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b316b7ba7f6.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3152bba16d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3134ef8270.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3130b868ac.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b312a6881bd.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3167e73130.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b315fd76f6b.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific  hc  hr  cr
## [1,]           1571           4207            9754 849 395 843
##      hcr_conserved
## [1,]           478
#     human_specific chimp_specific rhesus_specific  hc  hr  cr hcr_conserved
#[1,]           1571           4207            9754 849 395 843           478

tissue_conserved_25_overlap(human_lung_specific_25[,1:4], chimp_lung_specific_25[,1:4], rhesus_lung_specific_25[,1:4])
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31a6170b1.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b313aae6be1.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b311882a33e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3110412ddb.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b315e4382a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b313ea971f6.bed -wao -f 0.25 -F 0.25
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b31d3812fa.bed -d 0 -c 4 -o collapse
##  * Collapsing 52 --> 51 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b3124cfa38f.bed -d 0 -c 4 -o collapse
##  * Collapsing 19 --> 18 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b3160e8f029.bed -d 0 -c 4 -o collapse
##  * Collapsing 26 --> 25 regions... NOTE
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b317d57e2c4.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3144acaf20.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b311fce0117.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b315dd384c8.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31575f3439.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317d8d5794.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b315d50d7c1.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b314bf61801.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b317dd79743.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31255b8167.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
## [1,]            415            382             488 46 13 20             5
#     human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
#[1,]            415            382             488 46 13 20             5

tissue_conserved_25_overlap(human_kidney_specific_25[,1:4], chimp_kidney_specific_25[,1:4], rhesus_kidney_specific_25[,1:4])
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b31625d20a1.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b317046d2ea.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b311bda3b69.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3129018c2d.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input seems to be in bed format but chr/start/end column names are missing
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... FAIL
##    The input for object has overlapping features!
##    This can cause unexpected results for some set operations.
##    i.e. x <- bedr.merge.region(x)
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b317fa50edc.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31189c5dfb.bed -wao -f 0.25 -F 0.25
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b315b8e13cc.bed -d 0 -c 4 -o collapse
##  * Collapsing 902 --> 894 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b3139cfd937.bed -d 0 -c 4 -o collapse
##  * Collapsing 599 --> 587 regions... NOTE
## MERGING
## VALIDATE REGIONS
##  * Checking input type... PASS
##    Input is in bed format
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Processing input (1): i
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
##    bedtools merge -i /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/i_10b31f76b00c.bed -d 0 -c 4 -o collapse
##  * Collapsing 440 --> 434 regions... NOTE
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b313e267ec6.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b311a4e8be1.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b314476674.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3159837906.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b313caeabb2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b3175833652.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3132212c87.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31626b42f3.bed -wao -f 0.25 -F 0.25
##  * Processing input (1): a
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##  * Processing input (2): b
## CONVERT TO BED
##  * Checking input type... PASS
##    Input is in bed format
## VALIDATE REGIONS
##  * Check if index is a string... PASS
##  * Check index pattern... PASS
##  * Check for missing values... PASS
##  * Check for larger start position... PASS.
##  * Check if zero based... PASS
##  * Checking sort order... PASS
##  * Checking for overlapping 'contiguous' regions... PASS
##    bedtools intersect -a /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/a_10b3143f9b072.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpP81HHD/b_10b31760df7bc.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific  hc  hr  cr
## [1,]           2773           1260            2820 607 300 148
##      hcr_conserved
## [1,]           287

Terminal commands

Left ventricle (E095), liver (E066), and lung (E096) from http://egg2.wustl.edu/roadmap/data/byFileType/peaks/consolidated/broadPeak/ucsc_compatible/ Kidney from http://egg2.wustl.edu/roadmap/data/byFileType/peaks/unconsolidated/broadPeak/ucsc_compatible/

Heart specific

bedtools intersect -a human_chimp_heart_specific_25_hs.bed -b E095-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_heart_specific_25_hs_test.bed

bedtools intersect -a human_chimp_heart_specific_25_conserved.bed -b E095-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_heart_specific_25_conserved_test.bed

Heart specific in hearts

bedtools intersect -a human_chimp_rhesus_lung_specific_25_conserved.bed -b E095-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_heart_specific_25_conserved_H3K27_HEART.bed

Heart specific in kidneys

bedtools intersect -a human_chimp_rhesus_lung_specific_25_conserved.bed -b BI.Adult_Kidney.H3K27ac.27.broadPeak -wao -f 0.25 > human_chimp_heart_specific_25_conserved_H3K27_KIDNEY.bed

Heart specific in livers

bedtools intersect -a human_chimp_rhesus_lung_specific_25_conserved.bed -b E066-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_heart_specific_25_conserved_H3K27_LIVER.bed

Heart specific in lungs

bedtools intersect -a human_chimp_rhesus_lung_specific_25_conserved.bed -b E096-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_heart_specific_25_conserved_H3K27_LUNGS.bed

Heart specific in hearts

bedtools intersect -a human_chimp_rhesus_heart_specific_25_conserved.bed -b ENCSR501FWC_rep2_1_pe_bwa_biorep_filtered_hotspots.bed -wao -f 0.25 > human_chimp_heart_specific_25_conserved_DHS_HEART.bed

Heart specific in kidneys

bedtools intersect -a human_chimp_rhesus_heart_specific_25_conserved.bed -b ENCSR422PVL_rep1_2_se_bwa_biorep_filtered_hotspots.bed -wao -f 0.25 > human_chimp_heart_specific_25_conserved_DHS_KIDNEY.bed

Heart specific in livers

bedtools intersect -a human_chimp_rhesus_heart_specific_25_conserved.bed -b ENCSR562FNN_rep1_1_pe_bwa_biorep_filtered_hotspots.bed -wao -f 0.25 > human_chimp_heart_specific_25_conserved_DHS_LIVER.bed

Heart specific in lungs

bedtools intersect -a human_chimp_rhesus_heart_specific_25_conserved.bed -b ENCSR541AVF_rep1_3_se_bwa_biorep_filtered_hotspots.bed -wao -f 0.25 > human_chimp_heart_specific_25_conserved_DHS_LUNGS.bed

# Read in data- human specific 
human_chimp_heart_specific_25_hs_test <- read.delim("../data/overlap_reg/human_chimp_heart_specific_25_conserved_DHS_HEART.bed", header = FALSE)
dim(human_chimp_heart_specific_25_hs_test)
## [1] 72 14
# Eliminate duplicates

dedup_human_chimp_heart_specific_25_hs_test <- human_chimp_heart_specific_25_hs_test[!duplicated(human_chimp_heart_specific_25_hs_test[,1:2]),]
dim(dedup_human_chimp_heart_specific_25_hs_test)
## [1] 69 14
dedup_overlap_human_chimp_heart_specific_25_hs_test <- dedup_human_chimp_heart_specific_25_hs_test[which(dedup_human_chimp_heart_specific_25_hs_test$V6 != -1),]

# Look at fraction overlapping H3K27ac
location <- dedup_human_chimp_heart_specific_25_hs_test[which(dedup_human_chimp_heart_specific_25_hs_test$V6 != -1),]

nrow(location)/nrow(human_chimp_heart_specific_25_hs_test)
## [1] 0.6388889
#0.6388889


hyper_only_conserved <- human_chimp_heart_specific_25_hs_test[which(human_chimp_heart_specific_25_hs_test[,4] == "hypo"),]

hyper_only_conserved_overlap <- hyper_only_conserved[which(hyper_only_conserved$V6 != -1),]

nrow(hyper_only_conserved_overlap)/nrow(hyper_only_conserved)
## [1] 0.7058824
nrow(hyper_only_conserved_overlap)
## [1] 48
human_chimp_heart_specific_25_hs_test <- read.delim("../data/overlap_reg/human_chimp_heart_specific_25_conserved_DHS_KIDNEY.bed", header = FALSE)
dim(human_chimp_heart_specific_25_hs_test)
## [1] 69 14
# Eliminate duplicates

dedup_human_chimp_heart_specific_25_hs_test <- human_chimp_heart_specific_25_hs_test[!duplicated(human_chimp_heart_specific_25_hs_test[,1:2]),]
dim(dedup_human_chimp_heart_specific_25_hs_test)
## [1] 69 14
dedup_overlap_human_chimp_heart_specific_25_hs_test <- dedup_human_chimp_heart_specific_25_hs_test[which(dedup_human_chimp_heart_specific_25_hs_test$V6 != -1),]

# Look at fraction overlapping H3K27ac
location <- dedup_human_chimp_heart_specific_25_hs_test[which(dedup_human_chimp_heart_specific_25_hs_test$V6 != -1),]

nrow(location)/nrow(human_chimp_heart_specific_25_hs_test)
## [1] 0
hyper_only_conserved <- human_chimp_heart_specific_25_hs_test[which(human_chimp_heart_specific_25_hs_test[,4] == "hypo"),]

hyper_only_conserved_overlap <- hyper_only_conserved[which(hyper_only_conserved$V6 != -1),]

nrow(hyper_only_conserved_overlap)/nrow(hyper_only_conserved)
## [1] 0
nrow(hyper_only_conserved_overlap)
## [1] 0
# 0.115

human_chimp_heart_specific_25_hs_test <- read.delim("../data/overlap_reg/human_chimp_heart_specific_25_conserved_DHS_LIVER.bed", header = FALSE)
dim(human_chimp_heart_specific_25_hs_test)
## [1] 69 14
# Eliminate duplicates

dedup_human_chimp_heart_specific_25_hs_test <- human_chimp_heart_specific_25_hs_test[!duplicated(human_chimp_heart_specific_25_hs_test[,1:2]),]
dim(dedup_human_chimp_heart_specific_25_hs_test)
## [1] 69 14
dedup_overlap_human_chimp_heart_specific_25_hs_test <- dedup_human_chimp_heart_specific_25_hs_test[which(dedup_human_chimp_heart_specific_25_hs_test$V6 != -1),]

# Look at fraction overlapping H3K27ac
location <- dedup_human_chimp_heart_specific_25_hs_test[which(dedup_human_chimp_heart_specific_25_hs_test$V6 != -1),]

nrow(location)/nrow(human_chimp_heart_specific_25_hs_test)
## [1] 0.115942
# 0.115 8/69

 hyper_only_conserved <- human_chimp_heart_specific_25_hs_test[which(human_chimp_heart_specific_25_hs_test[,4] == "hypo"),]

hyper_only_conserved_overlap <- hyper_only_conserved[which(hyper_only_conserved$V6 != -1),]

nrow(hyper_only_conserved_overlap)/nrow(hyper_only_conserved)
## [1] 0.1230769
nrow(hyper_only_conserved_overlap)
## [1] 8
human_chimp_heart_specific_25_hs_test <- read.delim("../data/overlap_reg/human_chimp_heart_specific_25_conserved_DHS_LUNGS.bed", header = FALSE)
dim(human_chimp_heart_specific_25_hs_test)
## [1] 69 14
# Eliminate duplicates

dedup_human_chimp_heart_specific_25_hs_test <- human_chimp_heart_specific_25_hs_test[!duplicated(human_chimp_heart_specific_25_hs_test[,1:2]),]
dim(dedup_human_chimp_heart_specific_25_hs_test)
## [1] 69 14
dedup_overlap_human_chimp_heart_specific_25_hs_test <- dedup_human_chimp_heart_specific_25_hs_test[which(dedup_human_chimp_heart_specific_25_hs_test$V6 != -1),]

# Look at fraction overlapping H3K27ac
location <- dedup_human_chimp_heart_specific_25_hs_test[which(dedup_human_chimp_heart_specific_25_hs_test$V6 != -1),]

nrow(location)/nrow(human_chimp_heart_specific_25_hs_test)
## [1] 0.1014493
#0.1014493 #7

hyper_only_conserved <- human_chimp_heart_specific_25_hs_test[which(human_chimp_heart_specific_25_hs_test[,4] == "hypo"),]

hyper_only_conserved_overlap <- hyper_only_conserved[which(hyper_only_conserved$V6 != -1),]

nrow(hyper_only_conserved_overlap)/nrow(hyper_only_conserved)
## [1] 0.1076923
nrow(hyper_only_conserved_overlap)
## [1] 7
# Read in data- human specific 
human_chimp_heart_specific_25_hs_test <- read.delim("../data/overlap_reg/human_chimp_heart_specific_25_conserved_H3K27_HEART.bed", header = FALSE)
dim(human_chimp_heart_specific_25_hs_test)
## [1]  6 14
# Eliminate duplicates

dedup_human_chimp_heart_specific_25_hs_test <- human_chimp_heart_specific_25_hs_test[!duplicated(human_chimp_heart_specific_25_hs_test[,1:2]),]
dim(dedup_human_chimp_heart_specific_25_hs_test)
## [1]  6 14
dedup_overlap_human_chimp_heart_specific_25_hs_test <- dedup_human_chimp_heart_specific_25_hs_test[which(dedup_human_chimp_heart_specific_25_hs_test$V6 != -1),]

# Look at fraction overlapping H3K27ac
location <- dedup_human_chimp_heart_specific_25_hs_test[which(dedup_human_chimp_heart_specific_25_hs_test$V6 != -1),]

nrow(location)/nrow(human_chimp_heart_specific_25_hs_test)
## [1] 0.1666667
#0.8550725 59/69

hyper_only_conserved <- human_chimp_heart_specific_25_hs_test[which(human_chimp_heart_specific_25_hs_test[,4] == "hypo"),]

hyper_only_conserved_overlap <- hyper_only_conserved[which(hyper_only_conserved$V6 != -1),]

nrow(hyper_only_conserved_overlap)/nrow(hyper_only_conserved)
## [1] NaN
nrow(hyper_only_conserved_overlap)
## [1] 0
human_chimp_heart_specific_25_hs_test <- read.delim("../data/overlap_reg/human_chimp_heart_specific_25_conserved_H3K27_KIDNEY.bed", header = FALSE)
dim(human_chimp_heart_specific_25_hs_test)
## [1]  6 14
# Eliminate duplicates

dedup_human_chimp_heart_specific_25_hs_test <- human_chimp_heart_specific_25_hs_test[!duplicated(human_chimp_heart_specific_25_hs_test[,1:2]),]
dim(dedup_human_chimp_heart_specific_25_hs_test)
## [1]  6 14
dedup_overlap_human_chimp_heart_specific_25_hs_test <- dedup_human_chimp_heart_specific_25_hs_test[which(dedup_human_chimp_heart_specific_25_hs_test$V6 != -1),]

# Look at fraction overlapping H3K27ac
location <- dedup_human_chimp_heart_specific_25_hs_test[which(dedup_human_chimp_heart_specific_25_hs_test$V6 != -1),]

nrow(location)/nrow(human_chimp_heart_specific_25_hs_test)
## [1] 0.5
hyper_only_conserved <- human_chimp_heart_specific_25_hs_test[which(human_chimp_heart_specific_25_hs_test[,4] == "hypo"),]

hyper_only_conserved_overlap <- hyper_only_conserved[which(hyper_only_conserved$V6 != -1),]

nrow(hyper_only_conserved_overlap)/nrow(hyper_only_conserved)
## [1] NaN
nrow(hyper_only_conserved_overlap)
## [1] 0
# 0.71  49

human_chimp_heart_specific_25_hs_test <- read.delim("../data/overlap_reg/human_chimp_heart_specific_25_conserved_H3K27_LIVER.bed", header = FALSE)
dim(human_chimp_heart_specific_25_hs_test)
## [1]  6 14
# Eliminate duplicates

dedup_human_chimp_heart_specific_25_hs_test <- human_chimp_heart_specific_25_hs_test[!duplicated(human_chimp_heart_specific_25_hs_test[,1:2]),]
dim(dedup_human_chimp_heart_specific_25_hs_test)
## [1]  6 14
dedup_overlap_human_chimp_heart_specific_25_hs_test <- dedup_human_chimp_heart_specific_25_hs_test[which(dedup_human_chimp_heart_specific_25_hs_test$V6 != -1),]

# Look at fraction overlapping H3K27ac
location <- dedup_human_chimp_heart_specific_25_hs_test[which(dedup_human_chimp_heart_specific_25_hs_test$V6 != -1),]

nrow(location)/nrow(human_chimp_heart_specific_25_hs_test)
## [1] 0.3333333
# 0.5652174 39

hyper_only_conserved <- human_chimp_heart_specific_25_hs_test[which(human_chimp_heart_specific_25_hs_test[,4] == "hypo"),]

hyper_only_conserved_overlap <- hyper_only_conserved[which(hyper_only_conserved$V6 != -1),]

nrow(hyper_only_conserved_overlap)/nrow(hyper_only_conserved)
## [1] NaN
nrow(hyper_only_conserved_overlap)
## [1] 0
human_chimp_heart_specific_25_hs_test <- read.delim("../data/overlap_reg/human_chimp_heart_specific_25_conserved_H3K27_LUNGS.bed", header = FALSE)
dim(human_chimp_heart_specific_25_hs_test)
## [1]  6 14
# Eliminate duplicates

dedup_human_chimp_heart_specific_25_hs_test <- human_chimp_heart_specific_25_hs_test[!duplicated(human_chimp_heart_specific_25_hs_test[,1:2]),]
dim(dedup_human_chimp_heart_specific_25_hs_test)
## [1]  6 14
dedup_overlap_human_chimp_heart_specific_25_hs_test <- dedup_human_chimp_heart_specific_25_hs_test[which(dedup_human_chimp_heart_specific_25_hs_test$V6 != -1),]

# Look at fraction overlapping H3K27ac
location <- dedup_human_chimp_heart_specific_25_hs_test[which(dedup_human_chimp_heart_specific_25_hs_test$V6 != -1),]

nrow(location)/nrow(human_chimp_heart_specific_25_hs_test)
## [1] 0.5
#0.7246377 #50

hyper_only_conserved <- human_chimp_heart_specific_25_hs_test[which(human_chimp_heart_specific_25_hs_test[,4] == "hypo"),]

hyper_only_conserved_overlap <- hyper_only_conserved[which(hyper_only_conserved$V6 != -1),]

nrow(hyper_only_conserved_overlap)/nrow(hyper_only_conserved)
## [1] NaN
nrow(hyper_only_conserved_overlap)
## [1] 0
prop.test(x = c(8,48), n = c(65,65))
## 
##  2-sample test for equality of proportions with continuity
##  correction
## 
## data:  c(8, 48) out of c(65, 65)
## X-squared = 47.715, df = 1, p-value = 4.93e-12
## alternative hypothesis: two.sided
## 95 percent confidence interval:
##  -0.7641587 -0.4666105
## sample estimates:
##    prop 1    prop 2 
## 0.1230769 0.7384615

25% overlap

bedtools intersect -a human_chimp_heart_specific_25_hs.bed -b E095-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_heart_specific_25_hs_test.bed

bedtools intersect -a human_chimp_heart_specific_25_conserved.bed -b E095-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_heart_specific_25_conserved_test.bed

bedtools intersect -a human_chimp_heart_specific_25_hs.bed -b E096-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_heart_specific_25_hs_liver_test.bed

bedtools intersect -a human_chimp_heart_specific_25_conserved.bed -b E096-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_heart_specific_25_conserved_liver_test.bed

bedtools intersect -a human_chimp_rhesus_heart_specific_25_hs.bed -b E095-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_rhesus_heart_specific_25_hs_test.bed

bedtools intersect -a human_chimp_rhesus_heart_specific_25_conserved.bed -b E095-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_rhesus_heart_specific_25_conserved_test.bed

50% overlap

bedtools intersect -a human_chimp_heart_specific_50_hs.bed -b E095-H3K27ac.broadPeak -wao -f 0.50 > human_chimp_heart_specific_50_hs_test.bed bedtools intersect -a human_chimp_heart_specific_50_conserved.bed -b E095-H3K27ac.broadPeak -wao -f 0.50 > human_chimp_heart_specific_50_conserved_test.bed bedtools intersect -a human_chimp_rhesus_heart_specific_50_hs.bed -b E095-H3K27ac.broadPeak -wao -f 0.50 > human_chimp_rhesus_heart_specific_50_hs_test.bed bedtools intersect -a human_chimp_rhesus_heart_specific_50_conserved.bed -b E095-H3K27ac.broadPeak -wao -f 0.50 > human_chimp_rhesus_heart_specific_50_conserved_test.bed

75% overlap

bedtools intersect -a human_chimp_heart_specific_75_hs.bed -b E095-H3K27ac.broadPeak -wao -f 0.75 > human_chimp_heart_specific_75_hs_test.bed bedtools intersect -a human_chimp_heart_specific_75_conserved.bed -b E095-H3K27ac.broadPeak -wao -f 0.75 > human_chimp_heart_specific_75_conserved_test.bed bedtools intersect -a human_chimp_rhesus_heart_specific_75_hs.bed -b E095-H3K27ac.broadPeak -wao -f 0.75 > human_chimp_rhesus_heart_specific_75_hs_test.bed bedtools intersect -a human_chimp_rhesus_heart_specific_75_conserved.bed -b E095-H3K27ac.broadPeak -wao -f 0.75 > human_chimp_rhesus_heart_specific_75_conserved_test.bed

Liver specific

25% overlap

bedtools intersect -a human_chimp_liver_specific_25_hs.bed -b E066-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_liver_specific_25_hs_test.bed bedtools intersect -a human_chimp_liver_specific_25_conserved.bed -b E066-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_liver_specific_25_conserved_test.bed

bedtools intersect -a human_chimp_liver_specific_25_hs.bed -b E096-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_liver_specific_25_hs_lung_test.bed bedtools intersect -a human_chimp_liver_specific_25_conserved.bed -b E096-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_liver_specific_25_conserved_lung_test.bed

bedtools intersect -a human_chimp_rhesus_liver_specific_25_hs.bed -b E066-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_rhesus_liver_specific_25_hs_test.bed bedtools intersect -a human_chimp_rhesus_liver_specific_25_conserved.bed -b E066-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_rhesus_liver_specific_25_conserved_test.bed

50% overlap

bedtools intersect -a human_chimp_liver_specific_50_hs.bed -b E066-H3K27ac.broadPeak -wao -f 0.50 > human_chimp_liver_specific_50_hs_test.bed bedtools intersect -a human_chimp_liver_specific_50_conserved.bed -b E066-H3K27ac.broadPeak -wao -f 0.50 > human_chimp_liver_specific_50_conserved_test.bed bedtools intersect -a human_chimp_rhesus_liver_specific_50_hs.bed -b E066-H3K27ac.broadPeak -wao -f 0.50 > human_chimp_rhesus_liver_specific_50_hs_test.bed bedtools intersect -a human_chimp_rhesus_liver_specific_50_conserved.bed -b E066-H3K27ac.broadPeak -wao -f 0.50 > human_chimp_rhesus_liver_specific_50_conserved_test.bed

75% overlap

bedtools intersect -a human_chimp_liver_specific_75_hs.bed -b E066-H3K27ac.broadPeak -wao -f 0.75 > human_chimp_liver_specific_75_hs_test.bed bedtools intersect -a human_chimp_liver_specific_75_conserved.bed -b E066-H3K27ac.broadPeak -wao -f 0.75 > human_chimp_liver_specific_75_conserved_test.bed bedtools intersect -a human_chimp_rhesus_liver_specific_75_hs.bed -b E066-H3K27ac.broadPeak -wao -f 0.75 > human_chimp_rhesus_liver_specific_75_hs_test.bed bedtools intersect -a human_chimp_rhesus_liver_specific_75_conserved.bed -b E066-H3K27ac.broadPeak -wao -f 0.75 > human_chimp_rhesus_liver_specific_75_conserved_test.bed

Lung specific

25% overlap

bedtools intersect -a human_chimp_lung_specific_25_hs.bed -b E096-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_lung_specific_25_hs_test.bed bedtools intersect -a human_chimp_lung_specific_25_conserved.bed -b E096-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_lung_specific_25_conserved_test.bed

bedtools intersect -a human_chimp_lung_specific_25_hs.bed -b E095-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_lung_specific_25_hs_heart_test.bed bedtools intersect -a human_chimp_lung_specific_25_conserved.bed -b E095-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_lung_specific_25_conserved_heart_test.bed

bedtools intersect -a human_chimp_rhesus_lung_specific_25_hs.bed -b E096-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_rhesus_lung_specific_25_hs_test.bed bedtools intersect -a human_chimp_rhesus_lung_specific_25_conserved.bed -b E096-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_rhesus_lung_specific_25_conserved_test.bed

50% overlap

bedtools intersect -a human_chimp_lung_specific_50_hs.bed -b E096-H3K27ac.broadPeak -wao -f 0.50 > human_chimp_lung_specific_50_hs_test.bed bedtools intersect -a human_chimp_lung_specific_50_conserved.bed -b E096-H3K27ac.broadPeak -wao -f 0.50 > human_chimp_lung_specific_50_conserved_test.bed bedtools intersect -a human_chimp_rhesus_lung_specific_50_hs.bed -b E096-H3K27ac.broadPeak -wao -f 0.50 > human_chimp_rhesus_lung_specific_50_hs_test.bed bedtools intersect -a human_chimp_rhesus_lung_specific_50_conserved.bed -b E096-H3K27ac.broadPeak -wao -f 0.50 > human_chimp_rhesus_lung_specific_50_conserved_test.bed

75% overlap

bedtools intersect -a human_chimp_lung_specific_75_hs.bed -b E096-H3K27ac.broadPeak -wao -f 0.75 > human_chimp_lung_specific_75_hs_test.bed bedtools intersect -a human_chimp_lung_specific_75_conserved.bed -b E096-H3K27ac.broadPeak -wao -f 0.75 > human_chimp_lung_specific_75_conserved_test.bed bedtools intersect -a human_chimp_rhesus_lung_specific_75_hs.bed -b E096-H3K27ac.broadPeak -wao -f 0.75 > human_chimp_rhesus_lung_specific_75_hs_test.bed bedtools intersect -a human_chimp_rhesus_lung_specific_75_conserved.bed -b E096-H3K27ac.broadPeak -wao -f 0.75 > human_chimp_rhesus_lung_specific_75_conserved_test.bed

Kidney specific (BI.Adult_Kidney.H3K27ac.27.broadPeak)

25% overlap

bedtools intersect -a human_chimp_kidney_specific_25_hs.bed -b BI.Adult_Kidney.H3K27ac.27.broadPeak -wao -f 0.25 > human_chimp_kidney_specific_25_hs_test.bed bedtools intersect -a human_chimp_kidney_specific_25_conserved.bed -b BI.Adult_Kidney.H3K27ac.27.broadPeak -wao -f 0.25 > human_chimp_kidney_specific_25_conserved_test.bed

bedtools intersect -a human_chimp_kidney_specific_25_hs.bed -b E096-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_kidney_specific_25_hs_lung_test.bed bedtools intersect -a human_chimp_kidney_specific_25_conserved.bed -b E096-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_kidney_specific_25_conserved_lung_test.bed

bedtools intersect -a human_chimp_rhesus_kidney_specific_25_hs.bed -b BI.Adult_Kidney.H3K27ac.27.broadPeak -wao -f 0.25 > human_chimp_rhesus_kidney_specific_25_hs_test.bed bedtools intersect -a human_chimp_rhesus_kidney_specific_25_conserved.bed -b BI.Adult_Kidney.H3K27ac.27.broadPeak -wao -f 0.25 > human_chimp_rhesus_kidney_specific_25_conserved_test.bed

50% overlap

bedtools intersect -a human_chimp_kidney_specific_50_hs.bed -b BI.Adult_Kidney.H3K27ac.27.broadPeak -wao -f 0.50 > human_chimp_kidney_specific_50_hs_test.bed bedtools intersect -a human_chimp_kidney_specific_50_conserved.bed -b BI.Adult_Kidney.H3K27ac.27.broadPeak -wao -f 0.50 > human_chimp_kidney_specific_50_conserved_test.bed bedtools intersect -a human_chimp_rhesus_kidney_specific_50_hs.bed -b BI.Adult_Kidney.H3K27ac.27.broadPeak -wao -f 0.50 > human_chimp_rhesus_kidney_specific_50_hs_test.bed bedtools intersect -a human_chimp_rhesus_kidney_specific_50_conserved.bed -b BI.Adult_Kidney.H3K27ac.27.broadPeak -wao -f 0.50 > human_chimp_rhesus_kidney_specific_50_conserved_test.bed

75% overlap

bedtools intersect -a human_chimp_kidney_specific_75_hs.bed -b BI.Adult_Kidney.H3K27ac.27.broadPeak -wao -f 0.75 > human_chimp_kidney_specific_75_hs_test.bed bedtools intersect -a human_chimp_kidney_specific_75_conserved.bed -b BI.Adult_Kidney.H3K27ac.27.broadPeak -wao -f 0.75 > human_chimp_kidney_specific_75_conserved_test.bed bedtools intersect -a human_chimp_rhesus_kidney_specific_75_hs.bed -b BI.Adult_Kidney.H3K27ac.27.broadPeak -wao -f 0.75 > human_chimp_rhesus_kidney_specific_75_hs_test.bed bedtools intersect -a human_chimp_rhesus_kidney_specific_75_conserved.bed -b BI.Adult_Kidney.H3K27ac.27.broadPeak -wao -f 0.75 > human_chimp_rhesus_kidney_specific_75_conserved_test.bed

Kidney specific (BI.Adult_Kidney.H3K27ac.153.broadPeak)

25% overlap

bedtools intersect -a human_chimp_kidney_specific_25_hs.bed -b BI.Adult_Kidney.H3K27ac.153.broadPeak -wao -f 0.25 > human_chimp_kidney_specific_25_hs_test2.bed bedtools intersect -a human_chimp_kidney_specific_25_conserved.bed -b BI.Adult_Kidney.H3K27ac.153.broadPeak -wao -f 0.25 > human_chimp_kidney_specific_25_conserved_test2.bed bedtools intersect -a human_chimp_kidney_specific_25_hs.bed -b E096-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_kidney_specific_25_hs_lung_test2.bed bedtools intersect -a human_chimp_kidney_specific_25_conserved.bed -b E096-H3K27ac.broadPeak -wao -f 0.25 > human_chimp_kidney_specific_25_conserved_lung_test2.bed bedtools intersect -a human_chimp_rhesus_kidney_specific_25_hs.bed -b BI.Adult_Kidney.H3K27ac.153.broadPeak -wao -f 0.25 > human_chimp_rhesus_kidney_specific_25_hs_test2.bed bedtools intersect -a human_chimp_rhesus_kidney_specific_25_conserved.bed -b BI.Adult_Kidney.H3K27ac.153.broadPeak -wao -f 0.25 > human_chimp_rhesus_kidney_specific_25_conserved_test2.bed

50% overlap

bedtools intersect -a human_chimp_kidney_specific_50_hs.bed -b BI.Adult_Kidney.H3K27ac.153.broadPeak -wao -f 0.50 > human_chimp_kidney_specific_50_hs_test2.bed bedtools intersect -a human_chimp_kidney_specific_50_conserved.bed -b BI.Adult_Kidney.H3K27ac.153.broadPeak -wao -f 0.50 > human_chimp_kidney_specific_50_conserved_test2.bed bedtools intersect -a human_chimp_rhesus_kidney_specific_50_hs.bed -b BI.Adult_Kidney.H3K27ac.153.broadPeak -wao -f 0.50 > human_chimp_rhesus_kidney_specific_50_hs_test2.bed bedtools intersect -a human_chimp_rhesus_kidney_specific_50_conserved.bed -b BI.Adult_Kidney.H3K27ac.153.broadPeak -wao -f 0.50 > human_chimp_rhesus_kidney_specific_50_conserved_test2.bed

75% overlap

bedtools intersect -a human_chimp_kidney_specific_75_hs.bed -b BI.Adult_Kidney.H3K27ac.153.broadPeak -wao -f 0.75 > human_chimp_kidney_specific_75_hs_test2.bed bedtools intersect -a human_chimp_kidney_specific_75_conserved.bed -b BI.Adult_Kidney.H3K27ac.153.broadPeak -wao -f 0.75 > human_chimp_kidney_specific_75_conserved_test2.bed bedtools intersect -a human_chimp_rhesus_kidney_specific_75_hs.bed -b BI.Adult_Kidney.H3K27ac.153.broadPeak -wao -f 0.75 > human_chimp_rhesus_kidney_specific_75_hs_test2.bed bedtools intersect -a human_chimp_rhesus_kidney_specific_75_conserved.bed -b BI.Adult_Kidney.H3K27ac.153.broadPeak -wao -f 0.75 > human_chimp_rhesus_kidney_specific_75_conserved_test2.bed

Conserved kidney

25% overlap

bedtools intersect -a human_chimp_kidney_specific_25_hs.bed -b combined_kidney.bed -wao -f 0.25 > human_chimp_kidney_specific_25_hs_test3.bed bedtools intersect -a human_chimp_kidney_specific_25_conserved.bed -b combined_kidney.bed -wao -f 0.25 > human_chimp_kidney_specific_25_conserved_test3.bed bedtools intersect -a human_chimp_kidney_specific_50_hs.bed -b combined_kidney.bed -wao -f 0.50 > human_chimp_kidney_specific_50_hs_test3.bed bedtools intersect -a human_chimp_kidney_specific_50_conserved.bed -b combined_kidney.bed -wao -f 0.50 > human_chimp_kidney_specific_50_conserved_test3.bed bedtools intersect -a human_chimp_kidney_specific_75_hs.bed -b combined_kidney.bed -wao -f 0.75 > human_chimp_kidney_specific_75_hs_test3.bed bedtools intersect -a human_chimp_kidney_specific_75_conserved.bed -b combined_kidney.bed -wao -f 0.75 > human_chimp_kidney_specific_75_conserved_test3.bed

25% overlap

bedtools intersect -a human_chimp_heart_specific_25_hs.bed -b ENCSR501FWC_rep2_1_pe_bwa_biorep_filtered_hotspots.bed -wao -f 0.25 > human_chimp_heart_specific_25_hs_test.bed bedtools intersect -a human_chimp_heart_specific_25_conserved.bed -b ENCSR501FWC_rep2_1_pe_bwa_biorep_filtered_hotspots.bed -wao -f 0.25 > human_chimp_heart_specific_25_conserved_test.bed bedtools intersect -a human_chimp_heart_specific_50_hs.bed -b ENCSR501FWC_rep2_1_pe_bwa_biorep_filtered_hotspots.bed -wao -f 0.50 > human_chimp_heart_specific_50_hs_test.bed bedtools intersect -a human_chimp_heart_specific_50_conserved.bed -b ENCSR501FWC_rep2_1_pe_bwa_biorep_filtered_hotspots.bed -wao -f 0.50 > human_chimp_heart_specific_50_conserved_test.bed bedtools intersect -a human_chimp_heart_specific_75_hs.bed -b ENCSR501FWC_rep2_1_pe_bwa_biorep_filtered_hotspots.bed -wao -f 0.75 > human_chimp_heart_specific_75_hs_test.bed bedtools intersect -a human_chimp_heart_specific_75_conserved.bed -b ENCSR501FWC_rep2_1_pe_bwa_biorep_filtered_hotspots.bed -wao -f 0.75 > human_chimp_heart_specific_75_conserved_test.bed

Liver

bedtools intersect -a human_chimp_liver_specific_25_hs.bed -b ENCSR562FNN_rep1_1_pe_bwa_biorep_filtered_hotspots.bed -wao -f 0.25 > human_chimp_liver_specific_25_hs_test.bed bedtools intersect -a human_chimp_liver_specific_25_conserved.bed -b ENCSR562FNN_rep1_1_pe_bwa_biorep_filtered_hotspots.bed -wao -f 0.25 > human_chimp_liver_specific_25_conserved_test.bed bedtools intersect -a human_chimp_liver_specific_50_hs.bed -b ENCSR562FNN_rep1_1_pe_bwa_biorep_filtered_hotspots.bed -wao -f 0.50 > human_chimp_liver_specific_50_hs_test.bed bedtools intersect -a human_chimp_liver_specific_50_conserved.bed -b ENCSR562FNN_rep1_1_pe_bwa_biorep_filtered_hotspots.bed -wao -f 0.50 > human_chimp_liver_specific_50_conserved_test.bed bedtools intersect -a human_chimp_liver_specific_75_hs.bed -b ENCSR562FNN_rep1_1_pe_bwa_biorep_filtered_hotspots.bed -wao -f 0.75 > human_chimp_liver_specific_75_hs_test.bed bedtools intersect -a human_chimp_liver_specific_75_conserved.bed -b ENCSR562FNN_rep1_1_pe_bwa_biorep_filtered_hotspots.bed -wao -f 0.75 > human_chimp_liver_specific_75_conserved_test.bed

ENCSR541AVF_rep1_3_se_bwa_biorep_filtered_hotspots.bed

Lung

bedtools intersect -a human_chimp_lung_specific_25_hs.bed -b ENCSR541AVF_rep1_3_se_bwa_biorep_filtered_hotspots.bed -wao -f 0.25 > human_chimp_lung_specific_25_hs_test.bed bedtools intersect -a human_chimp_lung_specific_25_conserved.bed -b ENCSR541AVF_rep1_3_se_bwa_biorep_filtered_hotspots.bed -wao -f 0.25 > human_chimp_lung_specific_25_conserved_test.bed bedtools intersect -a human_chimp_lung_specific_50_hs.bed -b ENCSR541AVF_rep1_3_se_bwa_biorep_filtered_hotspots.bed -wao -f 0.50 > human_chimp_lung_specific_50_hs_test.bed bedtools intersect -a human_chimp_lung_specific_50_conserved.bed -b ENCSR541AVF_rep1_3_se_bwa_biorep_filtered_hotspots.bed -wao -f 0.50 > human_chimp_lung_specific_50_conserved_test.bed bedtools intersect -a human_chimp_lung_specific_75_hs.bed -b ENCSR541AVF_rep1_3_se_bwa_biorep_filtered_hotspots.bed -wao -f 0.75 > human_chimp_lung_specific_75_hs_test.bed bedtools intersect -a human_chimp_lung_specific_75_conserved.bed -b ENCSR541AVF_rep1_3_se_bwa_biorep_filtered_hotspots.bed -wao -f 0.75 > human_chimp_lung_specific_75_conserved_test.bed

ENCSR422PVL_rep1_2_se_bwa_biorep_filtered_hotspots.bed

bedtools intersect -a human_chimp_kidney_specific_25_hs.bed -b ENCSR422PVL_rep1_2_se_bwa_biorep_filtered_hotspots.bed -wao -f 0.25 > human_chimp_kidney_specific_25_hs_test2.bed bedtools intersect -a human_chimp_kidney_specific_25_conserved.bed -b ENCSR422PVL_rep1_2_se_bwa_biorep_filtered_hotspots.bed -wao -f 0.25 > human_chimp_kidney_specific_25_conserved_test2.bed bedtools intersect -a human_chimp_kidney_specific_50_hs.bed -b ENCSR422PVL_rep1_2_se_bwa_biorep_filtered_hotspots.bed -wao -f 0.50 > human_chimp_kidney_specific_50_hs_test2.bed bedtools intersect -a human_chimp_kidney_specific_50_conserved.bed -b ENCSR422PVL_rep1_2_se_bwa_biorep_filtered_hotspots.bed -wao -f 0.50 > human_chimp_kidney_specific_50_conserved_test2.bed bedtools intersect -a human_chimp_kidney_specific_75_hs.bed -b ENCSR422PVL_rep1_2_se_bwa_biorep_filtered_hotspots.bed -wao -f 0.75 > human_chimp_kidney_specific_75_hs_test2.bed bedtools intersect -a human_chimp_kidney_specific_75_conserved.bed -b ENCSR422PVL_rep1_2_se_bwa_biorep_filtered_hotspots.bed -wao -f 0.75 > human_chimp_kidney_specific_75_conserved_test2.bed

Pull the human-chimp data back in from bedtools

Perform initial analysis

# Read in data- human specific 
human_chimp_heart_specific_25_hs_test <- read.delim("../data/overlap_reg/human_chimp_heart_specific_25_hs_test.bed", header = FALSE)
dim(human_chimp_heart_specific_25_hs_test)
## [1] 2591   14
# Eliminate duplicates

dedup_human_chimp_heart_specific_25_hs_test <- human_chimp_heart_specific_25_hs_test[!duplicated(human_chimp_heart_specific_25_hs_test[,1:2]),]
dim(dedup_human_chimp_heart_specific_25_hs_test)
## [1] 2509   14
dedup_overlap_human_chimp_heart_specific_25_hs_test <- dedup_human_chimp_heart_specific_25_hs_test[which(dedup_human_chimp_heart_specific_25_hs_test$V6 != -1),]

# Look at fraction overlapping H3K27ac
location <- dedup_human_chimp_heart_specific_25_hs_test[which(dedup_human_chimp_heart_specific_25_hs_test$V6 != -1),]

nrow(location)/nrow(human_chimp_heart_specific_25_hs_test)
## [1] 0.5773832
# Read in data- human and chimp conserved

human_chimp_heart_specific_25_conserved_test <- read.delim("../data/overlap_reg/human_chimp_heart_specific_25_conserved_test.bed", header = FALSE)

dedup_overlap_human_chimp_heart_specific_25_conserved_test <- human_chimp_heart_specific_25_conserved_test[which(human_chimp_heart_specific_25_conserved_test$V6 != -1),]

nrow(dedup_overlap_human_chimp_heart_specific_25_conserved_test)/nrow(human_chimp_heart_specific_25_conserved_test)
## [1] 0.6534447
# Run a difference in proportions test

res <- prop.test(x = c(1918, 373), n = c(2473, 441))
res
## 
##  2-sample test for equality of proportions with continuity
##  correction
## 
## data:  c(1918, 373) out of c(2473, 441)
## X-squared = 10.568, df = 1, p-value = 0.001151
## alternative hypothesis: two.sided
## 95 percent confidence interval:
##  -0.10906708 -0.03139045
## sample estimates:
##    prop 1    prop 2 
## 0.7755762 0.8458050

Separate into hyper- and hypo- methylated regions

# What if we look at just the hypermethylated regions

# Human Specific
hyper_only_hs <- human_chimp_heart_specific_25_hs_test[which(human_chimp_heart_specific_25_hs_test[,4] == "hyper"),]

hyper_only_hs_overlap <- hyper_only_hs[which(hyper_only_hs$V6 != -1),]

nrow(hyper_only_hs_overlap)/nrow(hyper_only_hs)
## [1] 0.2222222
# Conserved
hyper_only_conserved <- human_chimp_heart_specific_25_conserved_test[which(human_chimp_heart_specific_25_conserved_test[,4] == "hyper"),]

hyper_only_conserved_overlap <- hyper_only_conserved[which(hyper_only_conserved$V6 != -1),]

nrow(hyper_only_conserved_overlap)/nrow(hyper_only_conserved)
## [1] 0.1627907
# What if we look at just the hypomethylated regions (hypomethylated regions, aka regions of less methylation, are more likely to be associated with an activating mark like H3K27ac)

# Human Specific
hyper_only_hs <- human_chimp_heart_specific_25_hs_test[which(human_chimp_heart_specific_25_hs_test[,4] == "hypo"),]

hyper_only_hs_overlap <- hyper_only_hs[which(hyper_only_hs$V6 != -1),]

nrow(hyper_only_hs_overlap)/nrow(hyper_only_hs)
## [1] 0.6660762
# Conserved
hyper_only_conserved <- human_chimp_heart_specific_25_conserved_test[which(human_chimp_heart_specific_25_conserved_test[,4] == "hypo"),]

hyper_only_conserved_overlap <- hyper_only_conserved[which(hyper_only_conserved$V6 != -1),]

nrow(hyper_only_conserved_overlap)/nrow(hyper_only_conserved)
## [1] 0.7018349
# Run the t test

res <- prop.test(x = c(nrow(hyper_only_hs_overlap), nrow(hyper_only_conserved_overlap)), n = c(nrow(hyper_only_hs), nrow(hyper_only_conserved)))
res
## 
##  2-sample test for equality of proportions with continuity
##  correction
## 
## data:  c(nrow(hyper_only_hs_overlap), nrow(hyper_only_conserved_overlap)) out of c(nrow(hyper_only_hs), nrow(hyper_only_conserved))
## X-squared = 1.9604, df = 1, p-value = 0.1615
## alternative hypothesis: two.sided
## 95 percent confidence interval:
##  -0.08426650  0.01274913
## sample estimates:
##    prop 1    prop 2 
## 0.6660762 0.7018349

Make a function to pull overlap

# Make a function that exports fraction overlap and p values of the differences for all data (row 1), hypomethylated data (row 2; what we are arguably most interested in), and hypermethylated data (row 3)

diff_prop_hs_versus_conserved <- function(filename_human_specific, filename_conserved){

######################################### FIRST, RUN THE FUNCTION ON ALL DATA #####################
  # Start with the human specific data
  
  filename_human_specific_overlap <- filename_human_specific[which(filename_human_specific$V6 != -1),]

  # Look at fraction overlapping H3K27ac
  fraction_hs_overlap <- nrow(filename_human_specific_overlap)/nrow(filename_human_specific)


  
  
  # Then, the conserved data
  filename_conserved_overlap <- filename_conserved[which(filename_conserved$V6 != -1),]
  fraction_conserved_overlap <- nrow(filename_conserved_overlap)/nrow(filename_conserved)

  # Run a difference in proportions test

  res <- prop.test(x = c(nrow(filename_human_specific_overlap), nrow(filename_conserved_overlap)), n = c(nrow(filename_human_specific), nrow(filename_conserved)))

  import_values_1 <- cbind(fraction_hs_overlap, fraction_conserved_overlap, res$p.value)
  
######################################### NEXT, RUN THE FUNCTION ON HYPOMETHYLATED DATA #####################
  
  # Human Specific
  hypo_only_hs <- filename_human_specific[which(filename_human_specific[,4] == "hypo"),]

  hypo_only_hs_overlap <- hypo_only_hs[which(hypo_only_hs$V6 != -1),]

  fraction_hypo_hs_overlap <- nrow(hypo_only_hs_overlap)/nrow(hypo_only_hs)

  # Conserved
  hypo_only_conserved <- filename_conserved[which(filename_conserved[,4] == "hypo"),]

  hypo_only_conserved_overlap <- hypo_only_conserved[which(hypo_only_conserved$V6 != -1),]

  fraction_hypo_conserved_overlap <- nrow(hypo_only_conserved_overlap)/nrow(hypo_only_conserved)

  # Run a difference in proportions test

  res <- prop.test(x = c(nrow(hypo_only_hs_overlap), nrow(hypo_only_conserved_overlap)), n = c(nrow(hypo_only_hs), nrow(hypo_only_conserved)))
  
  import_values_2 <- cbind(fraction_hypo_hs_overlap, fraction_hypo_conserved_overlap, res$p.value)
  
  
  ######################################### NEXT, RUN THE FUNCTION ON HYPERMETHYLATED DATA #####################
  
  # Human Specific
  hypo_only_hs <- filename_human_specific[which(filename_human_specific[,4] == "hyper"),]

  hypo_only_hs_overlap <- hypo_only_hs[which(hypo_only_hs$V6 != -1),]

  fraction_hypo_hs_overlap <- nrow(hypo_only_hs_overlap)/nrow(hypo_only_hs)

  # Conserved
  hypo_only_conserved <- filename_conserved[which(filename_conserved[,4] == "hyper"),]

  hypo_only_conserved_overlap <- hypo_only_conserved[which(hypo_only_conserved$V6 != -1),]

  fraction_hypo_conserved_overlap <- nrow(hypo_only_conserved_overlap)/nrow(hypo_only_conserved)

  # Run a difference in proportions test

  res <- prop.test(x = c(nrow(hypo_only_hs_overlap), nrow(hypo_only_conserved_overlap)), n = c(nrow(hypo_only_hs), nrow(hypo_only_conserved)))
  
  import_values_3 <- cbind(fraction_hypo_hs_overlap, fraction_hypo_conserved_overlap, res$p.value)
  
  import_values <- rbind(import_values_1, import_values_2, import_values_3)
  
  
  
  
  return(import_values)

}


#diff_prop_hs_versus_conserved(human_chimp_heart_specific_25_hs_test, human_chimp_heart_specific_25_conserved_test)

# Run with liver to compare

#human_chimp_heart_specific_25_hs_test_liver <- read.delim("../data/overlap_reg/human_chimp_heart_specific_25_hs_liver_test.bed", header = FALSE)
#human_chimp_heart_specific_25_conserved_test_liver <- read.delim("../data/overlap_reg/human_chimp_heart_specific_25_conserved_liver_test.bed", header = FALSE)

#diff_prop_hs_versus_conserved(human_chimp_heart_specific_25_hs_test_liver, human_chimp_heart_specific_25_conserved_test_liver)

Heart specific

# Heart specific 25%- human and chimp

human_chimp_heart_specific_25_hs_test <- read.delim("../data/overlap_reg/human_chimp_heart_specific_25_hs_test.bed", header = FALSE)

human_chimp_heart_specific_25_conserved_test <- read.delim("../data/overlap_reg/human_chimp_heart_specific_25_conserved_test.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_heart_specific_25_hs_test, human_chimp_heart_specific_25_conserved_test)
##      fraction_hs_overlap fraction_conserved_overlap           
## [1,]           0.6090313                  0.6534447 0.07427587
## [2,]           0.6660762                  0.7018349 0.16146641
## [3,]           0.2222222                  0.1627907 0.48704248
# Heart specific 25%- human, chimp, and rhesus

human_chimp_rhesus_heart_specific_25_hs_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_heart_specific_25_hs_test.bed", header = FALSE)
human_chimp_rhesus_heart_specific_25_conserved_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_heart_specific_25_conserved_test.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_rhesus_heart_specific_25_hs_test, human_chimp_rhesus_heart_specific_25_conserved_test)
## Warning in prop.test(x = c(nrow(hypo_only_hs_overlap),
## nrow(hypo_only_conserved_overlap)), : Chi-squared approximation may be
## incorrect
##      fraction_hs_overlap fraction_conserved_overlap          
## [1,]           0.7756118                  0.8550725 0.1559953
## [2,]           0.8094556                  0.8923077 0.1279157
## [3,]           0.5520505                  0.2500000 0.4834394
# Heart specific 50%- human and chimp

human_chimp_heart_specific_50_hs_test <- read.delim("../data/overlap_reg/human_chimp_heart_specific_50_hs_test.bed", header = FALSE)
human_chimp_heart_specific_50_conserved_test <- read.delim("../data/overlap_reg/human_chimp_heart_specific_50_conserved_test.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_heart_specific_50_hs_test, human_chimp_heart_specific_50_conserved_test)
## Warning in prop.test(x = c(nrow(hypo_only_hs_overlap),
## nrow(hypo_only_conserved_overlap)), : Chi-squared approximation may be
## incorrect
##      fraction_hs_overlap fraction_conserved_overlap          
## [1,]           0.4263607                  0.4324324 0.9059476
## [2,]           0.4634731                  0.4567901 0.8994426
## [3,]           0.1225490                  0.0625000 0.7532367
# Heart specific 50%- human, chimp, and rhesus

human_chimp_rhesus_heart_specific_50_hs_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_heart_specific_50_hs_test.bed", header = FALSE)
human_chimp_rhesus_heart_specific_50_conserved_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_heart_specific_50_conserved_test.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_rhesus_heart_specific_50_hs_test, human_chimp_rhesus_heart_specific_50_conserved_test)
## Warning in prop.test(x = c(nrow(hypo_only_hs_overlap),
## nrow(hypo_only_conserved_overlap)), : Chi-squared approximation may be
## incorrect
##      fraction_hs_overlap fraction_conserved_overlap           
## [1,]           0.7424492                  0.9024390 0.03188221
## [2,]           0.7725031                  0.9473684 0.01823557
## [3,]           0.4974874                  0.3333333 1.00000000
# Heart specific 75%- human and chimp

human_chimp_heart_specific_75_hs_test <- read.delim("../data/overlap_reg/human_chimp_heart_specific_75_hs_test.bed", header = FALSE)
human_chimp_heart_specific_75_conserved_test <- read.delim("../data/overlap_reg/human_chimp_heart_specific_75_conserved_test.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_heart_specific_75_hs_test, human_chimp_heart_specific_75_conserved_test)
## Warning in prop.test(x = c(nrow(hypo_only_hs_overlap),
## nrow(hypo_only_conserved_overlap)), : Chi-squared approximation may be
## incorrect
##      fraction_hs_overlap fraction_conserved_overlap          
## [1,]           0.2903907                  0.2608696 0.7911581
## [2,]           0.3058419                  0.2727273 0.7657660
## [3,]           0.1081081                  0.0000000 1.0000000
# Heart specific 75%- human, chimp, and rhesus

human_chimp_rhesus_heart_specific_75_hs_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_heart_specific_75_hs_test.bed", header = FALSE)
human_chimp_rhesus_heart_specific_75_conserved_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_heart_specific_75_conserved_test.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_rhesus_heart_specific_75_hs_test, human_chimp_rhesus_heart_specific_75_conserved_test)
## Warning in prop.test(x = c(nrow(filename_human_specific_overlap),
## nrow(filename_conserved_overlap)), : Chi-squared approximation may be
## incorrect

## Warning in prop.test(x = c(nrow(filename_human_specific_overlap),
## nrow(filename_conserved_overlap)), : Chi-squared approximation may be
## incorrect

## Warning in prop.test(x = c(nrow(filename_human_specific_overlap),
## nrow(filename_conserved_overlap)), : Chi-squared approximation may be
## incorrect
##      fraction_hs_overlap fraction_conserved_overlap          
## [1,]           0.7124464                  0.6666667 1.0000000
## [2,]           0.7299185                  1.0000000 0.9504976
## [3,]           0.5068493                  0.0000000 1.0000000

Liver specific

Row 2 is the hypomethylated region.

# Liver specific 25%- human and chimp

human_chimp_heart_specific_25_hs_test <- read.delim("../data/overlap_reg/human_chimp_liver_specific_25_hs_test.bed", header = FALSE)

human_chimp_heart_specific_25_conserved_test <- read.delim("../data/overlap_reg/human_chimp_liver_specific_25_conserved_test.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_heart_specific_25_hs_test, human_chimp_heart_specific_25_conserved_test)
##      fraction_hs_overlap fraction_conserved_overlap             
## [1,]           0.2675483                  0.3071799 0.0143412074
## [2,]           0.2183250                  0.2790485 0.0005617279
## [3,]           0.3884007                  0.4263566 0.3392974626
# liver specific 25%- human, chimp, and rhesus

#human_chimp_rhesus_heart_specific_25_hs_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_liver_specific_25_hs_test.bed", header = FALSE)
#human_chimp_rhesus_heart_specific_25_conserved_test <- read.table("../data/overlap_reg/human_chimp_rhesus_liver_specific_25_conserved_test.bed", header = FALSE)

#diff_prop_hs_versus_conserved(human_chimp_rhesus_heart_specific_25_hs_test, human_chimp_rhesus_heart_specific_25_conserved_test)

# liver specific 50%- human and chimp

human_chimp_heart_specific_50_hs_test <- read.delim("../data/overlap_reg/human_chimp_liver_specific_50_hs_test.bed", header = FALSE)
human_chimp_heart_specific_50_conserved_test <- read.delim("../data/overlap_reg/human_chimp_liver_specific_50_conserved_test.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_heart_specific_50_hs_test, human_chimp_heart_specific_50_conserved_test)
##      fraction_hs_overlap fraction_conserved_overlap          
## [1,]           0.1646377                  0.1606218 0.8475217
## [2,]           0.1203704                  0.1386749 0.2833358
## [3,]           0.2983683                  0.2764228 0.7196738
# liver specific 50%- human, chimp, and rhesus

#human_chimp_rhesus_heart_specific_50_hs_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_liver_specific_50_hs_test.bed", header = FALSE)
#human_chimp_rhesus_heart_specific_50_conserved_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_liver_specific_50_conserved_test.bed", header = FALSE)

#diff_prop_hs_versus_conserved(human_chimp_rhesus_heart_specific_50_hs_test, human_chimp_rhesus_heart_specific_50_conserved_test)



# liver specific 75%- human and chimp

human_chimp_heart_specific_75_hs_test <- read.delim("../data/overlap_reg/human_chimp_liver_specific_75_hs_test.bed", header = FALSE)
human_chimp_heart_specific_75_conserved_test <- read.delim("../data/overlap_reg/human_chimp_liver_specific_75_conserved_test.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_heart_specific_75_hs_test, human_chimp_heart_specific_75_conserved_test)
##      fraction_hs_overlap fraction_conserved_overlap          
## [1,]          0.08370837                 0.09905660 0.5510101
## [2,]          0.06394708                 0.08839779 0.3024212
## [3,]          0.17156863                 0.16129032 1.0000000
# liver specific 75%- human, chimp, and rhesus

#human_chimp_rhesus_heart_specific_75_hs_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_liver_specific_75_hs_test.bed", header = FALSE)
#human_chimp_rhesus_heart_specific_75_conserved_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_liver_specific_75_conserved_test.bed", header = FALSE)

#diff_prop_hs_versus_conserved(human_chimp_rhesus_heart_specific_75_hs_test, human_chimp_rhesus_heart_specific_75_conserved_test)

lung specific

# lung specific 25%- human and chimp

human_chimp_heart_specific_25_hs_test <- read.delim("../data/overlap_reg/human_chimp_lung_specific_25_hs_test.bed", header = FALSE)

human_chimp_heart_specific_25_conserved_test <- read.delim("../data/overlap_reg/human_chimp_lung_specific_25_conserved_test.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_heart_specific_25_hs_test, human_chimp_heart_specific_25_conserved_test)
## Warning in prop.test(x = c(nrow(hypo_only_hs_overlap),
## nrow(hypo_only_conserved_overlap)), : Chi-squared approximation may be
## incorrect

## Warning in prop.test(x = c(nrow(hypo_only_hs_overlap),
## nrow(hypo_only_conserved_overlap)), : Chi-squared approximation may be
## incorrect
##      fraction_hs_overlap fraction_conserved_overlap          
## [1,]          0.12149533                  0.1568627 0.6188327
## [2,]          0.16783217                  0.1428571 1.0000000
## [3,]          0.09824561                  0.1666667 0.3949900
# lung specific 25%- human, chimp, and rhesus

#human_chimp_rhesus_heart_specific_25_hs_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_lung_specific_25_hs_test.bed", header = FALSE)
#human_chimp_rhesus_heart_specific_25_conserved_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_lung_specific_25_conserved_test.bed", header = FALSE)

#diff_prop_hs_versus_conserved(human_chimp_rhesus_heart_specific_25_hs_test, human_chimp_rhesus_heart_specific_25_conserved_test)

# lung specific 50%- human and chimp

human_chimp_heart_specific_50_hs_test <- read.delim("../data/overlap_reg/human_chimp_lung_specific_50_hs_test.bed", header = FALSE)
human_chimp_heart_specific_50_conserved_test <- read.delim("../data/overlap_reg/human_chimp_lung_specific_50_conserved_test.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_heart_specific_50_hs_test, human_chimp_heart_specific_50_conserved_test)
## Warning in prop.test(x = c(nrow(filename_human_specific_overlap),
## nrow(filename_conserved_overlap)), : Chi-squared approximation may be
## incorrect

## Warning in prop.test(x = c(nrow(filename_human_specific_overlap),
## nrow(filename_conserved_overlap)), : Chi-squared approximation may be
## incorrect

## Warning in prop.test(x = c(nrow(filename_human_specific_overlap),
## nrow(filename_conserved_overlap)), : Chi-squared approximation may be
## incorrect
##      fraction_hs_overlap fraction_conserved_overlap          
## [1,]          0.08230453                  0.1304348 0.6914651
## [2,]          0.09722222                  0.1250000 1.0000000
## [3,]          0.07602339                  0.1333333 0.7740207
# lung specific 50%- human, chimp, and rhesus

#human_chimp_rhesus_heart_specific_50_hs_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_lung_specific_50_hs_test.bed", header = FALSE)
#human_chimp_rhesus_heart_specific_50_conserved_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_lung_specific_50_conserved_test.bed", header = FALSE)

#diff_prop_hs_versus_conserved(human_chimp_rhesus_heart_specific_50_hs_test, human_chimp_rhesus_heart_specific_50_conserved_test)



# lung specific 75%- human and chimp

#human_chimp_heart_specific_75_hs_test <- read.delim("../data/overlap_reg/human_chimp_lung_specific_75_hs_test.bed", header = FALSE)
#human_chimp_heart_specific_75_conserved_test <- read.delim("../data/overlap_reg/human_chimp_lung_specific_75_conserved_test.bed", header = FALSE)

#diff_prop_hs_versus_conserved(human_chimp_heart_specific_75_hs_test, human_chimp_heart_specific_75_conserved_test)

# lung specific 75%- human, chimp, and rhesus

#human_chimp_rhesus_heart_specific_75_hs_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_lung_specific_75_hs_test.bed", header = FALSE)
#human_chimp_rhesus_heart_specific_75_conserved_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_lung_specific_75_conserved_test.bed", header = FALSE)

#diff_prop_hs_versus_conserved(human_chimp_rhesus_heart_specific_75_hs_test, human_chimp_rhesus_heart_specific_75_conserved_test)

kidney specific (comparison with H3.K27ac.27)

# kidney specific 25%- human and chimp

human_chimp_heart_specific_25_hs_test <- read.delim("../data/overlap_reg/human_chimp_kidney_specific_25_hs_test.bed", header = FALSE)

human_chimp_heart_specific_25_conserved_test <- read.delim("../data/overlap_reg/human_chimp_kidney_specific_25_conserved_test.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_heart_specific_25_hs_test, human_chimp_heart_specific_25_conserved_test)
##      fraction_hs_overlap fraction_conserved_overlap          
## [1,]           0.6044386                  0.6265329 0.2484979
## [2,]           0.5645161                  0.6666667 0.3185271
## [3,]           0.6070188                  0.6247086 0.3718584
# kidney specific 25%- human, chimp, and rhesus

human_chimp_rhesus_heart_specific_25_hs_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_kidney_specific_25_hs_test.bed", header = FALSE)
human_chimp_rhesus_heart_specific_25_conserved_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_kidney_specific_25_conserved_test.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_rhesus_heart_specific_25_hs_test, human_chimp_rhesus_heart_specific_25_conserved_test)
##      fraction_hs_overlap fraction_conserved_overlap          
## [1,]           0.6119726                  0.5719064 0.1984457
## [2,]           0.5454545                  0.5000000 0.9317478
## [3,]           0.6161810                  0.5759717 0.2097119
# kidney specific 50%- human and chimp

human_chimp_heart_specific_50_hs_test <- read.delim("../data/overlap_reg/human_chimp_kidney_specific_50_hs_test.bed", header = FALSE)
human_chimp_heart_specific_50_conserved_test <- read.delim("../data/overlap_reg/human_chimp_kidney_specific_50_conserved_test.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_heart_specific_50_hs_test, human_chimp_heart_specific_50_conserved_test)
##      fraction_hs_overlap fraction_conserved_overlap          
## [1,]           0.5590615                  0.5798165 0.4028833
## [2,]           0.5433071                  0.6785714 0.2725937
## [3,]           0.5599147                  0.5744681 0.5790053
# kidney specific 50%- human, chimp, and rhesus

human_chimp_rhesus_heart_specific_50_hs_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_kidney_specific_50_hs_test.bed", header = FALSE)
human_chimp_rhesus_heart_specific_50_conserved_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_kidney_specific_50_conserved_test.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_rhesus_heart_specific_50_hs_test, human_chimp_rhesus_heart_specific_50_conserved_test)
##      fraction_hs_overlap fraction_conserved_overlap            
## [1,]           0.5607723                  0.4397163 0.006550611
## [2,]           0.5294118                  0.5454545 1.000000000
## [3,]           0.5625000                  0.4307692 0.004449768
# kidney specific 75%- human and chimp

human_chimp_heart_specific_75_hs_test <- read.delim("../data/overlap_reg/human_chimp_kidney_specific_75_hs_test.bed", header = FALSE)
human_chimp_heart_specific_75_conserved_test <- read.delim("../data/overlap_reg/human_chimp_kidney_specific_75_conserved_test.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_heart_specific_75_hs_test, human_chimp_heart_specific_75_conserved_test)
## Warning in prop.test(x = c(nrow(hypo_only_hs_overlap),
## nrow(hypo_only_conserved_overlap)), : Chi-squared approximation may be
## incorrect
##      fraction_hs_overlap fraction_conserved_overlap          
## [1,]           0.5079251                  0.4545455 0.2594192
## [2,]           0.4285714                  0.4545455 1.0000000
## [3,]           0.5112613                  0.4545455 0.2493508
# kdiney specific 75%- human, chimp, and rhesus

human_chimp_rhesus_heart_specific_75_hs_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_kidney_specific_75_hs_test.bed", header = FALSE)
human_chimp_rhesus_heart_specific_75_conserved_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_kidney_specific_75_conserved_test.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_rhesus_heart_specific_75_hs_test, human_chimp_rhesus_heart_specific_75_conserved_test)
## Warning in prop.test(x = c(nrow(hypo_only_hs_overlap),
## nrow(hypo_only_conserved_overlap)), : Chi-squared approximation may be
## incorrect
##      fraction_hs_overlap fraction_conserved_overlap          
## [1,]           0.5137957                  0.2105263 0.0166335
## [2,]           0.4181818                  0.0000000 1.0000000
## [3,]           0.5178849                  0.2222222 0.0241384

kidney specific (comparison with H3.K27ac.153)

# kidney specific 25%- human and chimp

human_chimp_heart_specific_25_hs_test <- read.delim("../data/overlap_reg/human_chimp_kidney_specific_25_hs_test2.bed", header = FALSE)

human_chimp_heart_specific_25_conserved_test <- read.delim("../data/overlap_reg/human_chimp_kidney_specific_25_conserved_test2.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_heart_specific_25_hs_test, human_chimp_heart_specific_25_conserved_test)
## Warning in prop.test(x = c(nrow(hypo_only_hs_overlap),
## nrow(hypo_only_conserved_overlap)), : Chi-squared approximation may be
## incorrect
##      fraction_hs_overlap fraction_conserved_overlap            
## [1,]          0.05014653                 0.07461024 0.006343597
## [2,]          0.00000000                 0.00000000         NaN
## [3,]          0.05337955                 0.07799767 0.009187823
# kidney specific 25%- human, chimp, and rhesus

human_chimp_rhesus_heart_specific_25_hs_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_kidney_specific_25_hs_test2.bed", header = FALSE)
human_chimp_rhesus_heart_specific_25_conserved_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_kidney_specific_25_conserved_test2.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_rhesus_heart_specific_25_hs_test, human_chimp_rhesus_heart_specific_25_conserved_test)
##      fraction_hs_overlap fraction_conserved_overlap          
## [1,]           0.7100613                  0.6822742 0.3490362
## [2,]           0.6666667                  0.6250000 0.9524119
## [3,]           0.7128067                  0.6855124 0.3722546
# kidney specific 50%- human and chimp

human_chimp_heart_specific_50_hs_test <- read.delim("../data/overlap_reg/human_chimp_kidney_specific_50_hs_test2.bed", header = FALSE)
human_chimp_heart_specific_50_conserved_test <- read.delim("../data/overlap_reg/human_chimp_kidney_specific_50_conserved_test2.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_heart_specific_50_hs_test, human_chimp_heart_specific_50_conserved_test)
## Warning in prop.test(x = c(nrow(hypo_only_hs_overlap),
## nrow(hypo_only_conserved_overlap)), : Chi-squared approximation may be
## incorrect
##      fraction_hs_overlap fraction_conserved_overlap          
## [1,]          0.01941748                 0.02201835 0.8226097
## [2,]          0.00000000                 0.00000000       NaN
## [3,]          0.02046908                 0.02321083 0.8225119
# kidney specific 50%- human, chimp, and rhesus

human_chimp_rhesus_heart_specific_50_hs_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_kidney_specific_50_hs_test2.bed", header = FALSE)
human_chimp_rhesus_heart_specific_50_conserved_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_kidney_specific_50_conserved_test2.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_rhesus_heart_specific_50_hs_test, human_chimp_rhesus_heart_specific_50_conserved_test)
##      fraction_hs_overlap fraction_conserved_overlap           
## [1,]           0.6458973                  0.5673759 0.07247934
## [2,]           0.5294118                  0.6363636 0.71533366
## [3,]           0.6523148                  0.5615385 0.04452769
# kidney specific 75%- human and chimp

human_chimp_heart_specific_75_hs_test <- read.delim("../data/overlap_reg/human_chimp_kidney_specific_75_hs_test2.bed", header = FALSE)
human_chimp_heart_specific_75_conserved_test <- read.delim("../data/overlap_reg/human_chimp_kidney_specific_75_conserved_test2.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_heart_specific_75_hs_test, human_chimp_heart_specific_75_conserved_test)
## Warning in prop.test(x = c(nrow(filename_human_specific_overlap),
## nrow(filename_conserved_overlap)), : Chi-squared approximation may be
## incorrect

## Warning in prop.test(x = c(nrow(filename_human_specific_overlap),
## nrow(filename_conserved_overlap)), : Chi-squared approximation may be
## incorrect

## Warning in prop.test(x = c(nrow(filename_human_specific_overlap),
## nrow(filename_conserved_overlap)), : Chi-squared approximation may be
## incorrect
##      fraction_hs_overlap fraction_conserved_overlap           
## [1,]         0.005043228                 0.02097902 0.08775972
## [2,]         0.000000000                 0.00000000        NaN
## [3,]         0.005255255                 0.02272727 0.07659695
# kdiney specific 75%- human, chimp, and rhesus

human_chimp_rhesus_heart_specific_75_hs_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_kidney_specific_75_hs_test2.bed", header = FALSE)
human_chimp_rhesus_heart_specific_75_conserved_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_kidney_specific_75_conserved_test2.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_rhesus_heart_specific_75_hs_test, human_chimp_rhesus_heart_specific_75_conserved_test)
## Warning in prop.test(x = c(nrow(hypo_only_hs_overlap),
## nrow(hypo_only_conserved_overlap)), : Chi-squared approximation may be
## incorrect
##      fraction_hs_overlap fraction_conserved_overlap           
## [1,]           0.5704698                  0.3157895 0.04641865
## [2,]           0.4727273                  0.0000000 1.00000000
## [3,]           0.5746501                  0.3333333 0.06957496

kidney specific (comparison with H3.K27ac.153)

# kidney specific 25%- human and chimp

human_chimp_heart_specific_25_hs_test <- read.delim("../data/overlap_reg/human_chimp_kidney_specific_25_hs_test3.bed", header = FALSE)

human_chimp_heart_specific_25_conserved_test <- read.delim("../data/overlap_reg/human_chimp_kidney_specific_25_conserved_test3.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_heart_specific_25_hs_test, human_chimp_heart_specific_25_conserved_test)
##      fraction_hs_overlap fraction_conserved_overlap          
## [1,]           0.3730418                  0.3857302 0.5151373
## [2,]           0.2903226                  0.3846154 0.3319795
## [3,]           0.3783878                  0.3857809 0.7252123
# kidney specific 50%- human and chimp

human_chimp_heart_specific_50_hs_test <- read.delim("../data/overlap_reg/human_chimp_kidney_specific_50_hs_test3.bed", header = FALSE)
human_chimp_heart_specific_50_conserved_test <- read.delim("../data/overlap_reg/human_chimp_kidney_specific_50_conserved_test3.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_heart_specific_50_hs_test, human_chimp_heart_specific_50_conserved_test)
##      fraction_hs_overlap fraction_conserved_overlap           
## [1,]           0.3559871                  0.3688073 0.60610114
## [2,]           0.2440945                  0.4642857 0.03506309
## [3,]           0.3620469                  0.3636364 0.98602355
# kidney specific 75%- human and chimp

human_chimp_heart_specific_75_hs_test <- read.delim("../data/overlap_reg/human_chimp_kidney_specific_75_hs_test3.bed", header = FALSE)
human_chimp_heart_specific_75_conserved_test <- read.delim("../data/overlap_reg/human_chimp_kidney_specific_75_conserved_test3.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_heart_specific_75_hs_test, human_chimp_heart_specific_75_conserved_test)
## Warning in prop.test(x = c(nrow(hypo_only_hs_overlap),
## nrow(hypo_only_conserved_overlap)), : Chi-squared approximation may be
## incorrect
##      fraction_hs_overlap fraction_conserved_overlap          
## [1,]           0.3386167                  0.3076923 0.5140024
## [2,]           0.2500000                  0.3636364 0.6852371
## [3,]           0.3423423                  0.3030303 0.4157341
# kdiney specific 75%- human, chimp, and rhesus

human_chimp_rhesus_heart_specific_75_hs_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_kidney_specific_75_hs_test2.bed", header = FALSE)
human_chimp_rhesus_heart_specific_75_conserved_test <- read.delim("../data/overlap_reg/human_chimp_rhesus_kidney_specific_75_conserved_test2.bed", header = FALSE)

diff_prop_hs_versus_conserved(human_chimp_rhesus_heart_specific_75_hs_test, human_chimp_rhesus_heart_specific_75_conserved_test)
## Warning in prop.test(x = c(nrow(hypo_only_hs_overlap),
## nrow(hypo_only_conserved_overlap)), : Chi-squared approximation may be
## incorrect
##      fraction_hs_overlap fraction_conserved_overlap           
## [1,]           0.5704698                  0.3157895 0.04641865
## [2,]           0.4727273                  0.0000000 1.00000000
## [3,]           0.5746501                  0.3333333 0.06957496