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

Introduction

# Import libraries

library("ggplot2")
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")
## Warning: package 'bedr' was built under R version 3.4.4
## 
## 
## ######################
## #### bedr v1.0.7 ####
## ######################
## 
## 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])

library("topGO")
## Loading required package: BiocGenerics
## Loading required package: parallel
## 
## Attaching package: 'BiocGenerics'
## The following objects are masked from 'package:parallel':
## 
##     clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
##     clusterExport, clusterMap, parApply, parCapply, parLapply,
##     parLapplyLB, parRapply, parSapply, parSapplyLB
## The following objects are masked from 'package:dplyr':
## 
##     combine, intersect, setdiff, union
## The following objects are masked from 'package:stats':
## 
##     IQR, mad, sd, var, xtabs
## The following objects are masked from 'package:base':
## 
##     anyDuplicated, append, as.data.frame, cbind, colMeans,
##     colnames, colSums, do.call, duplicated, eval, evalq, Filter,
##     Find, get, grep, grepl, intersect, is.unsorted, lapply,
##     lengths, Map, mapply, match, mget, order, paste, pmax,
##     pmax.int, pmin, pmin.int, Position, rank, rbind, Reduce,
##     rowMeans, rownames, rowSums, sapply, setdiff, sort, table,
##     tapply, union, unique, unsplit, which, which.max, which.min
## Loading required package: graph
## 
## Attaching package: 'graph'
## The following object is masked from 'package:plyr':
## 
##     join
## Loading required package: Biobase
## Welcome to Bioconductor
## 
##     Vignettes contain introductory material; view with
##     'browseVignettes()'. To cite Bioconductor, see
##     'citation("Biobase")', and for packages 'citation("pkgname")'.
## Loading required package: GO.db
## Loading required package: AnnotationDbi
## Loading required package: stats4
## Loading required package: IRanges
## Loading required package: S4Vectors
## 
## Attaching package: 'S4Vectors'
## The following objects are masked from 'package:dplyr':
## 
##     first, rename
## The following object is masked from 'package:plyr':
## 
##     rename
## The following object is masked from 'package:base':
## 
##     expand.grid
## 
## Attaching package: 'IRanges'
## The following objects are masked from 'package:dplyr':
## 
##     collapse, desc, slice
## The following object is masked from 'package:plyr':
## 
##     desc
## 
## Attaching package: 'AnnotationDbi'
## The following object is masked from 'package:dplyr':
## 
##     select
## 
## Loading required package: SparseM
## 
## Attaching package: 'SparseM'
## The following object is masked from 'package:base':
## 
##     backsolve
## 
## groupGOTerms:    GOBPTerm, GOMFTerm, GOCCTerm environments built.
## 
## Attaching package: 'topGO'
## The following object is masked from 'package:IRanges':
## 
##     members
## The following object is masked from 'package:grid':
## 
##     depth
#library("biomaRt")
library("clusterProfiler")
## Loading required package: DOSE
## DOSE v3.4.0  For help: https://guangchuangyu.github.io/DOSE
## 
## If you use DOSE in published research, please cite:
## Guangchuang Yu, Li-Gen Wang, Guang-Rong Yan, Qing-Yu He. DOSE: an R/Bioconductor package for Disease Ontology Semantic and Enrichment analysis. Bioinformatics 2015, 31(4):608-609
## clusterProfiler v3.6.0  For help: https://guangchuangyu.github.io/clusterProfiler
## 
## If you use clusterProfiler in published research, please cite:
## Guangchuang Yu., Li-Gen Wang, Yanyan Han, Qing-Yu He. clusterProfiler: an R package for comparing biological themes among gene clusters. OMICS: A Journal of Integrative Biology. 2012, 16(5):284-287.
library("org.Hs.eg.db")
## 

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//RtmpDtLF2z/a_4f37761bbe4f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374518aeda.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//RtmpDtLF2z/a_4f3719725886.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376b57d2.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//RtmpDtLF2z/a_4f3716da4e8.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3743a8f105.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//RtmpDtLF2z/a_4f3739d674e7.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377a292231.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//RtmpDtLF2z/a_4f375d2c0cf3.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373b25fa7d.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//RtmpDtLF2z/a_4f374389abfe.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3724db9d54.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//RtmpDtLF2z/a_4f375ec265f3.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3737967555.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//RtmpDtLF2z/a_4f371f222d39.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37259ff023.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//RtmpDtLF2z/a_4f373f5d033d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37148069ae.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//RtmpDtLF2z/a_4f372ba3707.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3764e1ec1d.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//RtmpDtLF2z/a_4f374319d4e5.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377e55fb53.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//RtmpDtLF2z/a_4f373889361.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377ecc99c9.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//RtmpDtLF2z/a_4f37213fce76.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377d46dafd.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//RtmpDtLF2z/a_4f3715b5852c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371f32bd02.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//RtmpDtLF2z/a_4f377d00611e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374178229c.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//RtmpDtLF2z/a_4f377ece6d38.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372134fcbf.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//RtmpDtLF2z/a_4f37255af60f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37685f79bf.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//RtmpDtLF2z/a_4f371520e7a8.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372d983cb9.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//RtmpDtLF2z/a_4f37598a5f94.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3774f6b8e1.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//RtmpDtLF2z/a_4f374a91c410.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3751245b5.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//RtmpDtLF2z/a_4f374b8aadad.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3774fcdc2d.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//RtmpDtLF2z/a_4f372ad562c4.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3767b5e921.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//RtmpDtLF2z/a_4f3776c909f1.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37181f9492.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//RtmpDtLF2z/a_4f37312f54e9.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3735e49946.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//RtmpDtLF2z/a_4f373f83bce4.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37108e3f0c.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//RtmpDtLF2z/a_4f373905f22e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375eb97a21.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//RtmpDtLF2z/a_4f375e70baa8.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376b2919.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//RtmpDtLF2z/a_4f371ba29ac9.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374764dc42.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//RtmpDtLF2z/a_4f37319b23bf.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371b8a2a80.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//RtmpDtLF2z/a_4f3722fb2b19.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373129e6d8.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//RtmpDtLF2z/a_4f376989c2eb.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374a77e0dc.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//RtmpDtLF2z/a_4f37203a2f14.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37289939f7.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//RtmpDtLF2z/a_4f37b1243bc.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371bbf5039.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//RtmpDtLF2z/a_4f375cc79978.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373b308c79.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//RtmpDtLF2z/a_4f3741c0b742.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37295892b4.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//RtmpDtLF2z/a_4f37c8f0d12.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3763657b89.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//RtmpDtLF2z/a_4f376a0f8117.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37974b2b4.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//RtmpDtLF2z/a_4f3731cd8237.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3725a2ed59.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//RtmpDtLF2z/a_4f375a23036.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3779badf6a.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//RtmpDtLF2z/a_4f37e436df7.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372b623482.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//RtmpDtLF2z/a_4f372b3bc290.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371fb87ce.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//RtmpDtLF2z/a_4f3733603c2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37756aa5d2.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//RtmpDtLF2z/a_4f3750a62067.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37127fe07.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//RtmpDtLF2z/a_4f371173af31.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372dfb3ae3.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//RtmpDtLF2z/a_4f372088d5db.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371bceba98.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//RtmpDtLF2z/a_4f37c460952.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3768852233.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//RtmpDtLF2z/a_4f376d43165c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377f36de36.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//RtmpDtLF2z/a_4f372b8856aa.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37553666ce.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//RtmpDtLF2z/a_4f3745d4a091.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376988339f.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//RtmpDtLF2z/a_4f374d892bba.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371f332c46.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//RtmpDtLF2z/a_4f3751bcb5d5.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372c271019.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//RtmpDtLF2z/a_4f372f2918bc.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37687ac659.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//RtmpDtLF2z/a_4f375e6eed2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3725c93341.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//RtmpDtLF2z/a_4f3756003d37.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3732a16e02.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//RtmpDtLF2z/a_4f376a6f515d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375cedabbb.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//RtmpDtLF2z/a_4f371dbccf98.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37ca65fa3.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//RtmpDtLF2z/a_4f3785c83d7.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37240297af.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//RtmpDtLF2z/a_4f376d6ac56f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37112e0592.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//RtmpDtLF2z/a_4f374419fbee.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3739e1aacd.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//RtmpDtLF2z/a_4f375352d2aa.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375d3a7907.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//RtmpDtLF2z/a_4f373a53ed32.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374f524c08.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//RtmpDtLF2z/a_4f371d7f5e94.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3746987651.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//RtmpDtLF2z/a_4f376ff95cb3.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372d388af9.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//RtmpDtLF2z/a_4f372c776533.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3724166e0.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//RtmpDtLF2z/a_4f376662fd94.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375e718c6c.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) #2969
## [1] 2969   37
nrow(human_heart_specific_25[which(human_heart_specific_25[,4] == "hypo"),]) #2599
## [1] 2599
# Note: for recording #, consider using merged
#nrow(bedr.merge.region(human_DMR_heart_specific_25[,1:4]))

