if (check.binary("bedtools")) {
index <- get.example.regions();
a <- index[[1]];
b <- index[[2]];
a <- bedr(engine = "bedtools", input = list(i = a), method = "sort", params = "");
b <- bedr(engine = "bedtools", input = list(i = b), method = "sort", params = "");
# a simple example
test.region.similarity(a, b, n = 8)
# note you can set the cores available to parallelize
options(cores = 4);
system.time(test.region.similarity(a, b, n = 8));
# a real example comparing the distribution of mRNA vs ncRNA genes in RefSeq
# more core
options(cores = 8);
# load refgene
refgene <- query.ucsc("refGene")
refgene <- refgene[,c("chrom","txStart","txEnd","name","name2","strand")]
# only include canonical chr
chr <- paste0("chr", c(1:22,"X","Y"));
refgene <- refgene[refgene$chrom
# remove genes with multiple positions
duplicated.gene <- duplicated(refgene$name2) | duplicated(rev(refgene$name2));
refgene <- refgene[!duplicated.gene,];
# only select pr coding genes
refgene.nm <- refgene[grepl("^NM",refgene$name),];
# only select non protein coding rna genes
refgene.nr <- refgene[grepl("^NR",refgene$name),];
# sort and merge
refgene.nm <- snm(refgene.nm,check.chr = FALSE);
refgene.nr <- snm(refgene.nr,check.chr = FALSE);
test.region.similarity(refgene.nm, refgene.nr, mask.unmapped = TRUE );
option(core = 1)
}Run the code above in your browser using DataLab