# 
# Reads in *.tab files and prepares subtables with contacts over certain distances
# These are saved into *.Rdata files for further use by downstream R scripts
# Tables in text format are published to the output dir
# 
args = commandArgs(trailingOnly=TRUE)
print(args)

tab <- read.table(args[1], sep="\t", header=T, stringsAsFactors=F)
tab_tad <- tab[which((tab$chr1 == tab$chr2) & (tab$pos2-tab$pos1 > 5000) & (tab$pos2-tab$pos1 < 1000000)),]
tab_dist <- tab[which((tab$chr1 == tab$chr2) & (tab$pos2-tab$pos1 > 1000000) | (tab$chr1 != tab$chr2)),]

save(tab, file="tab.Rdata")
save(tab_tad, file="tab_tad.Rdata")
save(tab_dist, file="tab_dist.Rdata")