nrow(bedr.merge.region(human_heart_specific_25[,1:4])) #2944
## 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//RtmpDtLF2z/i_4f375169ec8d.bed -d 0 -c 4 -o collapse
##  * Collapsing 2969 --> 2964 regions... NOTE
## [1] 2964
# 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//RtmpDtLF2z/a_4f376407844f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3757526805.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//RtmpDtLF2z/a_4f37604ba3fc.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37743239c6.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//RtmpDtLF2z/a_4f3721ba68e2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372884f449.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//RtmpDtLF2z/a_4f374ba0f9e4.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371e7a43f5.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//RtmpDtLF2z/a_4f37676a59a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3757ce1a18.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) #2133
## [1] 2133   37
nrow(human_heart_specific_50[which(human_heart_specific_50[,4] == "hypo"),]) #1913
## [1] 1913
nrow(bedr.merge.region(human_heart_specific_50[,1:4])) #2133
## 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//RtmpDtLF2z/i_4f37368cb8dd.bed -d 0 -c 4 -o collapse
##  * Collapsing 2133 --> 2133 regions... NOTE
## [1] 2133
# 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//RtmpDtLF2z/a_4f3778b000d4.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377c52ee.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//RtmpDtLF2z/a_4f37799a2456.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37396eaebc.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//RtmpDtLF2z/a_4f372001da35.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37543fe473.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//RtmpDtLF2z/a_4f37583b9ef.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373b98e4d0.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//RtmpDtLF2z/a_4f377c0de4fd.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376c388595.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) #993
## [1] 993  37
nrow(human_heart_specific_75[which(human_heart_specific_75[,4] == "hypo"),]) #917
## [1] 917
nrow(bedr.merge.region(human_heart_specific_75[,1:4])) #993
## 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//RtmpDtLF2z/i_4f373843b44c.bed -d 0 -c 4 -o collapse
##  * Collapsing 993 --> 993 regions... NOTE
## [1] 993
# 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//RtmpDtLF2z/a_4f373b5e686b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3732876628.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//RtmpDtLF2z/a_4f377a2e8655.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3716c6324f.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//RtmpDtLF2z/a_4f371f7c0ccf.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37688526f0.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//RtmpDtLF2z/a_4f3733911a26.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374bb184e8.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//RtmpDtLF2z/a_4f3729cf4a59.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375be04805.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) #1743
## [1] 1743   37
nrow(chimp_heart_specific_25[which(chimp_heart_specific_25[,4] == "hypo"),]) #1493
## [1] 1493
nrow(bedr.merge.region(chimp_heart_specific_25[,1:4])) #1741
## 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//RtmpDtLF2z/i_4f375eb8bcfc.bed -d 0 -c 4 -o collapse
##  * Collapsing 1743 --> 1741 regions... NOTE
## [1] 1741
# 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//RtmpDtLF2z/a_4f374947fb60.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3763e7b8c6.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//RtmpDtLF2z/a_4f3797ce9e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3772e500ba.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//RtmpDtLF2z/a_4f375c6134c3.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373b0b3496.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//RtmpDtLF2z/a_4f3717ab7c57.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375bfa6e22.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//RtmpDtLF2z/a_4f37791401a9.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377e5eb39a.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) #1217
## [1] 1217   37
nrow(chimp_heart_specific_50[which(chimp_heart_specific_50[,4] == "hypo"),]) #1070
## [1] 1070
nrow(bedr.merge.region(chimp_heart_specific_50[,1:4])) #1217
## 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//RtmpDtLF2z/i_4f373f334ef2.bed -d 0 -c 4 -o collapse
##  * Collapsing 1217 --> 1217 regions... NOTE
## [1] 1217
# 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//RtmpDtLF2z/a_4f376a47af0a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3770d25cc2.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//RtmpDtLF2z/a_4f375c90a31e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374495ba8d.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//RtmpDtLF2z/a_4f372adf941d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3770283d35.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//RtmpDtLF2z/a_4f3710dd9cd1.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37375bc262.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//RtmpDtLF2z/a_4f377143decc.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3735a25a01.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) #556
## [1] 556  37
nrow(chimp_heart_specific_75[which(chimp_heart_specific_75[,4] == "hypo"),]) #501
## [1] 501
nrow(bedr.merge.region(chimp_heart_specific_75[,1:4])) #556
## 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//RtmpDtLF2z/i_4f371a1f0452.bed -d 0 -c 4 -o collapse
##  * Collapsing 556 --> 556 regions... NOTE
## [1] 556
# 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//RtmpDtLF2z/a_4f37658c805d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37698d631b.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//RtmpDtLF2z/a_4f373f7da6e4.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373a98ffd0.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//RtmpDtLF2z/a_4f371876d0b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375d1395c9.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//RtmpDtLF2z/a_4f3747404368.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3777f173cd.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//RtmpDtLF2z/a_4f3767a518ca.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37e5047d1.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) #1597
## [1] 1597   37
nrow(rhesus_heart_specific_25[which(rhesus_heart_specific_25[,4] == "hypo"),]) #1395
## [1] 1395
nrow(bedr.merge.region(rhesus_heart_specific_25[,1:4])) #1594
## 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//RtmpDtLF2z/i_4f374470f38a.bed -d 0 -c 4 -o collapse
##  * Collapsing 1597 --> 1594 regions... NOTE
## [1] 1594
# 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//RtmpDtLF2z/a_4f3772bc1489.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373da275d.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//RtmpDtLF2z/a_4f375cc1fe72.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3760f9e013.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//RtmpDtLF2z/a_4f372d37445c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3775b51753.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//RtmpDtLF2z/a_4f37177242b4.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37650ed19f.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//RtmpDtLF2z/a_4f37636ba4a5.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3775efd17f.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) #1148
## [1] 1148   37
nrow(rhesus_heart_specific_50[which(rhesus_heart_specific_50[,4] == "hypo"),]) #1033
## [1] 1033
nrow(bedr.merge.region(rhesus_heart_specific_50[,1:4])) #1148
## 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//RtmpDtLF2z/i_4f377be85bff.bed -d 0 -c 4 -o collapse
##  * Collapsing 1148 --> 1148 regions... NOTE
## [1] 1148
# 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//RtmpDtLF2z/a_4f3766ae61ac.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3752fa7c05.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//RtmpDtLF2z/a_4f3767ec6b6b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372796629b.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//RtmpDtLF2z/a_4f37537051cd.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3749c20b60.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//RtmpDtLF2z/a_4f373e7b83ee.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3731af08a7.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//RtmpDtLF2z/a_4f372c1a1b62.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3760e7eb7c.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) # 559
## [1] 559  37
nrow(rhesus_heart_specific_75[which(rhesus_heart_specific_75[,4] == "hypo"),]) #513
## [1] 513
nrow(bedr.merge.region(rhesus_heart_specific_75[,1:4])) #559
## 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//RtmpDtLF2z/i_4f376c15f588.bed -d 0 -c 4 -o collapse
##  * Collapsing 559 --> 559 regions... NOTE
## [1] 559

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//RtmpDtLF2z/a_4f375dd77ce4.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37617653bc.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//RtmpDtLF2z/a_4f374297e3f1.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3737e9d53.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//RtmpDtLF2z/a_4f3721001916.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375199792a.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//RtmpDtLF2z/a_4f37632e1f15.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3771ee5dfb.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//RtmpDtLF2z/a_4f375eb590e3.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373f15688f.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//RtmpDtLF2z/a_4f376949496d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3728ed856b.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//RtmpDtLF2z/a_4f376563da9c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371aa57fde.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//RtmpDtLF2z/a_4f37406e7ad.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37d3892b6.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//RtmpDtLF2z/a_4f37619e0b0a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375c4aaf87.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//RtmpDtLF2z/a_4f37487af07c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3729315f1d.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//RtmpDtLF2z/a_4f37139c3f21.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372944022f.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//RtmpDtLF2z/a_4f377ae4a66e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376120d0ea.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//RtmpDtLF2z/a_4f3741d84b1d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37664adc10.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//RtmpDtLF2z/a_4f371e0a37c5.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3728a766fd.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//RtmpDtLF2z/a_4f37cab2bee.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376f50b384.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//RtmpDtLF2z/a_4f373b7d1d39.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376d624470.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//RtmpDtLF2z/a_4f377cfdec77.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3715a0320a.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//RtmpDtLF2z/a_4f37be6503d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3718bbcf3b.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//RtmpDtLF2z/a_4f377c4ba657.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3715fe8c81.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//RtmpDtLF2z/a_4f37c013e5a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375e5a7b0a.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) #3293
## [1] 3293   37
nrow(human_liver_specific_25[which(human_liver_specific_25[,4] == "hypo"),]) #2475
## [1] 2475
nrow(bedr.merge.region(human_liver_specific_25[,1:4])) #3278
## 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//RtmpDtLF2z/i_4f3759d35283.bed -d 0 -c 4 -o collapse
##  * Collapsing 3293 --> 3278 regions... NOTE
## [1] 3278
# 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//RtmpDtLF2z/a_4f377f155859.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3778190dd4.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//RtmpDtLF2z/a_4f375fd24912.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37469d3f19.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//RtmpDtLF2z/a_4f3731e98baf.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3758a0c366.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//RtmpDtLF2z/a_4f37546fe988.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3773c96d73.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//RtmpDtLF2z/a_4f372ff942e7.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373a9db322.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) #2497
## [1] 2497   37
nrow(human_liver_specific_50[which(human_liver_specific_50[,4] == "hypo"),]) #1945
## [1] 1945
nrow(bedr.merge.region(human_liver_specific_50[,1:4])) #2497
## 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//RtmpDtLF2z/i_4f374f2d280b.bed -d 0 -c 4 -o collapse
##  * Collapsing 2497 --> 2497 regions... NOTE
## [1] 2497
# 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//RtmpDtLF2z/a_4f376fded0d5.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374f8c4cd.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//RtmpDtLF2z/a_4f376d6543be.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3743d5015d.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//RtmpDtLF2z/a_4f372934bafc.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37249a7ce1.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//RtmpDtLF2z/a_4f37135a6aae.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373852eae7.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//RtmpDtLF2z/a_4f3729cc5497.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376e8f6202.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) #1323
## [1] 1323   37
nrow(human_liver_specific_75[which(human_liver_specific_75[,4] == "hypo"),]) #1088
## [1] 1088
nrow(bedr.merge.region(human_liver_specific_75[,1:4])) #1323
## 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//RtmpDtLF2z/i_4f372d66aec3.bed -d 0 -c 4 -o collapse
##  * Collapsing 1323 --> 1323 regions... NOTE
## [1] 1323
# 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//RtmpDtLF2z/a_4f372928507a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375f8d7afc.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//RtmpDtLF2z/a_4f373fe5c927.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372816bdbb.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//RtmpDtLF2z/a_4f3721b80c75.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371e7e972f.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//RtmpDtLF2z/a_4f3730856e64.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37556b75d8.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//RtmpDtLF2z/a_4f3719372f76.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3734121591.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) #6377
## [1] 6377   37
nrow(chimp_liver_specific_25[which(chimp_liver_specific_25[,4] == "hypo"),]) #5064
## [1] 5064
nrow(bedr.merge.region(chimp_liver_specific_25[,1:4])) #6361
## 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//RtmpDtLF2z/i_4f373bf89069.bed -d 0 -c 4 -o collapse
##  * Collapsing 6377 --> 6361 regions... NOTE
## [1] 6361
# 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//RtmpDtLF2z/a_4f371f186faa.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3770c1d1c6.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//RtmpDtLF2z/a_4f3756f90388.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374f62ee63.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//RtmpDtLF2z/a_4f377c7b35a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373ffe6fd1.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//RtmpDtLF2z/a_4f37308edc34.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3732e86b0c.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//RtmpDtLF2z/a_4f377afa2a7c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37e296ab3.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) #4959
## [1] 4959   37
nrow(chimp_liver_specific_50[which(chimp_liver_specific_50[,4] == "hypo"),]) #4959
## [1] 4081
nrow(bedr.merge.region(chimp_liver_specific_50[,1:4])) # 4959
## 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//RtmpDtLF2z/i_4f371aa8e19d.bed -d 0 -c 4 -o collapse
##  * Collapsing 4959 --> 4959 regions... NOTE
## [1] 4959
# Chimp liver 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//RtmpDtLF2z/a_4f374c1ca4bd.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371f94537e.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//RtmpDtLF2z/a_4f3773c1fd20.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373ed8a9a1.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//RtmpDtLF2z/a_4f372933a352.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373d406276.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//RtmpDtLF2z/a_4f377e5ceca1.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377252c56f.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//RtmpDtLF2z/a_4f371d8b0fe2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372a6cff31.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) #2851
## [1] 2851   37
nrow(chimp_liver_specific_75[which(chimp_liver_specific_75[,4] == "hypo"),]) #2472
## [1] 2472
nrow(bedr.merge.region(chimp_liver_specific_75[,1:4])) # 2851
## 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//RtmpDtLF2z/i_4f37af7f8cb.bed -d 0 -c 4 -o collapse
##  * Collapsing 2851 --> 2851 regions... NOTE
## [1] 2851
# 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//RtmpDtLF2z/a_4f3768c10000.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3746c01163.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//RtmpDtLF2z/a_4f3747b7d418.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3720abb114.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//RtmpDtLF2z/a_4f373a7e3058.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37188cae40.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//RtmpDtLF2z/a_4f37769f7137.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37152ab8ac.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//RtmpDtLF2z/a_4f37383c83f6.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37134d38f4.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) #11470
## [1] 11470    37
nrow(rhesus_liver_specific_25[which(rhesus_liver_specific_25[,4] == "hypo"),]) #8880
## [1] 8880
nrow(bedr.merge.region(rhesus_liver_specific_25[,1:4])) # 11433
## 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//RtmpDtLF2z/i_4f3791bdad1.bed -d 0 -c 4 -o collapse
##  * Collapsing 11470 --> 11433 regions... NOTE
## [1] 11433
# Rhesus liver 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//RtmpDtLF2z/a_4f3741e9dd65.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3754fd8205.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//RtmpDtLF2z/a_4f377009a8f5.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37717fd77f.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//RtmpDtLF2z/a_4f371bb2be51.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3713368c59.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//RtmpDtLF2z/a_4f3731ac3ea2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376c65a1.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//RtmpDtLF2z/a_4f373693393d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3721183bd1.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
nrow(rhesus_liver_specific_50[which(rhesus_liver_specific_50[,4] == "hypo"),]) #8880
## [1] 7569
nrow(bedr.merge.region(rhesus_liver_specific_50[,1:4])) # 11433
## 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//RtmpDtLF2z/i_4f373a6e14fc.bed -d 0 -c 4 -o collapse
##  * Collapsing 9549 --> 9549 regions... NOTE
## [1] 9549
# Rhesus liver 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//RtmpDtLF2z/a_4f3729b381a2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377e92327e.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//RtmpDtLF2z/a_4f373b8eba9c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3773e180ac.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//RtmpDtLF2z/a_4f37f1d0b2f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377d268728.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//RtmpDtLF2z/a_4f37749fec5b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373b88c888.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//RtmpDtLF2z/a_4f3763e15fa1.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371dd99649.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) #5949
## [1] 5949   37
nrow(rhesus_liver_specific_75[which(rhesus_liver_specific_75[,4] == "hypo"),]) #5018
## [1] 5018
nrow(bedr.merge.region(rhesus_liver_specific_75[,1:4])) # 5949
## 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//RtmpDtLF2z/i_4f371ad62d08.bed -d 0 -c 4 -o collapse
##  * Collapsing 5949 --> 5949 regions... NOTE
## [1] 5949

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//RtmpDtLF2z/a_4f372436c520.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3741ba32d.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//RtmpDtLF2z/a_4f3715552c96.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377e80112a.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//RtmpDtLF2z/a_4f372ab25765.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377d59f6c9.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//RtmpDtLF2z/a_4f375b77955c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376a985b7c.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//RtmpDtLF2z/a_4f376ecc167d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37512e1a39.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//RtmpDtLF2z/a_4f3725c89785.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371975752f.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//RtmpDtLF2z/a_4f3777218908.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37523aa15f.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//RtmpDtLF2z/a_4f375129956b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37697432d0.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//RtmpDtLF2z/a_4f3718014af4.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375e03e34e.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//RtmpDtLF2z/a_4f3751cfe81c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373303e389.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//RtmpDtLF2z/a_4f378a70a3b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3772e022f.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//RtmpDtLF2z/a_4f37347d3cf3.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377c7a2d9f.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//RtmpDtLF2z/a_4f3734eec0c3.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375b486eaf.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//RtmpDtLF2z/a_4f37ed5b62d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374eee3a59.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//RtmpDtLF2z/a_4f3748663061.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37332bb65f.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//RtmpDtLF2z/a_4f376328a0e6.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3768e1ad9f.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//RtmpDtLF2z/a_4f3713dbc246.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372ada060b.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//RtmpDtLF2z/a_4f37611c856d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3751e1361.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//RtmpDtLF2z/a_4f3749b87faa.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372d64982d.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//RtmpDtLF2z/a_4f375afacf64.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37272ba4bf.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) #479
## [1] 479  37
nrow(human_lung_specific_25[which(human_lung_specific_25[,4] == "hypo"),]) #163
## [1] 163
nrow(bedr.merge.region(human_lung_specific_25[,1:4])) #478
## 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//RtmpDtLF2z/i_4f37703a6167.bed -d 0 -c 4 -o collapse
##  * Collapsing 479 --> 478 regions... NOTE
## [1] 478
## 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//RtmpDtLF2z/a_4f37705b9860.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3798a9656.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//RtmpDtLF2z/a_4f37722ad8ab.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37686582e0.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//RtmpDtLF2z/a_4f37efc6023.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3728dccad3.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//RtmpDtLF2z/a_4f373722ebd1.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374f1a9f67.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//RtmpDtLF2z/a_4f373f10ccbe.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37a464dcb.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) #266
## [1] 266  37
nrow(human_lung_specific_50[which(human_lung_specific_50[,4] == "hypo"),]) #80
## [1] 80
nrow(bedr.merge.region(human_lung_specific_50[,1:4])) #266
## 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//RtmpDtLF2z/i_4f3752db3619.bed -d 0 -c 4 -o collapse
##  * Collapsing 266 --> 266 regions... NOTE
## [1] 266
## 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//RtmpDtLF2z/a_4f374ea3f50e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377a0df142.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//RtmpDtLF2z/a_4f37665172a4.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37349c459c.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//RtmpDtLF2z/a_4f3718083e8.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376a8a3a59.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//RtmpDtLF2z/a_4f37147eceb2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37231750e0.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//RtmpDtLF2z/a_4f3753bde540.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373204e9c3.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) #84
## [1] 84 37
nrow(human_lung_specific_75[which(human_lung_specific_75[,4] == "hypo"),]) #27
## [1] 27
nrow(bedr.merge.region(human_lung_specific_75[,1:4])) #84
## 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//RtmpDtLF2z/i_4f37532c930a.bed -d 0 -c 4 -o collapse
##  * Collapsing 84 --> 84 regions... NOTE
## [1] 84
## 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//RtmpDtLF2z/a_4f37e9223cd.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37c7b983b.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//RtmpDtLF2z/a_4f371aa749be.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3784ee086.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//RtmpDtLF2z/a_4f374fc76df7.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3715c737b3.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//RtmpDtLF2z/a_4f3750b424bb.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371008b097.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//RtmpDtLF2z/a_4f375611aa83.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3718374e69.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) #453
## [1] 453  37
nrow(chimp_lung_specific_25[which(chimp_lung_specific_25[,4] == "hypo"),]) # 129
## [1] 129
nrow(bedr.merge.region(chimp_lung_specific_25[,1:4])) #452
## 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//RtmpDtLF2z/i_4f3772ca0c43.bed -d 0 -c 4 -o collapse
##  * Collapsing 453 --> 452 regions... NOTE
## [1] 452
## 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//RtmpDtLF2z/a_4f374822a9dd.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3772fefab2.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//RtmpDtLF2z/a_4f3716b458bc.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376a095e68.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//RtmpDtLF2z/a_4f3779d6158b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377f5e0b94.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//RtmpDtLF2z/a_4f374d888d96.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3728b07844.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//RtmpDtLF2z/a_4f3725be5f15.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375ac8a540.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) # 294
## [1] 294  37
nrow(chimp_lung_specific_50[which(chimp_lung_specific_50[,4] == "hypo"),]) # 73
## [1] 73
nrow(bedr.merge.region(chimp_lung_specific_50[,1:4])) # 294
## 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//RtmpDtLF2z/i_4f371bc5172a.bed -d 0 -c 4 -o collapse
##  * Collapsing 294 --> 294 regions... NOTE
## [1] 294
## 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//RtmpDtLF2z/a_4f3759a28540.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3730c47695.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//RtmpDtLF2z/a_4f371f90f3f9.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374a31ce9.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//RtmpDtLF2z/a_4f3713c00aa6.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373086eded.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//RtmpDtLF2z/a_4f376350bec6.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375a33d078.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//RtmpDtLF2z/a_4f37feca1f5.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372e9137f5.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) # 117
## [1] 117  37
nrow(chimp_lung_specific_75[which(chimp_lung_specific_75[,4] == "hypo"),]) # 25
## [1] 25
nrow(bedr.merge.region(chimp_lung_specific_75[,1:4])) # 117
## 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//RtmpDtLF2z/i_4f375a5146de.bed -d 0 -c 4 -o collapse
##  * Collapsing 117 --> 117 regions... NOTE
## [1] 117
# 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//RtmpDtLF2z/a_4f375772c97e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374ad3071f.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//RtmpDtLF2z/a_4f37255c815d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37480a218f.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//RtmpDtLF2z/a_4f3732ca7f26.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37659e10aa.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//RtmpDtLF2z/a_4f374c7cb5ce.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37fe9cd8e.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//RtmpDtLF2z/a_4f374fd2d549.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376483820f.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) #526
## [1] 526  37
nrow(rhesus_lung_specific_25[which(rhesus_lung_specific_25[,4] == "hypo"),]) # 94
## [1] 94
nrow(bedr.merge.region(rhesus_lung_specific_25[,1:4])) # 524
## 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//RtmpDtLF2z/i_4f3721078087.bed -d 0 -c 4 -o collapse
##  * Collapsing 526 --> 524 regions... NOTE
## [1] 524
## 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//RtmpDtLF2z/a_4f37232cac28.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377fb4c863.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//RtmpDtLF2z/a_4f377624371f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375a293dee.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//RtmpDtLF2z/a_4f376bd3b5e7.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371e46e786.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//RtmpDtLF2z/a_4f372552e87c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3724521e68.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//RtmpDtLF2z/a_4f374dd35b69.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376c7039d4.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) #324
## [1] 324  37
nrow(rhesus_lung_specific_50[which(rhesus_lung_specific_50[,4] == "hypo"),]) # 48
## [1] 48
nrow(bedr.merge.region(rhesus_lung_specific_50[,1:4])) # 324
## 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//RtmpDtLF2z/i_4f37283bfd5e.bed -d 0 -c 4 -o collapse
##  * Collapsing 324 --> 324 regions... NOTE
## [1] 324
## 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//RtmpDtLF2z/a_4f3765ada6cd.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3745a34471.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//RtmpDtLF2z/a_4f373ac65093.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3775bb23ee.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//RtmpDtLF2z/a_4f374fdca839.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375027fbcc.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//RtmpDtLF2z/a_4f37a76822d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3773fd7955.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//RtmpDtLF2z/a_4f3712c88112.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3734bcd515.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) #153
## [1] 153  37
nrow(rhesus_lung_specific_75[which(rhesus_lung_specific_75[,4] == "hypo"),]) # 16
## [1] 16
nrow(bedr.merge.region(rhesus_lung_specific_75[,1:4])) # 153
## 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//RtmpDtLF2z/i_4f3764893964.bed -d 0 -c 4 -o collapse
##  * Collapsing 153 --> 153 regions... NOTE
## [1] 153

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//RtmpDtLF2z/a_4f3757047c02.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376d4cb09e.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//RtmpDtLF2z/a_4f373439a2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3735f3287c.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//RtmpDtLF2z/a_4f3733b869f7.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3745294d57.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//RtmpDtLF2z/a_4f377d6c3b31.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37174f3f09.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//RtmpDtLF2z/a_4f371925cae.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372ce77e60.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//RtmpDtLF2z/a_4f3711b0adc2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37368d863f.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//RtmpDtLF2z/a_4f37146a8c17.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37384e6876.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//RtmpDtLF2z/a_4f377f8b6e80.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37294e42f4.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//RtmpDtLF2z/a_4f3713f4a8b6.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3734eb6b8a.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//RtmpDtLF2z/a_4f374f7160ab.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377a51dcd2.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//RtmpDtLF2z/a_4f37264c31d7.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375b3cd47.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//RtmpDtLF2z/a_4f37564bde7.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372630788c.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//RtmpDtLF2z/a_4f37390365f3.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37482a0b4a.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//RtmpDtLF2z/a_4f3773a65fc0.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3719fee599.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//RtmpDtLF2z/a_4f375f56e46a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371eed023.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//RtmpDtLF2z/a_4f371c0d3cf.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37150ec15f.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//RtmpDtLF2z/a_4f372e400616.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3775085333.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//RtmpDtLF2z/a_4f373dd7f892.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37262c8478.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//RtmpDtLF2z/a_4f37135d1444.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377ec1760f.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//RtmpDtLF2z/a_4f3751cf2304.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3749c81d44.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) #3967
## [1] 3967   37
nrow(human_kidney_specific_25[which(human_kidney_specific_25[,4] == "hyper"),]) # 3739
## [1] 3739
nrow(bedr.merge.region(human_kidney_specific_25[,1:4])) # 3957
## 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//RtmpDtLF2z/i_4f37c917537.bed -d 0 -c 4 -o collapse
##  * Collapsing 3967 --> 3957 regions... NOTE
## [1] 3957
## 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//RtmpDtLF2z/a_4f3755dd7076.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37757ee6e8.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//RtmpDtLF2z/a_4f37445561ee.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373ef00289.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//RtmpDtLF2z/a_4f377aa38428.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3726a88469.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//RtmpDtLF2z/a_4f372213a571.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375355caf8.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//RtmpDtLF2z/a_4f371e5799a3.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371decfc9c.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) #3017
## [1] 3017   37
nrow(human_kidney_specific_50[which(human_kidney_specific_50[,4] == "hyper"),]) #2862
## [1] 2862
nrow(bedr.merge.region(human_kidney_specific_50[,1:4])) # 3017
## 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//RtmpDtLF2z/i_4f374bacdc6d.bed -d 0 -c 4 -o collapse
##  * Collapsing 3017 --> 3017 regions... NOTE
## [1] 3017
## 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//RtmpDtLF2z/a_4f3774b9510a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3779e0e4d2.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//RtmpDtLF2z/a_4f3717949dbc.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372a2950fa.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//RtmpDtLF2z/a_4f3741ff18a6.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3766537306.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//RtmpDtLF2z/a_4f37149ff3d7.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3771b0b4a8.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//RtmpDtLF2z/a_4f371229ae0f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37b8f160.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) #1531
## [1] 1531   37
nrow(human_kidney_specific_75[which(human_kidney_specific_75[,4] == "hyper"),]) #1464
## [1] 1464
nrow(bedr.merge.region(human_kidney_specific_75[,1:4])) # 1531
## 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//RtmpDtLF2z/i_4f375b234f14.bed -d 0 -c 4 -o collapse
##  * Collapsing 1531 --> 1531 regions... NOTE
## [1] 1531
# 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//RtmpDtLF2z/a_4f374638bad0.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3763596a5a.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//RtmpDtLF2z/a_4f375ba73e0c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372e489b94.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//RtmpDtLF2z/a_4f375dd82f71.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375ccff02b.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//RtmpDtLF2z/a_4f37767d9b31.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377e4cb483.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//RtmpDtLF2z/a_4f372160caa5.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37285e1f4d.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) #2302
## [1] 2302   37
nrow(chimp_kidney_specific_25[which(chimp_kidney_specific_25[,4] == "hyper"),]) #2129
## [1] 2129
nrow(bedr.merge.region(chimp_kidney_specific_25[,1:4])) # 2300
## 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//RtmpDtLF2z/i_4f3753603d59.bed -d 0 -c 4 -o collapse
##  * Collapsing 2302 --> 2300 regions... NOTE
## [1] 2300
## 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//RtmpDtLF2z/a_4f374f6a9ea2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3755c53bf8.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//RtmpDtLF2z/a_4f3757917600.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3711bfc6b7.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//RtmpDtLF2z/a_4f371f4cb24e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375d37fbc3.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//RtmpDtLF2z/a_4f37702d09.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374f1bfb5f.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//RtmpDtLF2z/a_4f37684b68e3.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377b77a3bb.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) #1729
## [1] 1729   37
nrow(chimp_kidney_specific_50[which(chimp_kidney_specific_50[,4] == "hyper"),]) #1622
## [1] 1622
nrow(bedr.merge.region(chimp_kidney_specific_50[,1:4])) #1729
## 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//RtmpDtLF2z/i_4f3775491a62.bed -d 0 -c 4 -o collapse
##  * Collapsing 1729 --> 1729 regions... NOTE
## [1] 1729
## 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//RtmpDtLF2z/a_4f377d5e55c0.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37518e563a.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//RtmpDtLF2z/a_4f3764abd776.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375bd8423e.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//RtmpDtLF2z/a_4f37689cb72.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3752ecc60c.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//RtmpDtLF2z/a_4f3731008333.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3770112d88.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//RtmpDtLF2z/a_4f376a0caa52.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3737eb2490.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) #854
## [1] 854  37
nrow(chimp_kidney_specific_75[which(chimp_kidney_specific_75[,4] == "hyper"),]) #806
## [1] 806
nrow(bedr.merge.region(chimp_kidney_specific_75[,1:4])) #854
## 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//RtmpDtLF2z/i_4f372610703.bed -d 0 -c 4 -o collapse
##  * Collapsing 854 --> 854 regions... NOTE
## [1] 854
# 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//RtmpDtLF2z/a_4f3759e624bb.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377a5d627d.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//RtmpDtLF2z/a_4f371b251893.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37348c5eba.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//RtmpDtLF2z/a_4f37794bf25a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373231ea6e.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//RtmpDtLF2z/a_4f3710611636.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374a326d5a.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//RtmpDtLF2z/a_4f37699d7397.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3760df136a.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) #3555
## [1] 3555   37
nrow(rhesus_kidney_specific_25[which(rhesus_kidney_specific_25[,4] == "hyper"),]) #3247
## [1] 3247
nrow(bedr.merge.region(rhesus_kidney_specific_25[,1:4]))  #3547
## 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//RtmpDtLF2z/i_4f3723c14ec7.bed -d 0 -c 4 -o collapse
##  * Collapsing 3555 --> 3547 regions... NOTE
## [1] 3547
## 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//RtmpDtLF2z/a_4f373b0ec46b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37309934e0.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//RtmpDtLF2z/a_4f37123cf632.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37369c2cd0.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//RtmpDtLF2z/a_4f376a713af2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3710138f7.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//RtmpDtLF2z/a_4f375a29933.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372d792934.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//RtmpDtLF2z/a_4f379eafc9c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3764eb690a.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) #2673
## [1] 2673   37
nrow(chimp_kidney_specific_50[which(chimp_kidney_specific_50[,4] == "hyper"),]) #1622
## [1] 1622
nrow(bedr.merge.region(chimp_kidney_specific_50[,1:4])) #1729
## 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//RtmpDtLF2z/i_4f37530c7b97.bed -d 0 -c 4 -o collapse
##  * Collapsing 1729 --> 1729 regions... NOTE
## [1] 1729
## 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//RtmpDtLF2z/a_4f374fbfaf.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377eb85189.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//RtmpDtLF2z/a_4f3749b43ceb.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3776637819.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//RtmpDtLF2z/a_4f3742551558.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37587d36d1.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//RtmpDtLF2z/a_4f37753bc6c8.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377ac6ee63.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//RtmpDtLF2z/a_4f372054f6ea.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37579ea2ab.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) #1397
## [1] 1397   37
nrow(chimp_kidney_specific_75[which(chimp_kidney_specific_75[,4] == "hyper"),]) #806
## [1] 806
nrow(bedr.merge.region(chimp_kidney_specific_75[,1:4])) #854
## 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//RtmpDtLF2z/i_4f3723aa5ae1.bed -d 0 -c 4 -o collapse
##  * Collapsing 854 --> 854 regions... NOTE
## [1] 854

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//RtmpDtLF2z/a_4f3721a61860.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372438048f.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//RtmpDtLF2z/a_4f375422eda1.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3746ed873f.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//RtmpDtLF2z/a_4f3739d6e535.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374dbf112b.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//RtmpDtLF2z/a_4f3766fa4e7a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371debfd31.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//RtmpDtLF2z/a_4f375fc97839.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3727acc1df.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//RtmpDtLF2z/a_4f37815a9ff.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3713f9468a.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//RtmpDtLF2z/i_4f3722ef3efe.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//RtmpDtLF2z/i_4f37246c3911.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//RtmpDtLF2z/i_4f3717d00fd8.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//RtmpDtLF2z/a_4f375f68c598.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374c511aab.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//RtmpDtLF2z/a_4f371891d5f6.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3714ca47ac.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//RtmpDtLF2z/i_4f37132e85a4.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//RtmpDtLF2z/i_4f3712b0e2b5.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//RtmpDtLF2z/i_4f371a5d312.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//RtmpDtLF2z/a_4f37727cbddc.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376a1296d2.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//RtmpDtLF2z/a_4f37475b16f0.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374b1a673a.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//RtmpDtLF2z/i_4f37239b513b.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//RtmpDtLF2z/i_4f37519fd8c3.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//RtmpDtLF2z/i_4f377c55d57f.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//RtmpDtLF2z/a_4f372bef1764.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373b106076.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//RtmpDtLF2z/a_4f3772ac158a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374ea29702.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//RtmpDtLF2z/i_4f37434a8bcc.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//RtmpDtLF2z/i_4f37623bc423.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//RtmpDtLF2z/i_4f3736e1749f.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//RtmpDtLF2z/a_4f37269786af.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37930c41a.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//RtmpDtLF2z/a_4f3739f753f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3727b68134.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//RtmpDtLF2z/i_4f372c6b184.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//RtmpDtLF2z/i_4f3745fa80ec.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//RtmpDtLF2z/i_4f3730854552.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//RtmpDtLF2z/a_4f371dd26e8e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377b1bc68.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//RtmpDtLF2z/a_4f372466ebf5.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37296b0bf2.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//RtmpDtLF2z/i_4f376039c65a.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//RtmpDtLF2z/i_4f372938646c.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//RtmpDtLF2z/i_4f374c8b0b7c.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//RtmpDtLF2z/a_4f373d0e2ae0.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371a1314bc.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//RtmpDtLF2z/a_4f3752329d66.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3730addcdf.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//RtmpDtLF2z/i_4f375088a8a2.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//RtmpDtLF2z/i_4f3768df5325.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//RtmpDtLF2z/i_4f3731cd17e3.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//RtmpDtLF2z/a_4f375bcc0bcd.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377ccb7f4d.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//RtmpDtLF2z/a_4f37405d5734.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374c8438d8.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//RtmpDtLF2z/i_4f37bfb0abe.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//RtmpDtLF2z/i_4f3742b9770.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//RtmpDtLF2z/i_4f3765855e2a.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//RtmpDtLF2z/a_4f3760cbdfe.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374597f12f.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//RtmpDtLF2z/a_4f375105d6ef.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371c6d698d.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//RtmpDtLF2z/i_4f371c8590f2.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//RtmpDtLF2z/i_4f376aa0b660.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//RtmpDtLF2z/i_4f374ce3fcf6.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//RtmpDtLF2z/a_4f37292a0807.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371e2119a2.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//RtmpDtLF2z/a_4f3770d9a18d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371214d538.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//RtmpDtLF2z/i_4f377d1c4786.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//RtmpDtLF2z/i_4f376a4c9efa.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//RtmpDtLF2z/i_4f3711dca46.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//RtmpDtLF2z/a_4f374f096f23.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372368363d.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//RtmpDtLF2z/a_4f374822ed30.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3760c902ec.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//RtmpDtLF2z/i_4f3765e8552b.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//RtmpDtLF2z/i_4f3725d857c.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//RtmpDtLF2z/i_4f37404067dd.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//RtmpDtLF2z/a_4f37be80713.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373402de37.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//RtmpDtLF2z/a_4f372459199e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375825da9c.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//RtmpDtLF2z/i_4f37192a6810.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//RtmpDtLF2z/i_4f374d2f028e.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//RtmpDtLF2z/i_4f375cb0a222.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//RtmpDtLF2z/a_4f372affc21e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376d2738bc.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//RtmpDtLF2z/a_4f37413b7362.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372942d7b1.bed -wao -f 0.75 -F 0.75
##      [,1] [,2] [,3] [,4]
## [1,] 1388  143 1341   19

