In this example we investigate the ENCODE Chip-Seq narrow and broad data, extracted from the GMQL remote repository to automate all the steps needed to identify transcription factor (TF) high accumulation DNA zones using RGQML together with TFHAZ, another R/Bioconductor package . The knowledge of DNA regions in which transcription factors bind, in particular the HOT (High Occupancy Target) regions occupied by many different factors, is crucial to understand cancer genesis and develop new targeted therapies.

Load the RGMQL package and initialize the remote GMQL context of scalable data management engine, specifying remote_processing = TRUE, and, possibly, an authenticated login:

library(RGMQL)
## Caricamento del pacchetto richiesto: RGMQLlib
## GMQL successfully loaded
remote_url <- "http://www.gmql.eu/gmql-rest"
init_gmql(url = remote_url, remote_processing = TRUE) #, username = 'XXXX', password = 'XXXX')
## [1] "your Token is b0fbf303-4693-4091-9e12-7c4613c2fd66"

Download and extract the list of datasets in the curated remote repository and focus on those concerning ENCODE:

dataset_list <- show_datasets_list(remote_url)
list <- unlist(lapply(dataset_list[["datasets"]], function(x) x$name))
grep(pattern = 'ENCODE', x = list, value = TRUE)
##  [1] "GRCh38_ANNOTATION_GENCODE"     "GRCh38_ENCODE_BROAD_2019_01"  
##  [3] "GRCh38_ENCODE_BROAD_2019_07"   "GRCh38_ENCODE_BROAD_2020_01"  
##  [5] "GRCh38_ENCODE_BROAD_AUG_2017"  "GRCh38_ENCODE_BROAD_NOV_2017" 
##  [7] "GRCh38_ENCODE_NARROW_2019_01"  "GRCh38_ENCODE_NARROW_2019_07" 
##  [9] "GRCh38_ENCODE_NARROW_2020_01"  "GRCh38_ENCODE_NARROW_AUG_2017"
## [11] "GRCh38_ENCODE_NARROW_NOV_2017" "HG19_ANNOTATION_GENCODE"      
## [13] "HG19_ENCODE_BROAD_2019_01"     "HG19_ENCODE_BROAD_AUG_2017"   
## [15] "HG19_ENCODE_BROAD_NOV_2016"    "HG19_ENCODE_BROAD_NOV_2017"   
## [17] "HG19_ENCODE_NARROW_2019_01"    "HG19_ENCODE_NARROW_AUG_2017"  
## [19] "HG19_ENCODE_NARROW_NOV_2016"   "HG19_ENCODE_NARROW_NOV_2017"

Select ChIP-seq data from the ENCODE NARROW dataset AUG_2017, aligned to HG19:

Enc_Narrow <- read_gmql("public.HG19_ENCODE_NARROW_AUG_2017",
                           is_local = FALSE)
HM_TF_rep_narrow <- filter(Enc_Narrow, assay == "ChIP-seq" & assembly
                          == "hg19" & project == "ENCODE" & file_status ==                           "released" & biosample_term_name == "H1-hESC" &                            output_type == "optimal idr thresholded peaks")

Select ChIP-seq data from the latest ENCODE BROAD dataset AUG_2017, aligned to HG19 and:

Enc_Broad <- read_gmql("public.HG19_ENCODE_BROAD_AUG_2017",
                          is_local = FALSE)
HM_TF_rep_broad <- filter(Enc_Broad, assay == "ChIP-seq" & assembly ==
                          "hg19" & project == "ENCODE" & file_status == 
                          "released" & biosample_term_name == "H1-hESC" &                            output_type == "optimal idr thresholded peaks")

Take the union of the two previously generated datasets:

HM_TF_rep <- union(HM_TF_rep_broad, HM_TF_rep_narrow)

Filter out samples subjected to pharmacological treatment or with specific “audit” marker:

HM_TF_rep_good_0 <- filter(HM_TF_rep, !biosample_treatments == "*" & !
                            (audit_error == "extremely low read depth" |                               audit_error == "extremely low read
                            length") & !(audit_warning == "insufficient                                read depth") & !(audit_not_compliant ==   
                            "insufficient read depth" | audit_not_compliant                             =="insufficient replicate concordance" |                                   audit_not_compliant == "missing input
                            control" | audit_not_compliant == "severe                                  bottlenecking" | audit_not_compliant
                            == "unreplicated experiment"))

Filter out samples related to HM histone modifications:

TF_rep_good_0 <- filter(HM_TF_rep_good_0, !(experiment_target ==                                   "H2AFZhuman" | experiment_target == "H3F3A-human" |                         experiment_target == "H3K27ac-human" |                                     experiment_target == "H3K27me3-human" |                                    experiment_target == "H3K36me3-human" |                                    experiment_target == "H3K4me1-human" |                                     experiment_target == "H3K4me2-human" |                                     experiment_target == "H3K4me3-human" |                                     experiment_target == "H3K79me2-human" |                                    experiment_target == "H3K9ac-human" |                                      experiment_target == "H3K9me1-human" |                                     experiment_target == "H3K9me2-human" |                                     experiment_target == "H3K9me3-human" |                                     experiment_target == "H4K20me1-human"))

Create new regions attribute: Length of each region and for each sample, compute the number of regions and the sum of each region length just created:

TF_rep_good_1 <- select(TF_rep_good_0, regions_update = list(length = right - left))

TF_rep_good <- extend(TF_rep_good_1, Region_number = COUNT(),
                     sum_length = SUM("length"))
  1. Processing to obtain a dataset on which finding the filtering threshold;
TF_rep_good_merged <- aggregate(TF_rep_good, groupBy =
                     conds(default = c("biosample_term_name")))
                                 

