Open tovahmarkowitz opened 3 days ago
prepDiffBind <- function(DiffBindFile) { inDiffBindData <- read.delim(DiffBindFile) DiffBindData <- inDiffBindData[order(inDiffBindData$seqnames,inDiffBindData$start),] DiffBindData$peak_id <- paste0("Peak",1:nrow(DiffBindData)) return(DiffBindData) } loadAndMerge <- function(DiffBindFile, UropaFile) { DiffBindData <- prepDiffBind(DiffBindFile) UropaData <- read.delim(UropaFile) MergedData <- merge(DiffBindData,UropaData) #which(MergedData$end != MergedData$peak_end) #names(MergedData) #[1] "peak_id" "seqnames" "start" "end" #[5] "width" "strand" "Conc" "Conc_D5pos4" #[9] "Conc_D5neg4" "Fold" "p.value" "FDR" #[13] "Called1" "Called2" "peak_chr" "peak_start" #[17] "peak_end" "peak_score" "peak_strand" "feature" #[21] "feat_start" "feat_end" "feat_strand" "feat_anchor" #[25] "distance" "relative_location" "feat_ovl_peak" "peak_ovl_feat" #[29] "gene_id" "gene_name" "gene_type" "name" MergedData2 <- MergedData[order(MergedData$FDR,decreasing = F), c(2:5,1,8:10,12,21:26,29:32)] return(MergedData2) } FilterMerged <- function(MergedData2,FDRcutoff=0.05,FoldCutoff=0) { MergedDataFDR <- MergedData2[which(MergedData2$FDR < FDRcutoff),] MergedDataFiltered <- MergedDataFDR[which((MergedDataFDR$Fold > FoldCutoff) | (MergedDataFDR$Fold) < -(FoldCutoff)),] return(MergedDataFiltered) }