Tissue conserved 25 bp

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

  DMR1_human <- bedr.merge.region(DMR1_human)
  DMR1_chimp <- bedr.merge.region(DMR1_chimp)
  DMR1_rhesus <- bedr.merge.region(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_50_overlap <- function(DMR1_human, DMR1_chimp, DMR1_rhesus){

    DMR1_human <- bedr.merge.region(DMR1_human)
  DMR1_chimp <- bedr.merge.region(DMR1_chimp)
  DMR1_rhesus <- bedr.merge.region(DMR1_rhesus)
  
# Human-chimp/human-rhesus

human_chimp_DMR <- bedr(input = list(a = DMR1_human, b = DMR1_chimp), method = "intersect",  params = "-wao -f 0.50 -F 0.50", 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.50 -F 0.50", 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.50 -F 0.50", 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.5 -F 0.5", 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.5 -F 0.5", 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.5 -F 0.5", 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.5 -F 0.5", 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.5 -F 0.5", 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_75_overlap <- function(DMR1_human, DMR1_chimp, DMR1_rhesus){

    DMR1_human <- bedr.merge.region(DMR1_human)
  DMR1_chimp <- bedr.merge.region(DMR1_chimp)
  DMR1_rhesus <- bedr.merge.region(DMR1_rhesus)
  
# Human-chimp/human-rhesus

human_chimp_DMR <- bedr(input = list(a = DMR1_human, b = DMR1_chimp), method = "intersect",  params = "-wao -f 0.75 -F 0.75", 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.75 -F 0.75", 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.75 -F 0.75", 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.75 -F 0.75", 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.75 -F 0.75", 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.75 -F 0.75", 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.75 -F 0.75", 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.75 -F 0.75", 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 specific 25% overlap (all tDMRs)

# Heart specific- 25% overlap

tissue_conserved_25_overlap(human_heart_specific_25[,1:4], chimp_heart_specific_25[,1:4], rhesus_heart_specific_25[,1:4])
## 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//RtmpDtLF2z/i_4f3714255537.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//RtmpDtLF2z/i_4f371b14111f.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//RtmpDtLF2z/i_4f374d3ef857.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//RtmpDtLF2z/a_4f3729ca0857.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375fa00346.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//RtmpDtLF2z/a_4f37702108b0.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3748604a59.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//RtmpDtLF2z/a_4f3747e1e49a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371478d004.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//RtmpDtLF2z/i_4f374ae6192d.bed -d 0 -c 4 -o collapse
##  * Collapsing 455 --> 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//RtmpDtLF2z/i_4f379ca03b2.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//RtmpDtLF2z/i_4f3734197148.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//RtmpDtLF2z/a_4f3763833db8.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3771702b45.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//RtmpDtLF2z/a_4f372930f17e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374cef2c85.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//RtmpDtLF2z/a_4f3755dadff6.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376eba7a5a.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//RtmpDtLF2z/a_4f373046ee2f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371c3af314.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//RtmpDtLF2z/a_4f3761ea34a9.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3729b357d0.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific  hc  hr cr
## [1,]           2408           1210            1351 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


# Heart specific- 50% overlap

tissue_conserved_50_overlap(human_heart_specific_50[,1:4], chimp_heart_specific_50[,1:4], rhesus_heart_specific_50[,1:4])
## 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//RtmpDtLF2z/i_4f37511700d4.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//RtmpDtLF2z/i_4f378ba677b.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//RtmpDtLF2z/i_4f3724e53164.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//RtmpDtLF2z/a_4f372dd2e44e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371f89dabc.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//RtmpDtLF2z/a_4f374f095f16.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373f46d317.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//RtmpDtLF2z/a_4f376e1d4d84.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37437b619e.bed -wao -f 0.50 -F 0.50
## 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//RtmpDtLF2z/i_4f377e390f4b.bed -d 0 -c 4 -o collapse
##  * Collapsing 259 --> 259 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//RtmpDtLF2z/i_4f374a7ac709.bed -d 0 -c 4 -o collapse
##  * Collapsing 94 --> 94 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//RtmpDtLF2z/i_4f3769ff69ea.bed -d 0 -c 4 -o collapse
##  * Collapsing 79 --> 79 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//RtmpDtLF2z/a_4f373b07a916.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377a6d8f20.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//RtmpDtLF2z/a_4f37f69ab6e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37670796b3.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//RtmpDtLF2z/a_4f37167d8abc.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3727035744.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//RtmpDtLF2z/a_4f374f8d258c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37570ee70d.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//RtmpDtLF2z/a_4f371af1b02d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371dc38033.bed -wao -f 0.5 -F 0.5
##      human_specific chimp_specific rhesus_specific  hc hr cr hcr_conserved
## [1,]           1816            915            1011 223 58 43            36
#     human_specific chimp_specific rhesus_specific  hc hr cr hcr_conserved
#[1,]           1816            915            1011 223 58 43            36

# Heart specific- 75% overlap

tissue_conserved_75_overlap(human_heart_specific_75[,1:4], chimp_heart_specific_75[,1:4], rhesus_heart_specific_75[,1:4])
## 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//RtmpDtLF2z/i_4f372ea37e98.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//RtmpDtLF2z/i_4f374bcb1bbc.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//RtmpDtLF2z/i_4f37579df1ec.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//RtmpDtLF2z/a_4f371554d09e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3721f3675.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//RtmpDtLF2z/a_4f3714493982.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374ff71e68.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//RtmpDtLF2z/a_4f3749aabc3f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3710e6a82a.bed -wao -f 0.75 -F 0.75
## 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//RtmpDtLF2z/i_4f376092f1f8.bed -d 0 -c 4 -o collapse
##  * Collapsing 46 --> 46 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//RtmpDtLF2z/i_4f3772bfadc.bed -d 0 -c 4 -o collapse
##  * Collapsing 18 --> 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//RtmpDtLF2z/i_4f372c16814c.bed -d 0 -c 4 -o collapse
##  * Collapsing 18 --> 18 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//RtmpDtLF2z/a_4f37c96ce1b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377d1f0411.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//RtmpDtLF2z/a_4f37cb7acc4.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37397d237c.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//RtmpDtLF2z/a_4f3757febd43.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376b79c4c3.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//RtmpDtLF2z/a_4f373055a17.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3730ca2acb.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//RtmpDtLF2z/a_4f37c194d17.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375d322d3.bed -wao -f 0.75 -F 0.75
##      human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
## [1,]            932            495             526 43 15 15             3
#     human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
#[1,]            932            495             526 43 15 15             3


# Kidney specific- 25% overlap

tissue_conserved_25_overlap(human_kidney_specific_25[,1:4], chimp_kidney_specific_25[,1:4], rhesus_kidney_specific_25[,1:4])
## 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//RtmpDtLF2z/i_4f371ecdbaaa.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//RtmpDtLF2z/i_4f374a208382.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//RtmpDtLF2z/i_4f373ed36250.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//RtmpDtLF2z/a_4f373de4c699.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37327e894c.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//RtmpDtLF2z/a_4f371cfccd7d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37469c5da5.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//RtmpDtLF2z/a_4f376fc3d600.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371f3ba769.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//RtmpDtLF2z/i_4f3770f81ee3.bed -d 0 -c 4 -o collapse
##  * Collapsing 897 --> 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//RtmpDtLF2z/i_4f3721329868.bed -d 0 -c 4 -o collapse
##  * Collapsing 589 --> 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//RtmpDtLF2z/i_4f372276ecd5.bed -d 0 -c 4 -o collapse
##  * Collapsing 436 --> 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//RtmpDtLF2z/a_4f37643b82bd.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37132044b2.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//RtmpDtLF2z/a_4f374e33785d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37411544b.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//RtmpDtLF2z/a_4f377c02ad0f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371df7bacc.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//RtmpDtLF2z/a_4f3776f733a9.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3715f37312.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//RtmpDtLF2z/a_4f373f20b842.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372569a82a.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific  hc  hr  cr
## [1,]           2763           1258            2812 607 300 148
##      hcr_conserved
## [1,]           287
#     human_specific chimp_specific rhesus_specific  hc  hr  cr hcr_conserved
#[1,]           2763           1258            2812   607 300 148           287

# Kidney specific- 50% overlap

tissue_conserved_50_overlap(human_kidney_specific_50[,1:4], chimp_kidney_specific_50[,1:4], rhesus_kidney_specific_50[,1:4])
## 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//RtmpDtLF2z/i_4f376098a66e.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//RtmpDtLF2z/i_4f3712125a0d.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//RtmpDtLF2z/i_4f3744ec427f.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//RtmpDtLF2z/a_4f375ceca60.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37b4578a5.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//RtmpDtLF2z/a_4f37616966e3.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3759588fd1.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//RtmpDtLF2z/a_4f372e9bf54a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3761e7d9b.bed -wao -f 0.50 -F 0.50
## 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//RtmpDtLF2z/i_4f375b896a69.bed -d 0 -c 4 -o collapse
##  * Collapsing 545 --> 545 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//RtmpDtLF2z/i_4f375e49580a.bed -d 0 -c 4 -o collapse
##  * Collapsing 334 --> 334 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//RtmpDtLF2z/i_4f3725c11e75.bed -d 0 -c 4 -o collapse
##  * Collapsing 220 --> 220 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//RtmpDtLF2z/a_4f37353711a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377dd1b1a6.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//RtmpDtLF2z/a_4f3726d6eea6.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374a8ac16e.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//RtmpDtLF2z/a_4f372788e65a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37605222a.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//RtmpDtLF2z/a_4f373de0aab1.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377967e6d0.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//RtmpDtLF2z/a_4f37129289ea.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37172ead5f.bed -wao -f 0.5 -F 0.5
##      human_specific chimp_specific rhesus_specific  hc  hr cr
## [1,]           2263           1089            2244 420 209 95
##      hcr_conserved
## [1,]           125
#     human_specific chimp_specific rhesus_specific  hc  hr cr hcr_conserved
#[1,]           2263           1089            2244 420 209 95           125

# Kidney specific- 75% overlap

tissue_conserved_75_overlap(human_kidney_specific_75[,1:4], chimp_kidney_specific_75[,1:4], rhesus_kidney_specific_75[,1:4])
## 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//RtmpDtLF2z/i_4f3746af5ed1.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//RtmpDtLF2z/i_4f372295d65a.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//RtmpDtLF2z/i_4f375567cbf4.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//RtmpDtLF2z/a_4f372df83885.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3727306615.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//RtmpDtLF2z/a_4f37333c2c7a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37dd051fd.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//RtmpDtLF2z/a_4f3732f68b6f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374b85cef7.bed -wao -f 0.75 -F 0.75
## 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//RtmpDtLF2z/i_4f376644ece2.bed -d 0 -c 4 -o collapse
##  * Collapsing 143 --> 143 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//RtmpDtLF2z/i_4f3716edfcb2.bed -d 0 -c 4 -o collapse
##  * Collapsing 66 --> 66 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//RtmpDtLF2z/i_4f37611b5799.bed -d 0 -c 4 -o collapse
##  * Collapsing 39 --> 39 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//RtmpDtLF2z/a_4f3776c6e69c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374cde7f4.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//RtmpDtLF2z/a_4f373d6ee0a9.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3739284b3a.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//RtmpDtLF2z/a_4f373758f960.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371f6a095a.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//RtmpDtLF2z/a_4f37663d0052.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376dcad305.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//RtmpDtLF2z/a_4f37623ce5bd.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37144f5d3c.bed -wao -f 0.75 -F 0.75
##      human_specific chimp_specific rhesus_specific  hc hr cr hcr_conserved
## [1,]           1338            688            1308 127 50 23            16
#     human_specific chimp_specific rhesus_specific  hc hr cr hcr_conserved
#[1,]           1338            688            1308 127 50 23            16

# Liver specific- 25% overlap

tissue_conserved_25_overlap(human_liver_specific_25[,1:4], chimp_liver_specific_25[,1:4], rhesus_liver_specific_25[,1:4])
## 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//RtmpDtLF2z/i_4f374caa472d.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//RtmpDtLF2z/i_4f371a20cc3f.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//RtmpDtLF2z/i_4f37374061b4.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//RtmpDtLF2z/a_4f3718a35383.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373d0a774.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//RtmpDtLF2z/a_4f37232dd861.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374729738e.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//RtmpDtLF2z/a_4f373c0d8f64.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3731b213ca.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//RtmpDtLF2z/i_4f375285d43e.bed -d 0 -c 4 -o collapse
##  * Collapsing 1333 --> 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//RtmpDtLF2z/i_4f3758c1b2a4.bed -d 0 -c 4 -o collapse
##  * Collapsing 882 --> 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//RtmpDtLF2z/i_4f371197176e.bed -d 0 -c 4 -o collapse
##  * Collapsing 1336 --> 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//RtmpDtLF2z/a_4f3779bd5394.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376bf836.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//RtmpDtLF2z/a_4f37153542dd.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377f138a43.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//RtmpDtLF2z/a_4f372e5f3807.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37186626b5.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//RtmpDtLF2z/a_4f376e6b0b72.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37465a065d.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//RtmpDtLF2z/a_4f3740395950.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37155a084.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific  hc  hr  cr
## [1,]           1556           4191            9717 849 395 843
##      hcr_conserved
## [1,]           478
#      human_specific chimp_specific rhesus_specific  hc  hr  cr hcr_conserved
#[1,]           1556           4191            9717   849 395 843           478

# Liver specific- 50% overlap

tissue_conserved_50_overlap(human_liver_specific_50[,1:4], chimp_liver_specific_50[,1:4], rhesus_liver_specific_50[,1:4])
## 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//RtmpDtLF2z/i_4f37167ef41a.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//RtmpDtLF2z/i_4f3721833599.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//RtmpDtLF2z/i_4f3728f89c88.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//RtmpDtLF2z/a_4f3748154f71.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374baeae2c.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//RtmpDtLF2z/a_4f373ebacfdd.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375663ce05.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//RtmpDtLF2z/a_4f372fded01a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376e71ab4f.bed -wao -f 0.50 -F 0.50
## 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//RtmpDtLF2z/i_4f376c6339ae.bed -d 0 -c 4 -o collapse
##  * Collapsing 772 --> 772 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//RtmpDtLF2z/i_4f372a3087d1.bed -d 0 -c 4 -o collapse
##  * Collapsing 448 --> 448 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//RtmpDtLF2z/i_4f3754b7e34b.bed -d 0 -c 4 -o collapse
##  * Collapsing 676 --> 676 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//RtmpDtLF2z/a_4f3737368a59.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37618633bc.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//RtmpDtLF2z/a_4f371a98c2b9.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3754a9172c.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//RtmpDtLF2z/a_4f372f5281bf.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37f671813.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//RtmpDtLF2z/a_4f3733c8985a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377adc5d44.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//RtmpDtLF2z/a_4f373be6518d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375e138dda.bed -wao -f 0.5 -F 0.5
##      human_specific chimp_specific rhesus_specific  hc  hr  cr
## [1,]           1474           3708            8622 575 251 479
##      hcr_conserved
## [1,]           197
#     human_specific chimp_specific rhesus_specific  hc  hr  cr hcr_conserved
#[1,]           1474           3708            8622   575 251 479           197

# Liver specific- 75% overlap

tissue_conserved_75_overlap(human_liver_specific_75[,1:4], chimp_liver_specific_75[,1:4], rhesus_liver_specific_75[,1:4])
## 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//RtmpDtLF2z/i_4f373f27d3f8.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//RtmpDtLF2z/i_4f3734236aa2.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//RtmpDtLF2z/i_4f3765c7c70e.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//RtmpDtLF2z/a_4f3757ff0538.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376c3295cf.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//RtmpDtLF2z/a_4f373c424340.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3759a22bcb.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//RtmpDtLF2z/a_4f3721bac2d0.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376e5f5afa.bed -wao -f 0.75 -F 0.75
## 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//RtmpDtLF2z/i_4f373de1eef8.bed -d 0 -c 4 -o collapse
##  * Collapsing 212 --> 212 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//RtmpDtLF2z/i_4f373d49f791.bed -d 0 -c 4 -o collapse
##  * Collapsing 73 --> 73 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//RtmpDtLF2z/i_4f377ffebc55.bed -d 0 -c 4 -o collapse
##  * Collapsing 125 --> 125 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//RtmpDtLF2z/a_4f376f07856.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373d681851.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//RtmpDtLF2z/a_4f376de038a4.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3719600870.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//RtmpDtLF2z/a_4f37234ed6d4.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3712645538.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//RtmpDtLF2z/a_4f37793b80a9.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37724b3287.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//RtmpDtLF2z/a_4f377c8df02d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375ff70166.bed -wao -f 0.75 -F 0.75
##      human_specific chimp_specific rhesus_specific  hc hr  cr
## [1,]           1059           2535            5772 191 52 104
##      hcr_conserved
## [1,]            21
#     human_specific chimp_specific rhesus_specific  hc hr  cr hcr_conserved
#[1,]           1059           2535            5772 191 52 104            21

# Lung specific- 25% overlap

tissue_conserved_25_overlap(human_lung_specific_25[,1:4], chimp_lung_specific_25[,1:4], rhesus_lung_specific_25[,1:4])
## 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//RtmpDtLF2z/i_4f3765bcea59.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//RtmpDtLF2z/i_4f3717b8abc5.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//RtmpDtLF2z/i_4f3715911f99.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//RtmpDtLF2z/a_4f374fe95efe.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376c97e01b.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//RtmpDtLF2z/a_4f373ca9d6be.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3777e71cd8.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//RtmpDtLF2z/a_4f376349f70f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37626f72d5.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//RtmpDtLF2z/i_4f3745f00a87.bed -d 0 -c 4 -o collapse
##  * Collapsing 51 --> 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//RtmpDtLF2z/i_4f377f698ded.bed -d 0 -c 4 -o collapse
##  * Collapsing 18 --> 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//RtmpDtLF2z/i_4f376166beff.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//RtmpDtLF2z/a_4f37a4d0dd3.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37a380e4c.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//RtmpDtLF2z/a_4f37132be316.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375ffcb298.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//RtmpDtLF2z/a_4f371860c5b0.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37121561ba.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//RtmpDtLF2z/a_4f375b68caf2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377c3e6299.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//RtmpDtLF2z/a_4f377460729b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37577d9e62.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
## [1,]            414            381             486 46 13 20             5
#    human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
#[1,]            415            382             488 46 13 20             5

# Lung specific- 50% overlap

tissue_conserved_50_overlap(human_lung_specific_50[,1:4], chimp_lung_specific_50[,1:4], rhesus_lung_specific_50[,1:4])
## 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//RtmpDtLF2z/i_4f376492705c.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//RtmpDtLF2z/i_4f3715733fcb.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//RtmpDtLF2z/i_4f3754775aa3.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//RtmpDtLF2z/a_4f37746910d8.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3726be3f23.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//RtmpDtLF2z/a_4f378fa5055.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371db2d24b.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//RtmpDtLF2z/a_4f375bec610e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37230addbd.bed -wao -f 0.50 -F 0.50
## 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//RtmpDtLF2z/i_4f37241192f2.bed -d 0 -c 4 -o collapse
##  * Collapsing 23 --> 23 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//RtmpDtLF2z/i_4f376ae0ba2d.bed -d 0 -c 4 -o collapse
##  * Collapsing 5 --> 5 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//RtmpDtLF2z/i_4f3776a6e91.bed -d 0 -c 4 -o collapse
##  * Collapsing 10 --> 10 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//RtmpDtLF2z/a_4f373ac29c03.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3762538921.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//RtmpDtLF2z/a_4f3729d42807.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375c56c5c1.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//RtmpDtLF2z/a_4f371527e1aa.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375aeec5ef.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//RtmpDtLF2z/a_4f3763f0ec34.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373a9b42a2.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//RtmpDtLF2z/a_4f37c76de69.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3754ab1c96.bed -wao -f 0.5 -F 0.5
##      human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
## [1,]            240            263             311 21  3  8             2
#     human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
#[1,]            240            263             311 21  3  8             2

# Lung specific- 75% overlap

#tissue_conserved_75_overlap(human_lung_specific_75[,1:4], chimp_lung_specific_75[,1:4], rhesus_lung_specific_75[,1:4])

Hypermethylated in first MR- 25% overlap

Note: due to pairwise ordering from above, tDMRs labeled as “hypermethylated” are actually hypomethylated in the lung and kidney.

# Heart specific 25% 

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])
## 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//RtmpDtLF2z/i_4f372b73d78f.bed -d 0 -c 4 -o collapse
##  * Collapsing 370 --> 368 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//RtmpDtLF2z/i_4f374e25883f.bed -d 0 -c 4 -o collapse
##  * Collapsing 250 --> 249 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//RtmpDtLF2z/i_4f3771250512.bed -d 0 -c 4 -o collapse
##  * Collapsing 202 --> 201 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//RtmpDtLF2z/a_4f377d2583c6.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371a6f724c.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//RtmpDtLF2z/a_4f371190772d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3711f7cec9.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//RtmpDtLF2z/a_4f37793ff804.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376855e297.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//RtmpDtLF2z/i_4f371623e21c.bed -d 0 -c 4 -o collapse
##  * Collapsing 42 --> 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//RtmpDtLF2z/i_4f373f53becf.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//RtmpDtLF2z/i_4f37106ffbe5.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//RtmpDtLF2z/a_4f372948f455.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372af52d5a.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//RtmpDtLF2z/a_4f3770176fd6.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3749ae0126.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//RtmpDtLF2z/a_4f37271abc57.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377bf14407.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//RtmpDtLF2z/a_4f3747df2b42.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373fb88581.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//RtmpDtLF2z/a_4f377c78aa54.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3734d1ed8c.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
## [1,]            317            197             178 38  9 10             4
#     human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
#[1,]            317            197             178 38  9 10             4


# Kidney specific 25% 

human_heart_specific_25_hypo <- human_kidney_specific_25[which(human_kidney_specific_25[,4] == "hyper"),]

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

rhesus_heart_specific_25_hypo <- rhesus_kidney_specific_25[which(rhesus_kidney_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])
## 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//RtmpDtLF2z/i_4f37236cfdc9.bed -d 0 -c 4 -o collapse
##  * Collapsing 3739 --> 3732 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//RtmpDtLF2z/i_4f3745c95e7a.bed -d 0 -c 4 -o collapse
##  * Collapsing 2129 --> 2127 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//RtmpDtLF2z/i_4f3775238d75.bed -d 0 -c 4 -o collapse
##  * Collapsing 3247 --> 3240 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//RtmpDtLF2z/a_4f375534548.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37a0323c.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//RtmpDtLF2z/a_4f3712e7f069.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3725796a71.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//RtmpDtLF2z/a_4f376a86fbce.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37e59f34f.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//RtmpDtLF2z/i_4f3739bb36c7.bed -d 0 -c 4 -o collapse
##  * Collapsing 858 --> 855 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//RtmpDtLF2z/i_4f37599adc5.bed -d 0 -c 4 -o collapse
##  * Collapsing 552 --> 550 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//RtmpDtLF2z/i_4f372a75cdb0.bed -d 0 -c 4 -o collapse
##  * Collapsing 413 --> 411 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//RtmpDtLF2z/a_4f374cf2e236.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37189c9c97.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//RtmpDtLF2z/a_4f37387ff694.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374ca07fa1.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//RtmpDtLF2z/a_4f371fc9b022.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3734a00632.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//RtmpDtLF2z/a_4f37755060e0.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37afd3dde.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//RtmpDtLF2z/a_4f37783a4c79.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377a235d9f.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific  hc  hr  cr
## [1,]           2598           1131            2549 584 279 141
##      hcr_conserved
## [1,]           271
#     human_specific chimp_specific rhesus_specific  hc  hr  cr hcr_conserved
#[1,]           2598           1131            2549 584 279 141           271


# Liver specific 25% 

human_heart_specific_25_hypo <- human_liver_specific_25[which(human_liver_specific_25[,4] == "hyper"),]

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

rhesus_heart_specific_25_hypo <- rhesus_liver_specific_25[which(rhesus_liver_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])
## 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//RtmpDtLF2z/i_4f37417bffc1.bed -d 0 -c 4 -o collapse
##  * Collapsing 818 --> 816 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//RtmpDtLF2z/i_4f3721a09820.bed -d 0 -c 4 -o collapse
##  * Collapsing 1313 --> 1312 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//RtmpDtLF2z/i_4f3739d2d11e.bed -d 0 -c 4 -o collapse
##  * Collapsing 2590 --> 2587 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//RtmpDtLF2z/a_4f37105680c1.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376e2421e5.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//RtmpDtLF2z/a_4f371152bced.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3740934a45.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//RtmpDtLF2z/a_4f375ade71f8.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373812756e.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//RtmpDtLF2z/i_4f3794f9fea.bed -d 0 -c 4 -o collapse
##  * Collapsing 252 --> 252 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//RtmpDtLF2z/i_4f371d0618b0.bed -d 0 -c 4 -o collapse
##  * Collapsing 198 --> 197 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//RtmpDtLF2z/i_4f375b467454.bed -d 0 -c 4 -o collapse
##  * Collapsing 274 --> 274 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//RtmpDtLF2z/a_4f3721e4dc6f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374c0eb662.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//RtmpDtLF2z/a_4f3734889d99.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371c13b26.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//RtmpDtLF2z/a_4f375a061c33.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37769aeeae.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//RtmpDtLF2z/a_4f3759b19e2b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375256e222.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//RtmpDtLF2z/a_4f375019d7d3.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37674508d6.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific  hc  hr  cr
## [1,]            457            876            2206 162 107 184
##      hcr_conserved
## [1,]            90
#     human_specific chimp_specific rhesus_specific  hc  hr  cr hcr_conserved
#[1,]            457            876            2206 162 107 184            90


# Lung specific 25% 

human_heart_specific_25_hypo <- human_lung_specific_25[which(human_lung_specific_25[,4] == "hyper"),]

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

rhesus_heart_specific_25_hypo <- rhesus_lung_specific_25[which(rhesus_lung_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])
## 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//RtmpDtLF2z/i_4f372c774589.bed -d 0 -c 4 -o collapse
##  * Collapsing 316 --> 315 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//RtmpDtLF2z/i_4f371868d48c.bed -d 0 -c 4 -o collapse
##  * Collapsing 324 --> 324 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//RtmpDtLF2z/i_4f372b15c4de.bed -d 0 -c 4 -o collapse
##  * Collapsing 432 --> 431 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//RtmpDtLF2z/a_4f3740f92f22.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372149eb2a.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//RtmpDtLF2z/a_4f3755d5c39b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371647709e.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//RtmpDtLF2z/a_4f3734002a9d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372e4b5980.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//RtmpDtLF2z/i_4f377e4d27fa.bed -d 0 -c 4 -o collapse
##  * Collapsing 30 --> 30 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//RtmpDtLF2z/i_4f377d4a4e80.bed -d 0 -c 4 -o collapse
##  * Collapsing 15 --> 15 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//RtmpDtLF2z/i_4f377837e23c.bed -d 0 -c 4 -o collapse
##  * Collapsing 23 --> 22 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//RtmpDtLF2z/a_4f3771980c6.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377a0a8076.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//RtmpDtLF2z/a_4f3771c72c2f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374f15ad60.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//RtmpDtLF2z/a_4f37453e3431.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3760242d1d.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//RtmpDtLF2z/a_4f373559d0f7.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373a69008c.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//RtmpDtLF2z/a_4f371f961814.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376c91be40.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
## [1,]            275            277             399 25 10 17             5
#     human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
#[1,]            276            277             400 25 10 17             5

Hypomethylated in first MR- 25% overlap

Note: due to pairwise ordering from above, tDMRs labeled as “hypomethylated” are actually hypermethylated in the lung and kidney.

# Heart specific 25% 

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])
## 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//RtmpDtLF2z/i_4f3745265dea.bed -d 0 -c 4 -o collapse
##  * Collapsing 2599 --> 2596 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//RtmpDtLF2z/i_4f377519f503.bed -d 0 -c 4 -o collapse
##  * Collapsing 1493 --> 1492 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//RtmpDtLF2z/i_4f372edb91c5.bed -d 0 -c 4 -o collapse
##  * Collapsing 1395 --> 1393 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//RtmpDtLF2z/a_4f377549d681.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37168c2e2d.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//RtmpDtLF2z/a_4f373f0ddda3.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372d4445e.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//RtmpDtLF2z/a_4f3725325e40.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375ae00b2d.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//RtmpDtLF2z/i_4f37304d12e.bed -d 0 -c 4 -o collapse
##  * Collapsing 413 --> 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//RtmpDtLF2z/i_4f372bc6ffe5.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//RtmpDtLF2z/i_4f37b80ed6e.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//RtmpDtLF2z/a_4f3762225e2c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376201fb94.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//RtmpDtLF2z/a_4f3798fd052.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376cb64244.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//RtmpDtLF2z/a_4f374bc48cb7.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3738375dfa.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//RtmpDtLF2z/a_4f377242d277.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3729736e8d.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//RtmpDtLF2z/a_4f37373c7f70.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373ab3e899.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific  hc hr cr hcr_conserved
## [1,]           2091           1013            1173 351 92 66            62
#     human_specific chimp_specific rhesus_specific  hc hr cr hcr_conserved
#[1,]           2091           1013            1173 351 92 66            62