TF_rep_good_ordered <- arrange(TF_rep_good_merged,                
                      regions_ordering = list(ASC("length")))

collect(TF_rep_good_ordered, name = "TF_rep_good_ordered")
job <- execute()

(1.1)Monitor the job status:

trace_job(remote_url , job$id)
  1. Processing to obtain a dataset on which finding the filtering threshold; once the job status is ‘SUCCESS’ download the resulting dataset obtained remotely in the working directory of the local File System:
dataset_name <- job$datasets[[1]]$name
print(dataset_name)

grl_TF_rep_good_ordered <- download_as_GRangesList(remote_url, dataset_name)

download_dataset(remote_url, datasetName = dataset_name, path = './Results_use_case_3')
  1. Processing to obtain a dataset on which finding the filtering threshold; once the needed dataset is saved, perform in the R environment all the remaining operations required to retrieve the threshold value:
name_sample <- names(grl_TF_rep_good_ordered)# campione singolo
g <- grl_TF_rep_good_ordered[[name_sample]] #estraggo GRanges
Region_number_tot <- length(g) # conto tutte le regioni  
n_up <- Region_number_tot * 0.95 #95percentile del numero di regioni
n_up_1 <- n_up + 1
index <- which(g$order >= ceiling(n_up) & g$order <= floor(n_up_1))
region <- g[index]
  1. Processing to obtain a dataset on which finding the filtering threshold; the chosen threshold is the length of the 95percentile of the region number:
threshold <- region$length
threshold <- as.numeric(threshold)
threshold
## [1] 1147

Going back to RGQML remote processing, take only the regions with region lengths greater than 100 and smaller than the threshold:

TF_rep_good_filtered_0 <- filter(TF_rep_good, r_predicate = length >= 100 & length <= threshold)

Create new metadata for each sample, with number of filtered regions and the sum of their lengths:

TF_rep_good_filtered <- extend(TF_rep_good_filtered_0,
                            Region_number_filtered = COUNT(),  
                            sum_length_filtered = SUM("length"))

Combine multiple replicate samples of the same TF experiment:

TF_0 <- cover(TF_rep_good_filtered, 1, ANY(), groupBy = 
               conds("experiment_target"))

Add new region attribute as length of each region after sample combination:

TF_1 <- select(TF_0, regions_update = list(length = right - left))

Create new metadata for each sample, with number of combined regions, and min, max and sum of their lengths:

TF <- extend(TF_1, Region_number_cover = COUNT(), sum_length_cover =
              SUM("length"), min_length_cover = MIN("length"), max_length_cover = MAX("length"))

Materialize TF dataset into repository and download it on mass memory but also in main memory as GRangesList

collect(TF, name= "TF_res")
res <- execute()
#Monitor job status:
trace_job(remote_url, res$id)
# Download dataset as folder:
res_name <- res$datasets[[1]]$name
download_dataset(remote_url, res_name, path = './Results_use_case_3')
# Download dataset as GRangesList:
samples <- download_as_GRangesList(remote_url, res_name)

Post-processing before the analysis with TFHAZ

TF=vector()
len_rep <- sapply(samples, function(x) len <- length(x))

TF_rep <- mapply(function(x, l){
  exp <- x$experiment_target
  TF_temp <- rep(exp, l)
  TF <- append(TF, TF_temp)
}, samples@metadata, len_rep) #metadata(samples)

TF <- unlist(TF_rep)
H1_hESC <- unlist(samples)
data <- data.frame(H1_hESC, TF)
H1_hESC <- as(data, "GRanges")

After loading the TFHAZ package, find the transcription factor HOT DNA zones focusing on one chromosome at at time, by executing the following instructions:

library(TFHAZ)
TF_acc_21_w_0 <- accumulation(H1_hESC, "TF", "chr21", 0)
d_zones <- high_accumulation_zones(TF_acc_21_w_0, method =
                                     "overlaps", threshold = "std")
print(d_zones)
## $zones
## GRanges object with 1300 ranges and 0 metadata columns:
##          seqnames            ranges strand
##             <Rle>         <IRanges>  <Rle>
##      [1]    chr21   9545017-9545326      *
##      [2]    chr21   9857474-9857783      *
##      [3]    chr21   9902931-9903240      *
##      [4]    chr21   9911648-9912212      *
##      [5]    chr21   9913190-9913499      *
##      ...      ...               ...    ...
##   [1296]    chr21 47877820-47879306      *
##   [1297]    chr21 48017969-48018244      *
##   [1298]    chr21 48045673-48046188      *
##   [1299]    chr21 48055000-48056276      *
##   [1300]    chr21 48087336-48088510      *
##   -------
##   seqinfo: 1 sequence from an unspecified genome; no seqlengths
## 
## $n_zones
## [1] 1300
## 
## $n_bases
## [1] 746512
## 
## $lengths
##                 TH            n_zones    length_zone_min    length_zone_max 
##         23198.0000          1300.0000           100.0000         19655.0000 
##   length_zone_mean length_zone_median     length_zone_sd 
##           574.2400           400.0000           728.5139 
## 
## $distances
##               TH          n_zones    dist_zone_min    dist_zone_max 
##         23198.00          1300.00             3.00       4244193.00 
##   dist_zone_mean dist_zone_median     dist_zone_sd 
##         29097.98          8477.00        129112.99 
## 
## $TH
## [1] 23198
## 
## $chr
## [1] "chr21"
## 
## $w
## [1] 0
## 
## $acctype
## [1] "TF"

Log out from remote engine:

logout_gmql(remote_url)
## [1] "Logout"