# HG changeset patch # User jeremyjliu # Date 1428463363 14400 # Node ID 76e108a19e64b21c0da19f56275904e50a563636 # Parent b868314320e263efda931a69fc7d2d8012f43f74 Uploaded diff -r b868314320e2 -r 76e108a19e64 region_motif_compare.r --- a/region_motif_compare.r Fri Mar 06 13:24:03 2015 -0500 +++ b/region_motif_compare.r Tue Apr 07 23:22:43 2015 -0400 @@ -5,11 +5,11 @@ # Author: Jeremy liu # Email: jeremy.liu@yale.edu # Date: 15/02/11 -# Note: This script is meant to be invoked with the following command +# Note: This script can be invoked with the following command # R --slave --vanilla -f ./region_motif_compare.r --args # -# is working directory of galaxy installation -# Dependencies: region_motif_data_manager, plotting.r +# is the directory where plotting.r is saved +# Dependencies: region_motif_data_manager, plotting.r, # Auxiliary function to concatenate multiple strings concat <- function(...) { @@ -46,14 +46,27 @@ startTime = Sys.time() cat("Running ... Started at:", format(startTime, "%a %b %d %X %Y"), "...\n") -# Loading motif position weight matrix (pwm) file and input tab file +# Loading motif position weight matrix (pwm) file +cat("Loading motif postion weight matrices...\n") +lines = scan(pwmFile, what="character", sep="\n", quiet=TRUE) +indices = which(grepl("MOTIF", lines)) +names(indices) = lapply(indices, function(i) { + nameline = lines[i] + name = substr(nameline, 7, nchar(nameline)) + }) + +pwms = sapply(indices, function(i) { + infoline = unlist(strsplit(lines[i+1], " ")) + alength = as.numeric(infoline[4]) + width = as.numeric(infoline[6]) + subset = lines[(i+2):(i+2+width-1)] + motiflines = strsplit(subset, " ") + motif = t(do.call(rbind, motiflines)) + motif = apply(motif, 2, as.numeric) + }, simplify=FALSE, USE.NAMES=TRUE) + +# Loading input tab files cat("Loading and reading input region motif count files...\n") -load(pwmFile) # pwms data structure -#if (dbCode == "c") { # Remaining implementation of dbCode "c" combined -# temp = pwms -# load(pwmFile2) -# pwms = append(temp, pwms) -#} region1DF = read_tsv(inTab1) region2DF = read_tsv(inTab2) region1Counts = region1DF$counts diff -r b868314320e2 -r 76e108a19e64 region_motif_intersect.r --- a/region_motif_intersect.r Fri Mar 06 13:24:03 2015 -0500 +++ b/region_motif_intersect.r Tue Apr 07 23:22:43 2015 -0400 @@ -4,9 +4,9 @@ # Author: Jeremy Liu # Email: jeremy.liu@yale.edu # Date: 15/02/11 -# Note: This script is meant to be invoked with the following command +# Note: This script can be invoked with the following command # R --slave --vanilla -f ./region_motif_intersect.r --args -# Dependencies: region_motif_data_manager +# Dependencies: region_motif_data_manager, Rsamtools # Auxiliary function to concatenate multiple strings concat <- function(...) { @@ -33,7 +33,7 @@ # Load dependencies cat("Loading dependencies...\n") -suppressPackageStartupMessages(library(Rsamtools, quietly=TRUE)) +suppressPackageStartupMessages(library(Rsamtools, quietly=TRUE)) # NEED TO HANDLE INSTALLATION # Initializing hash table (as env) with motif names and loading tabix file cat("Loading motif database and initializing hash table...\n") diff -r b868314320e2 -r 76e108a19e64 repository_dependencies.xml --- a/repository_dependencies.xml Fri Mar 06 13:24:03 2015 -0500 +++ b/repository_dependencies.xml Tue Apr 07 23:22:43 2015 -0400 @@ -1,4 +1,4 @@ - +