# Kidney specific 25% 

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

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

rhesus_heart_specific_25_hypo <- rhesus_kidney_specific_25[which(rhesus_kidney_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])
## 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//RtmpDtLF2z/i_4f37daf5eed.bed -d 0 -c 4 -o collapse
##  * Collapsing 228 --> 225 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//RtmpDtLF2z/i_4f374984e27a.bed -d 0 -c 4 -o collapse
##  * Collapsing 173 --> 173 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//RtmpDtLF2z/i_4f374d10812e.bed -d 0 -c 4 -o collapse
##  * Collapsing 308 --> 307 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//RtmpDtLF2z/a_4f373be55e8a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3762d9d4b0.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//RtmpDtLF2z/a_4f377a0cc19e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37b10fb32.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//RtmpDtLF2z/a_4f3723452300.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3778c521b8.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//RtmpDtLF2z/i_4f371aeb33a0.bed -d 0 -c 4 -o collapse
##  * Collapsing 39 --> 39 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//RtmpDtLF2z/i_4f374c684db3.bed -d 0 -c 4 -o collapse
##  * Collapsing 37 --> 37 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//RtmpDtLF2z/i_4f373d7a9eca.bed -d 0 -c 4 -o collapse
##  * Collapsing 23 --> 23 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//RtmpDtLF2z/a_4f37707a80a5.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3751362f60.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//RtmpDtLF2z/a_4f3759bfd50a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3744b4f6b6.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//RtmpDtLF2z/a_4f37232bb8cf.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376c6fe13.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//RtmpDtLF2z/a_4f3736161a4f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3749c09155.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//RtmpDtLF2z/a_4f37615d8ef4.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375e57ff48.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
## [1,]            165            127             263 23 21  7            16
#     human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
#[1,]            165            127             263 23 21  7            16


