makeGenomicInteractionsFromDataFrame: Creates a GenomicInteractions object from a DataFrame in the...

Description Usage Arguments Value Examples

View source: R/makeGenomicInteractionsFromDataFrame.R

Description

Creates a GenomicInteractions object from a DataFrame in the appropriate format (having columns chr1,start1,end1,chr2,start2,end2,....).

Usage

1
2
3
4
5
makeGenomicInteractionsFromDataFrame(
  inputdf,
  n = nrow(inputdf),
  includemetadata = T
)

Arguments

inputdf

Dataframe with six cols, with chr1,start1,end1,chr2,start2,end2

n

the number of rows to use from the dataframe.

includemetadata

include metadata (the columns after the first six) in output?

Value

output_gint

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
library(magrittr)
 gs3dk_gint <- data.table::fread(system.file(
 "extdata","signficant_genes_genoscan_3D_knock.csv",
 package = "GS3DKViz")) %>% 
 #automatically clean column names, converting to standard format.
 janitor::clean_names() %>%
   #split the gene position into start and end
   tidyr::separate(gene_position,c("genestart","geneend"),  "-") %>% 
   #split the promoter position into start and end
   tidyr::separate(promoter_position,c("promoterstart","promoterend"),  "-") %>% 
   #split the enhancer position into start and end
   tidyr::separate(best_enhancer_position,c("enhstart","enhend"),  "-") %>%
   #convert the promoter starts to numeric, assign replacements for missing data.
   dplyr::mutate(promoterstart=suppressWarnings(as.numeric(promoterstart)),
                 chr1=chr,chr2=chr,
                 #replace missing promoter starts with TSS
                 promoterstart=ifelse(is.na(promoterstart),genestart,
                                      promoterstart),
                 #replace missing promoter ends with TSS
                 promoterend=ifelse(is.na(promoterend),genestart
                                    ,promoterend)) %>%  
   #create metadata column that determines whether an interaction is from
   #the ABC model or from GeneHancer.
   dplyr::mutate(enhancer_type=ifelse(grepl(pattern="GH",x=enhancer_id),
                                      "GH","ABC")) %>% 
   #rearrange data columns for GenomicInteractions Objects
   dplyr::select(chr1,promoterstart,promoterend,chr2,enhstart,enhend,
                 dplyr::everything()) %>% 
   #rename columns to standard GenomicInteractions format.
   dplyr::rename(start1=promoterstart,end1=promoterend,start2=enhstart,
               end2=enhend) %>%
   #remove chromosomes from second range (ranges should only be positions).
   dplyr::mutate(start2=gsub("chr19: ","",start2)) %>% 
   #create the GI.
makeGenomicInteractionsFromDataFrame() %>% 
 .[which(GenomicInteractions::calculateDistances(.)!=0),]
   #remove arcs where the promoter and enhancers overlap.
   S4Vectors::mcols(gs3dk_gint)=gs3dk_gint %>% tibble::as_tibble() %>% janitor::clean_names() %>% 
   dplyr::group_by(enhancer_type) %>%
   dplyr::mutate(interaction_score=interaction_score/mean(interaction_score,na.rm=TRUE)) 
   S4Vectors::mcols(gs3dk_gint)$counts<-ifelse(
   !is.na(S4Vectors::mcols(gs3dk_gint)$interaction_score),
   S4Vectors::mcols(gs3dk_gint)$interaction_score,1) 

jamesdalg/GS3DKViz documentation built on Jan. 1, 2021, 4:27 a.m.