comparison region_motif_intersect.r @ 31:0e031bf8c5b1 draft

Uploaded
author jeremyjliu
date Wed, 04 Feb 2015 13:52:22 -0500
parents 2c909bfdd090
children 4ce22698acb0
comparison
equal deleted inserted replaced
30:da0bc6dead0d 31:0e031bf8c5b1
1 # Name: region_motif_intersect.r 1 # Name: region_motif_intersect.r
2 # Description: Takes a bed file of target regions and counts intersections 2 # Description: Takes a bed file of target regions and counts intersections
3 # of each motif (built in rdata database) and target regions. 3 # of each motif (in separately installed tabix database) and target regions.
4 # Author: Jeremy liu 4 # Author: Jeremy liu
5 # Email: jeremy.liu@yale.edu 5 # Email: jeremy.liu@yale.edu
6 # Date: 14/07/02 6 # Date: 15/02/04
7 # Note: This script is meant to be invoked with the following command 7 # Note: This script is meant to be invoked with the following command
8 # R --slave --vanilla -f ./region_motif_intersect.r --args <workingdir> <db> <inbed> <outtab> 8 # R --slave --vanilla -f ./region_motif_intersect.r --args <db_bgz> <db_tbi> <inbed> <outtab>
9 # <workingdir> is working directory of galaxy installation 9 # Dependencies: region_motif_data_manager
10 # <db> types: "t" test, "p" pouya, "j" jaspar jolma, "m" mouse
11 # Dependencies: none
12 10
13 # Auxiliary function to concatenate multiple strings 11 # Auxiliary function to concatenate multiple strings
14 concat <- function(...) { 12 concat <- function(...) {
15 input_list <- list(...) 13 input_list <- list(...)
16 return(paste(input_list, sep="", collapse="")) 14 return(paste(input_list, sep="", collapse=""))
17 } 15 }
18 16
19 # Set common and data directories 17 # Retrive motif database path
20 args <- commandArgs() 18 args <- commandArgs()
21 workingDir = args[7] 19 motifDB_bgz = args[7]
22 dbDir = concat(workingDir, "/region_motif_db") 20 motifDB_tbi = args[8]
23 dbCode = args[8]
24 if (dbCode == "t") {
25 motifDB = concat(dbDir, "/pouya_test_motifs.bed.bgz")
26 } else if (dbCode == "p") {
27 motifDB = concat(dbDir, "/pouya_motifs.bed.bgz")
28 } else if (dbCode == "j") {
29 motifDB = concat(dbDir, "/jaspar_jolma_motifs.bed.bgz")
30 } else if (dbCode == "m") {
31 motifDB = concat(dbDir, "/mm9_motifs.bed.bgz")
32 } else {
33 motifDB = concat(dbDir, "/pouya_motifs.bed.bgz")
34 }
35 21
36 # Set input and reference files, comment to toggle commmand line arguments 22 # Set input and reference files, comment to toggle commmand line arguments
37 inBed = args[9] 23 inBed = args[9]
38 outTab = args[10] 24 outTab = args[10]
39 25
50 suppressPackageStartupMessages(library(Rsamtools, quietly=TRUE)) 36 suppressPackageStartupMessages(library(Rsamtools, quietly=TRUE))
51 37
52 # Initializing hash table (as env) with motif names and loading tabix file 38 # Initializing hash table (as env) with motif names and loading tabix file
53 cat("Loading motif database and initializing hash table...\n") 39 cat("Loading motif database and initializing hash table...\n")
54 motifTable = new.env() 40 motifTable = new.env()
55 motifTbx <- TabixFile(motifDB) 41 motifTbx <- TabixFile(motifDB_bgz)
56 42
57 # Loading input bed file, convert integer columns to numeric, name columns 43 # Loading input bed file, convert integer columns to numeric, name columns
58 cat("Loading region file...\n") 44 cat("Loading region file...\n")
59 regionsDF = read_bed(inBed) 45 regionsDF = read_bed(inBed)
60 dfTemp = sapply(regionsDF, is.integer) 46 dfTemp = sapply(regionsDF, is.integer)