# Liver specific 25% 

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

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

rhesus_heart_specific_25_hypo <- rhesus_liver_specific_25[which(rhesus_liver_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])
## 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//RtmpDtLF2z/i_4f3733468941.bed -d 0 -c 4 -o collapse
##  * Collapsing 2475 --> 2462 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//RtmpDtLF2z/i_4f37139492e3.bed -d 0 -c 4 -o collapse
##  * Collapsing 5064 --> 5049 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//RtmpDtLF2z/i_4f37147b0d79.bed -d 0 -c 4 -o collapse
##  * Collapsing 8880 --> 8846 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//RtmpDtLF2z/a_4f371a546541.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375aed9440.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//RtmpDtLF2z/a_4f37717253e3.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37674328fb.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//RtmpDtLF2z/a_4f3760e9ecf5.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375ddbfab4.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//RtmpDtLF2z/i_4f3711b461ca.bed -d 0 -c 4 -o collapse
##  * Collapsing 1081 --> 1074 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//RtmpDtLF2z/i_4f376a28011d.bed -d 0 -c 4 -o collapse
##  * Collapsing 683 --> 674 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//RtmpDtLF2z/i_4f374c1e4a34.bed -d 0 -c 4 -o collapse
##  * Collapsing 1062 --> 1041 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//RtmpDtLF2z/a_4f372437c7d3.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3740bcf461.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//RtmpDtLF2z/a_4f37169def13.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37602c52bf.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//RtmpDtLF2z/a_4f375c5eb733.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374aa023c7.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//RtmpDtLF2z/a_4f37456c383d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375694705a.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//RtmpDtLF2z/a_4f37711145b0.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3718b585d5.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific  hc  hr  cr
## [1,]           1100           3315            7512 687 287 659
##      hcr_conserved
## [1,]           388
#     human_specific chimp_specific rhesus_specific  hc  hr  cr hcr_conserved
#[1,]           1100           3315            7512 687 287 659           388

# Lung specific 25% 

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

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

rhesus_heart_specific_25_hypo <- rhesus_lung_specific_25[which(rhesus_lung_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])

Hypomethylated in first MR- 50% overlap

# Heart specific 50% 

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

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

rhesus_heart_specific_25_hypo <- rhesus_heart_specific_50[which(rhesus_heart_specific_50[,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])
## 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//RtmpDtLF2z/i_4f375b826d0.bed -d 0 -c 4 -o collapse
##  * Collapsing 1913 --> 1913 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//RtmpDtLF2z/i_4f37dc8412d.bed -d 0 -c 4 -o collapse
##  * Collapsing 1070 --> 1070 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//RtmpDtLF2z/i_4f3725b7a6a8.bed -d 0 -c 4 -o collapse
##  * Collapsing 1033 --> 1033 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//RtmpDtLF2z/a_4f371b3d00e5.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372b9774c8.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//RtmpDtLF2z/a_4f3751c08284.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372e010367.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//RtmpDtLF2z/a_4f375e88dc6e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37302d0de4.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//RtmpDtLF2z/i_4f37727dfee2.bed -d 0 -c 4 -o collapse
##  * Collapsing 282 --> 282 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//RtmpDtLF2z/i_4f37145785fd.bed -d 0 -c 4 -o collapse
##  * Collapsing 110 --> 110 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//RtmpDtLF2z/i_4f374eeb719e.bed -d 0 -c 4 -o collapse
##  * Collapsing 94 --> 94 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//RtmpDtLF2z/a_4f37497d4b53.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3729ad0a38.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//RtmpDtLF2z/a_4f37410dece.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375053c154.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//RtmpDtLF2z/a_4f374ca1656a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375d9f3123.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//RtmpDtLF2z/a_4f3757b6e78a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3743880793.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//RtmpDtLF2z/a_4f3760811cf5.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3768f4784d.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific  hc hr cr hcr_conserved
## [1,]           1566            739             874 237 65 49            45
#     human_specific chimp_specific rhesus_specific  hc hr cr hcr_conserved
#[1,]           1566            739             874 237 65 49            45

# Kidney specific 50% 

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

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

rhesus_heart_specific_25_hypo <- rhesus_kidney_specific_50[which(rhesus_kidney_specific_50[,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])
## 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//RtmpDtLF2z/i_4f371f92ea94.bed -d 0 -c 4 -o collapse
##  * Collapsing 155 --> 155 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//RtmpDtLF2z/i_4f375e5392d0.bed -d 0 -c 4 -o collapse
##  * Collapsing 107 --> 107 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//RtmpDtLF2z/i_4f37238a753.bed -d 0 -c 4 -o collapse
##  * Collapsing 198 --> 198 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//RtmpDtLF2z/a_4f37307446d8.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377b2de9e5.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//RtmpDtLF2z/a_4f3732d75084.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37776260c3.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//RtmpDtLF2z/a_4f37710121ba.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373df7902d.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//RtmpDtLF2z/i_4f374a7d94d0.bed -d 0 -c 4 -o collapse
##  * Collapsing 29 --> 29 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//RtmpDtLF2z/i_4f3739c96ac.bed -d 0 -c 4 -o collapse
##  * Collapsing 25 --> 25 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//RtmpDtLF2z/i_4f3714ce6e37.bed -d 0 -c 4 -o collapse
##  * Collapsing 13 --> 13 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//RtmpDtLF2z/a_4f374e120e82.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3728f93651.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//RtmpDtLF2z/a_4f377e9a2b05.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3765d21ee0.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//RtmpDtLF2z/a_4f375aea5eef.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3749fe49a3.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//RtmpDtLF2z/a_4f37d73d3de.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377763ebd7.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//RtmpDtLF2z/a_4f37670ea034.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37213964f.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
## [1,]            112             76             171 18 14  2            11
#     human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
#[1,]            112             76             171 18 14  2            11

# Liver specific 50% 

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

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

rhesus_heart_specific_25_hypo <- rhesus_liver_specific_50[which(rhesus_liver_specific_50[,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])
## 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//RtmpDtLF2z/i_4f377ace52dc.bed -d 0 -c 4 -o collapse
##  * Collapsing 1945 --> 1945 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//RtmpDtLF2z/i_4f376f112cf6.bed -d 0 -c 4 -o collapse
##  * Collapsing 4081 --> 4081 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//RtmpDtLF2z/i_4f37779b1910.bed -d 0 -c 4 -o collapse
##  * Collapsing 7569 --> 7569 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//RtmpDtLF2z/a_4f375c1ef29d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37751389af.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//RtmpDtLF2z/a_4f3742a0f0a2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37123f21dd.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//RtmpDtLF2z/a_4f37508b8a1.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377f557035.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//RtmpDtLF2z/i_4f3767e86f65.bed -d 0 -c 4 -o collapse
##  * Collapsing 810 --> 807 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//RtmpDtLF2z/i_4f377726b674.bed -d 0 -c 4 -o collapse
##  * Collapsing 557 --> 549 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//RtmpDtLF2z/i_4f37456c4d99.bed -d 0 -c 4 -o collapse
##  * Collapsing 865 --> 850 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//RtmpDtLF2z/a_4f3729c46b7a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37137a523e.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//RtmpDtLF2z/a_4f374afb0f6b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371b50d974.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//RtmpDtLF2z/a_4f373218e5.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377f09d0ab.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//RtmpDtLF2z/a_4f3771bf6d08.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374f2f96d6.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//RtmpDtLF2z/a_4f37677df57e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3765fab9c2.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific  hc  hr  cr
## [1,]            902           2734            6480 494 236 540
##      hcr_conserved
## [1,]           313
#     human_specific chimp_specific rhesus_specific  hc  hr  cr hcr_conserved
#[1,]            902           2734            6480 494 236 540           313


# Lung specific 50% 

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

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

rhesus_heart_specific_25_hypo <- rhesus_lung_specific_50[which(rhesus_lung_specific_50[,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])

Hypermethylated in first MR- 50% overlap

# Heart specific 50% 

human_heart_specific_25_hypo <- human_heart_specific_50[which(human_heart_specific_50[,4] == "hyper"),]

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

rhesus_heart_specific_25_hypo <- rhesus_heart_specific_50[which(rhesus_heart_specific_50[,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])
## 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//RtmpDtLF2z/i_4f373d122eef.bed -d 0 -c 4 -o collapse
##  * Collapsing 220 --> 220 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//RtmpDtLF2z/i_4f375092d162.bed -d 0 -c 4 -o collapse
##  * Collapsing 147 --> 147 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//RtmpDtLF2z/i_4f37502c85fe.bed -d 0 -c 4 -o collapse
##  * Collapsing 115 --> 115 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//RtmpDtLF2z/a_4f3724eaacb8.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37a6502df.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//RtmpDtLF2z/a_4f3762d0efa1.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371adccb59.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//RtmpDtLF2z/a_4f376eb34ee4.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377a06447.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//RtmpDtLF2z/i_4f3749114d0a.bed -d 0 -c 4 -o collapse
##  * Collapsing 18 --> 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//RtmpDtLF2z/i_4f3744b63e9d.bed -d 0 -c 4 -o collapse
##  * Collapsing 9 --> 9 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//RtmpDtLF2z/i_4f372a084bf5.bed -d 0 -c 4 -o collapse
##  * Collapsing 9 --> 9 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//RtmpDtLF2z/a_4f377ff68843.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3741c0a41.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//RtmpDtLF2z/a_4f37a3a4a6d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37710fb75c.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//RtmpDtLF2z/a_4f374db643a6.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372b5515f8.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//RtmpDtLF2z/a_4f373ae83ddb.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377c7b489b.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//RtmpDtLF2z/a_4f373e24c632.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377f085985.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
## [1,]            196            123             100 15  6  6             3
#     human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
#[1,]            196            123             100 15  6  6             3

# Kidney specific 50% 

human_heart_specific_25_hypo <- human_kidney_specific_50[which(human_kidney_specific_50[,4] == "hyper"),]

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

rhesus_heart_specific_25_hypo <- rhesus_kidney_specific_50[which(rhesus_kidney_specific_50[,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])
## 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//RtmpDtLF2z/i_4f3731080fda.bed -d 0 -c 4 -o collapse
##  * Collapsing 2862 --> 2862 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//RtmpDtLF2z/i_4f3762dd6243.bed -d 0 -c 4 -o collapse
##  * Collapsing 1622 --> 1622 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//RtmpDtLF2z/i_4f371bafd302.bed -d 0 -c 4 -o collapse
##  * Collapsing 2475 --> 2475 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//RtmpDtLF2z/a_4f374528cdb6.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37b287f49.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//RtmpDtLF2z/a_4f371076534f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372e2f0fd8.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//RtmpDtLF2z/a_4f373ad71fa0.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37316f155c.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//RtmpDtLF2z/i_4f3755d292c2.bed -d 0 -c 4 -o collapse
##  * Collapsing 624 --> 621 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//RtmpDtLF2z/i_4f3759f2128c.bed -d 0 -c 4 -o collapse
##  * Collapsing 412 --> 411 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//RtmpDtLF2z/i_4f3751f3fa3f.bed -d 0 -c 4 -o collapse
##  * Collapsing 296 --> 295 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//RtmpDtLF2z/a_4f3724e70891.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371d20e979.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//RtmpDtLF2z/a_4f372944af0f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373be32ef.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//RtmpDtLF2z/a_4f3721ec5c5.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373a631f2c.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//RtmpDtLF2z/a_4f37b891c3c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371dcca1a3.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//RtmpDtLF2z/a_4f37117c332.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372ddb713a.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific  hc  hr  cr
## [1,]           2020            896            1959 431 221 105
##      hcr_conserved
## [1,]           190
#     human_specific chimp_specific rhesus_specific  hc  hr  cr hcr_conserved
#[1,]           2020            896            1959 431 221 105           190

# Liver specific 50% 

human_heart_specific_25_hypo <- human_liver_specific_50[which(human_liver_specific_50[,4] == "hyper"),]

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

rhesus_heart_specific_25_hypo <- rhesus_liver_specific_50[which(rhesus_liver_specific_50[,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])
## 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//RtmpDtLF2z/i_4f372fc0e9c0.bed -d 0 -c 4 -o collapse
##  * Collapsing 552 --> 552 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//RtmpDtLF2z/i_4f371659977c.bed -d 0 -c 4 -o collapse
##  * Collapsing 878 --> 878 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//RtmpDtLF2z/i_4f373b424ebf.bed -d 0 -c 4 -o collapse
##  * Collapsing 1980 --> 1980 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//RtmpDtLF2z/a_4f375f6cd7c8.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37c4fd8d7.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//RtmpDtLF2z/a_4f37405dcfa8.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3738c49e30.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//RtmpDtLF2z/a_4f3778274316.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3749de8259.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//RtmpDtLF2z/i_4f3741e521a.bed -d 0 -c 4 -o collapse
##  * Collapsing 150 --> 150 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//RtmpDtLF2z/i_4f3716bdd54.bed -d 0 -c 4 -o collapse
##  * Collapsing 140 --> 140 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//RtmpDtLF2z/i_4f37b1840bc.bed -d 0 -c 4 -o collapse
##  * Collapsing 218 --> 218 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//RtmpDtLF2z/a_4f371d34b91.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3768e89122.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//RtmpDtLF2z/a_4f377d38d4d5.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37370cd486.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//RtmpDtLF2z/a_4f371e0ccba9.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371e31e5df.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//RtmpDtLF2z/a_4f3727f76e8b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3762920473.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//RtmpDtLF2z/a_4f374172feaf.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371e24a024.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific hc hr  cr hcr_conserved
## [1,]            327            575            1687 85 75 153            65
#     human_specific chimp_specific rhesus_specific hc hr  cr hcr_conserved
#[1,]            327            575            1687 85 75 153            65


# Lung specific 50% 

human_heart_specific_25_hypo <- human_lung_specific_50[which(human_lung_specific_50[,4] == "hyper"),]

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

rhesus_heart_specific_25_hypo <- rhesus_lung_specific_50[which(rhesus_lung_specific_50[,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])
## 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//RtmpDtLF2z/i_4f374ed1f105.bed -d 0 -c 4 -o collapse
##  * Collapsing 186 --> 186 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//RtmpDtLF2z/i_4f3718cb3120.bed -d 0 -c 4 -o collapse
##  * Collapsing 221 --> 221 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//RtmpDtLF2z/i_4f37746d6464.bed -d 0 -c 4 -o collapse
##  * Collapsing 276 --> 276 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//RtmpDtLF2z/a_4f374ba265ad.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37c9c037.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//RtmpDtLF2z/a_4f3740125449.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3770c32dd1.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//RtmpDtLF2z/a_4f372dd573d7.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3755168130.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//RtmpDtLF2z/i_4f373cc5b724.bed -d 0 -c 4 -o collapse
##  * Collapsing 19 --> 19 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//RtmpDtLF2z/i_4f3761b5fe52.bed -d 0 -c 4 -o collapse
##  * Collapsing 6 --> 6 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//RtmpDtLF2z/i_4f377d59483f.bed -d 0 -c 4 -o collapse
##  * Collapsing 16 --> 16 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//RtmpDtLF2z/a_4f3760f86680.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3726325575.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//RtmpDtLF2z/a_4f3745949bcf.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3793373bf.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//RtmpDtLF2z/a_4f3742de3bb2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371d40d2ad.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//RtmpDtLF2z/a_4f37694468d4.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377081a847.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//RtmpDtLF2z/a_4f373abb07b0.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371ce450a8.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
## [1,]            163            188             256 17  4 14             2
#     human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
#[1,]            163            188             256 17  4 14             2

Hypomethylated in first MR- 75% overlap

# Heart specific 75% 

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

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

rhesus_heart_specific_25_hypo <- rhesus_heart_specific_75[which(rhesus_heart_specific_75[,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])
## 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//RtmpDtLF2z/i_4f3721a5f055.bed -d 0 -c 4 -o collapse
##  * Collapsing 917 --> 917 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//RtmpDtLF2z/i_4f3712590fc.bed -d 0 -c 4 -o collapse
##  * Collapsing 501 --> 501 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//RtmpDtLF2z/i_4f37a0532b1.bed -d 0 -c 4 -o collapse
##  * Collapsing 513 --> 513 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//RtmpDtLF2z/a_4f3720902b04.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374f9200bd.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//RtmpDtLF2z/a_4f372e7c4af3.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37408bb8aa.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//RtmpDtLF2z/a_4f378cd2985.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3762870e14.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//RtmpDtLF2z/i_4f376c0291c0.bed -d 0 -c 4 -o collapse
##  * Collapsing 80 --> 80 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//RtmpDtLF2z/i_4f372825ce00.bed -d 0 -c 4 -o collapse
##  * Collapsing 33 --> 33 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//RtmpDtLF2z/i_4f37158ad971.bed -d 0 -c 4 -o collapse
##  * Collapsing 28 --> 28 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//RtmpDtLF2z/a_4f376cd84977.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37b01a12d.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//RtmpDtLF2z/a_4f37c27df38.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3731fd2f4d.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//RtmpDtLF2z/a_4f3751357339.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373ad495d0.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//RtmpDtLF2z/a_4f3776fe990b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374d69d1ca.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//RtmpDtLF2z/a_4f37298aff65.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372b0134fb.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
## [1,]            813            402             461 71 24 19             9
#     human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
#[1,]            813            402             461 71 24 19             9

# Kidney specific 75% 

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

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

rhesus_heart_specific_25_hypo <- rhesus_kidney_specific_75[which(rhesus_kidney_specific_75[,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])
## 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//RtmpDtLF2z/i_4f37419ddebc.bed -d 0 -c 4 -o collapse
##  * Collapsing 67 --> 67 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//RtmpDtLF2z/i_4f373ded4fb.bed -d 0 -c 4 -o collapse
##  * Collapsing 48 --> 48 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//RtmpDtLF2z/i_4f375b5bb33e.bed -d 0 -c 4 -o collapse
##  * Collapsing 89 --> 89 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//RtmpDtLF2z/a_4f3733827675.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375bbc819.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//RtmpDtLF2z/a_4f3774d17979.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3750f0ffe7.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//RtmpDtLF2z/a_4f3753820497.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374b55b017.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//RtmpDtLF2z/i_4f372b2c79d.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//RtmpDtLF2z/i_4f37392059e4.bed -d 0 -c 4 -o collapse
##  * Collapsing 10 --> 10 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//RtmpDtLF2z/i_4f377edef45.bed -d 0 -c 4 -o collapse
##  * Collapsing 7 --> 7 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//RtmpDtLF2z/a_4f375c301d2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3778fe28f3.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//RtmpDtLF2z/a_4f3714153773.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37199eff85.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//RtmpDtLF2z/a_4f3726e2f74b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377889090b.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//RtmpDtLF2z/a_4f37302ccbcb.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f376168dd04.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//RtmpDtLF2z/a_4f374dd8759d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37198e3ae2.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
## [1,]             50             34              78  7  4  1             6
#     human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
#[1,]             50             34              78  7  4  1             6


# Liver specific 75% 

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

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

rhesus_heart_specific_25_hypo <- rhesus_liver_specific_75[which(rhesus_liver_specific_75[,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])
## 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//RtmpDtLF2z/i_4f3724852fad.bed -d 0 -c 4 -o collapse
##  * Collapsing 1088 --> 1088 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//RtmpDtLF2z/i_4f373d9ad94f.bed -d 0 -c 4 -o collapse
##  * Collapsing 2472 --> 2472 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//RtmpDtLF2z/i_4f373426efca.bed -d 0 -c 4 -o collapse
##  * Collapsing 5018 --> 5018 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//RtmpDtLF2z/a_4f372eeb0429.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3728c4a93b.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//RtmpDtLF2z/a_4f3768621626.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37460fa803.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//RtmpDtLF2z/a_4f37573cb58b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3764b6fd94.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//RtmpDtLF2z/i_4f37cafb057.bed -d 0 -c 4 -o collapse
##  * Collapsing 349 --> 347 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//RtmpDtLF2z/i_4f3719bde984.bed -d 0 -c 4 -o collapse
##  * Collapsing 249 --> 248 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//RtmpDtLF2z/i_4f373a6b8fd1.bed -d 0 -c 4 -o collapse
##  * Collapsing 395 --> 388 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//RtmpDtLF2z/a_4f372458d4b1.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37430fda3.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//RtmpDtLF2z/a_4f376aa04518.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3744ffe649.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//RtmpDtLF2z/a_4f371df52fa0.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3742d7bf56.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//RtmpDtLF2z/a_4f37566ab21d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3764237d67.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//RtmpDtLF2z/a_4f374aa1d053.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373edaceb9.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific  hc  hr  cr
## [1,]            605           1848            4493 235 136 277
##      hcr_conserved
## [1,]           112
#     human_specific chimp_specific rhesus_specific  hc  hr  cr hcr_conserved
# [1,]            605           1848            4493 235 136 277           112


# Lung specific 75% 

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

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

#rhesus_heart_specific_25_hypo <- rhesus_lung_specific_75[which(rhesus_lung_specific_75[,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])

Hypermethylated in first MR- 75% overlap

# Heart specific 75% 

human_heart_specific_25_hypo <- human_heart_specific_75[which(human_heart_specific_75[,4] == "hyper"),]

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

rhesus_heart_specific_25_hypo <- rhesus_heart_specific_75[which(rhesus_heart_specific_75[,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])
## 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//RtmpDtLF2z/i_4f37201ad390.bed -d 0 -c 4 -o collapse
##  * Collapsing 76 --> 76 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//RtmpDtLF2z/i_4f372bc8e0a4.bed -d 0 -c 4 -o collapse
##  * Collapsing 55 --> 55 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//RtmpDtLF2z/i_4f3749db0679.bed -d 0 -c 4 -o collapse
##  * Collapsing 46 --> 46 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//RtmpDtLF2z/a_4f377b4f084a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3729a1f673.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//RtmpDtLF2z/a_4f377896218.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3756362081.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//RtmpDtLF2z/a_4f374f138787.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3763ddb3c8.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//RtmpDtLF2z/i_4f3714c46a66.bed -d 0 -c 4 -o collapse
##  * Collapsing 3 --> 3 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//RtmpDtLF2z/i_4f3761029544.bed -d 0 -c 4 -o collapse
##  * Collapsing 2 --> 2 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//RtmpDtLF2z/i_4f377cda9ca9.bed -d 0 -c 4 -o collapse
##  * Collapsing 3 --> 3 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//RtmpDtLF2z/a_4f3771b675e5.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37777ecff3.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//RtmpDtLF2z/a_4f371f351d9c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3766038785.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//RtmpDtLF2z/a_4f376533442e.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3739d5e15.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//RtmpDtLF2z/a_4f376f59123a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375658008a.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//RtmpDtLF2z/a_4f3734d913cb.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371359cfa3.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
## [1,]             72             50              42  2  1  2             1
#     human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
#[1,]             72             50              42  2  1  2             1

# Kidney specific 75% 

human_heart_specific_25_hypo <- human_kidney_specific_75[which(human_kidney_specific_75[,4] == "hyper"),]

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

rhesus_heart_specific_25_hypo <- rhesus_kidney_specific_75[which(rhesus_kidney_specific_75[,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])
## 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//RtmpDtLF2z/i_4f3755650377.bed -d 0 -c 4 -o collapse
##  * Collapsing 1464 --> 1464 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//RtmpDtLF2z/i_4f372796c5aa.bed -d 0 -c 4 -o collapse
##  * Collapsing 806 --> 806 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//RtmpDtLF2z/i_4f374f09b40c.bed -d 0 -c 4 -o collapse
##  * Collapsing 1308 --> 1308 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//RtmpDtLF2z/a_4f37747e5fcf.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371c7d3c4f.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//RtmpDtLF2z/a_4f371cad01b7.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f377b494f79.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//RtmpDtLF2z/a_4f374f308e77.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3772c7c413.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//RtmpDtLF2z/i_4f377776f73b.bed -d 0 -c 4 -o collapse
##  * Collapsing 228 --> 226 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//RtmpDtLF2z/i_4f37560aed5a.bed -d 0 -c 4 -o collapse
##  * Collapsing 143 --> 143 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//RtmpDtLF2z/i_4f37e9d3549.bed -d 0 -c 4 -o collapse
##  * Collapsing 93 --> 92 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//RtmpDtLF2z/a_4f375491756.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3791af709.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//RtmpDtLF2z/a_4f375425bcc0.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375ba30be5.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//RtmpDtLF2z/a_4f375f23b8e2.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3756f0dfc7.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//RtmpDtLF2z/a_4f376179cd4b.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f372071a250.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//RtmpDtLF2z/a_4f3779141dd1.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3731f986c9.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific  hc hr cr hcr_conserved
## [1,]           1147            540            1125 174 91 40            52
#     human_specific chimp_specific rhesus_specific  hc hr cr hcr_conserved
#[1,]           1147            540            1125 174 91 40            52

# Liver specific 75% 

human_heart_specific_25_hypo <- human_liver_specific_75[which(human_liver_specific_75[,4] == "hyper"),]

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

rhesus_heart_specific_25_hypo <- rhesus_liver_specific_75[which(rhesus_liver_specific_75[,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])
## 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//RtmpDtLF2z/i_4f37570a4242.bed -d 0 -c 4 -o collapse
##  * Collapsing 235 --> 235 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//RtmpDtLF2z/i_4f37524a49a5.bed -d 0 -c 4 -o collapse
##  * Collapsing 379 --> 379 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//RtmpDtLF2z/i_4f37375fb9a1.bed -d 0 -c 4 -o collapse
##  * Collapsing 931 --> 931 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//RtmpDtLF2z/a_4f377ccac653.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3748c20785.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//RtmpDtLF2z/a_4f3792a908.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f375b097901.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//RtmpDtLF2z/a_4f372cd4fb14.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f373666554c.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//RtmpDtLF2z/i_4f377a595b58.bed -d 0 -c 4 -o collapse
##  * Collapsing 43 --> 43 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//RtmpDtLF2z/i_4f375878defe.bed -d 0 -c 4 -o collapse
##  * Collapsing 43 --> 43 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//RtmpDtLF2z/i_4f3746a7d0.bed -d 0 -c 4 -o collapse
##  * Collapsing 53 --> 53 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//RtmpDtLF2z/a_4f372a89628f.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f371109b2fe.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//RtmpDtLF2z/a_4f3735ed1a6c.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37faf2b2b.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//RtmpDtLF2z/a_4f374135d71.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37260d800e.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//RtmpDtLF2z/a_4f373a3dae98.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f374a40f49f.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//RtmpDtLF2z/a_4f374b2e7361.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3730ab1b1.bed -wao -f 0.25 -F 0.25
##      human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
## [1,]            163            297             849 29 29 39            14
#     human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
#[1,]            163            297             849 29 29 39            14

# Lung specific 75% 

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

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

#rhesus_heart_specific_25_hypo <- rhesus_lung_specific_75[which(rhesus_lung_specific_75[,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])

Generating lung specific tDMRs that didn’t come up above

Lungs- 75% overlap

# Lungs- 75% overlap

DMR1_human <- bedr.merge.region(human_lung_specific_75[,1:4])
## 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//RtmpDtLF2z/i_4f372b46edb3.bed -d 0 -c 4 -o collapse
##  * Collapsing 84 --> 84 regions... NOTE
DMR1_chimp <- bedr.merge.region(chimp_lung_specific_75[,1:4])
## 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//RtmpDtLF2z/i_4f3738f39fbc.bed -d 0 -c 4 -o collapse
##  * Collapsing 117 --> 117 regions... NOTE
DMR1_rhesus <- bedr.merge.region(rhesus_lung_specific_75[,1:4])
## 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//RtmpDtLF2z/i_4f371e2fbd7c.bed -d 0 -c 4 -o collapse
##  * Collapsing 153 --> 153 regions... NOTE
# Human-chimp/human-rhesus

human_chimp_DMR <- bedr(input = list(a = DMR1_human, b = DMR1_chimp), 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//RtmpDtLF2z/a_4f37343a0d3d.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37442bb028.bed -wao -f 0.75 -F 0.75
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.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//RtmpDtLF2z/a_4f37437dc88a.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f37600e45a.bed -wao -f 0.75 -F 0.75
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.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//RtmpDtLF2z/a_4f37310d50ef.bed -b /var/folders/rf/qrcw6ncj05z1pc_pq9xzw3540000gn/T//RtmpDtLF2z/b_4f3726938e91.bed -wao -f 0.75 -F 0.75
nrow(DMR1_human) # 83
## [1] 84
nrow(DMR1_chimp) # 116
## [1] 117
nrow(DMR1_rhesus) # 153
## [1] 153
nrow(human_chimp_DMR) #1
## [1] 1
nrow(chimp_rhesus_DMR)
## [1] 117
nrow(human_rhesus_DMR)
## [1] 0

Lungs- 25% overlap in hypermethylated regions

#human_lung_specific_25_hypo <- human_lung_specific_25[which(human_lung_specific_25[,4] == "hypo"),]

#chimp_lung_specific_25_hypo <- chimp_lung_specific_25[which(chimp_lung_specific_25[,4] == "hypo"),]

#rhesus_lung_specific_25_hypo <- rhesus_lung_specific_25[which(rhesus_lung_specific_25[,4] == "hypo"),]

#    DMR1_human <- bedr.merge.region(human_lung_specific_25_hypo)
#  DMR1_chimp <- bedr.merge.region(chimp_lung_specific_25_hypo)
#  DMR1_rhesus <- bedr.merge.region(rhesus_lung_specific_25_hypo)
  
# 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")

#combine

#     human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
#[1,]            134             99              82 21  3  3             5

Lungs- 50% overlap in hypomethylated regions

#human_lung_specific_25_hypo <- human_lung_specific_50[which(human_lung_specific_50[,4] == "hyper"),]

#chimp_lung_specific_25_hypo <- chimp_lung_specific_50[which(chimp_lung_specific_50[,4] == "hyper"),]

#rhesus_lung_specific_25_hypo <- rhesus_lung_specific_50[which(rhesus_lung_specific_50[,4] == "hyper"),]

#    DMR1_human <- bedr.merge.region(human_lung_specific_25_hypo)
#  DMR1_chimp <- bedr.merge.region(chimp_lung_specific_25_hypo)
#  DMR1_rhesus <- bedr.merge.region(rhesus_lung_specific_25_hypo)
  
# Human-chimp/human-rhesus

# human_chimp_DMR <- bedr(input = list(a = DMR1_human, b = DMR1_chimp), method = "intersect",  params = "-wao -f 0.5 -F 0.5", 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.5 -F 0.5", 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.5 -F 0.5", 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.5 -F 0.5", 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.5 -F 0.5", 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.5 -F 0.5", 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.5 -F 0.5", 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.5 -F 0.5", 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")

#combine

#     human_specific chimp_specific rhesus_specific hc hr cr hcr_conserved
#[1,]            168            198             263 13  3  8             2

Lungs- 50% overlap in hypomethylated regions

#human_lung_specific_25_hypo <- human_lung_specific_50[which(human_lung_specific_50[,4] == "hypo"),]

#chimp_lung_specific_25_hypo <- chimp_lung_specific_50[which(chimp_lung_specific_50[,4] == "hypo"),]

#rhesus_lung_specific_25_hypo <- rhesus_lung_specific_50[which(rhesus_lung_specific_50[,4] == "hypo"),]

#    DMR1_human <- bedr.merge.region(human_lung_specific_25_hypo)
#  DMR1_chimp <- bedr.merge.region(chimp_lung_specific_25_hypo)
#  DMR1_rhesus <- bedr.merge.region(rhesus_lung_specific_25_hypo)
  
# Human-chimp/human-rhesus

#human_chimp_DMR <- bedr(input = list(a = DMR1_human, b = DMR1_chimp), method = "intersect",  params = "-wao -f 0.5 -F 0.5", 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.5 -F 0.5", 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.5 -F 0.5", 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)

#nrow(DMR1_human) - nrow(human_chimp_DMR) #72
#nrow(DMR1_chimp) - nrow(human_chimp_DMR) #65
#nrow(DMR1_rhesus) #48
#nrow(human_chimp_DMR) #8
#nrow(human_rhesus_DMR) # 0
#nrow(chimp_rhesus_DMR) #0

Lungs- 75% overlap in hypomethylated regions

#human_lung_specific_25_hypo <- human_lung_specific_75[which(human_lung_specific_75[,4] == "hyper"),]

#chimp_lung_specific_25_hypo <- chimp_lung_specific_75[which(chimp_lung_specific_75[,4] == "hyper"),]

#rhesus_lung_specific_25_hypo <- rhesus_lung_specific_75[which(rhesus_lung_specific_75[,4] == "hyper"),]

#    DMR1_human <- bedr.merge.region(human_lung_specific_25_hypo)
#  DMR1_chimp <- bedr.merge.region(chimp_lung_specific_25_hypo)
#  DMR1_rhesus <- bedr.merge.region(rhesus_lung_specific_25_hypo)
  
# Human-chimp/human-rhesus

#human_chimp_DMR <- bedr(input = list(a = DMR1_human, b = DMR1_chimp), method = "intersect",  params = "-wao -f 0.75 -F 0.75", 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.75 -F 0.75", 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.75 -F 0.75", 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")


#nrow(DMR1_human) - nrow(human_chimp_DMR) #57
#nrow(DMR1_chimp) - nrow(human_chimp_DMR) #92
#nrow(DMR1_rhesus) #137
#nrow(human_chimp_DMR) #8
#nrow(human_rhesus_DMR) # 0
#nrow(chimp_rhesus_DMR) #0

Lungs- 75% overlap in hypomethylated regions

#human_lung_specific_25_hypo <- human_lung_specific_75[which(human_lung_specific_75[,4] == "hypo"),]

#chimp_lung_specific_25_hypo <- chimp_lung_specific_75[which(chimp_lung_specific_75[,4] == "hypo"),]

#rhesus_lung_specific_25_hypo <- rhesus_lung_specific_75[which(rhesus_lung_specific_75[,4] == "hypo"),]

#    DMR1_human <- bedr.merge.region(human_lung_specific_25_hypo)
#  DMR1_chimp <- bedr.merge.region(chimp_lung_specific_25_hypo)
#  DMR1_rhesus <- bedr.merge.region(rhesus_lung_specific_25_hypo)
  
# Human-chimp/human-rhesus

#human_chimp_DMR <- bedr(input = list(a = DMR1_human, b = DMR1_chimp), method = "intersect",  params = "-wao -f 0.75 -F 0.75", 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.75 -F 0.75", 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.75 -F 0.75", 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")


#nrow(DMR1_human) - nrow(human_chimp_DMR) #26
#nrow(DMR1_chimp) - nrow(human_chimp_DMR) #24
#nrow(DMR1_rhesus) #16
#nrow(human_chimp_DMR) #1
#nrow(human_rhesus_DMR) # 0
#nrow(chimp_rhesus_DMR) #0