git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/seqTools@128657 bc3139a8-67e5-0310-9ffc-ced21a209358
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,113 @@ |
1 |
+ |
|
2 |
+## + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ## |
|
3 |
+## ## |
|
4 |
+## Project : seqTools ## |
|
5 |
+## Created : 26.August.2013 ## |
|
6 |
+## Author : W. Kaisers ## |
|
7 |
+## File : allStatics.r ## |
|
8 |
+## Content : All static variables and (not directly object related ) ## |
|
9 |
+## function declarations ## |
|
10 |
+## ## |
|
11 |
+## + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ## |
|
12 |
+ |
|
13 |
+ |
|
14 |
+## + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ## |
|
15 |
+## Global variables: |
|
16 |
+## + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ## |
|
17 |
+ |
|
18 |
+strandlevels <- c("+", "-", "*") |
|
19 |
+iupac_chars <- c('a', 'c', 'g', 't', 'u', 'r', 'y', 's', 'w', 'k', 'm', 'b', |
|
20 |
+ 'd', 'h', 'v', 'n', '.', '-', '=') |
|
21 |
+ |
|
22 |
+## + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ## |
|
23 |
+## Although static array sizes would allow larger k (e.g. 15: 8 GB RAM), |
|
24 |
+## exponential increase in run-time restricts usability to k values in 1:12 |
|
25 |
+## 4^12 = 16.777.216 possible combinations. |
|
26 |
+## 'Hard' coded (in stat_defs.h: 15) |
|
27 |
+max_k <- 12 |
|
28 |
+## + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ## |
|
29 |
+ |
|
30 |
+## + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ## |
|
31 |
+## End global variables |
|
32 |
+## + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ## |
|
33 |
+ |
|
34 |
+ |
|
35 |
+## + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ## |
|
36 |
+## Some useful functions for work with phred's |
|
37 |
+## + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ## |
|
38 |
+ |
|
39 |
+char2ascii <- function(c) { strtoi(charToRaw(c), base=16L) } |
|
40 |
+ |
|
41 |
+ascii2char <- function(x, multiple=FALSE) |
|
42 |
+ { rawToChar(as.raw(x), multiple=multiple) } |
|
43 |
+ |
|
44 |
+phredTable <- function(phred=0:93) |
|
45 |
+{ |
|
46 |
+ if(!is.numeric(phred)) |
|
47 |
+ stop("phred must be numeric.") |
|
48 |
+ |
|
49 |
+ phred <- sort(unique(as.integer(phred))) |
|
50 |
+ |
|
51 |
+ if( (phred[1] < 0) || (max(phred) > 93) ) |
|
52 |
+ stop("Only phred values in 0:93 are allowed.") |
|
53 |
+ |
|
54 |
+ ascii <- phred + 33 |
|
55 |
+ return(data.frame(ascii=ascii, phred=phred, |
|
56 |
+ char=ascii2char(ascii, multiple=TRUE))) |
|
57 |
+} |
|
58 |
+## + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ## |
|
59 |
+ |
|
60 |
+# unexported functions, do not check for x |
|
61 |
+rel_int <- function(x) {return(.Call("rel_int", x, PACKAGE="seqTools"))} |
|
62 |
+rel_real <- function(x) {return(.Call("rel_real", x, PACKAGE="seqTools"))} |
|
63 |
+ |
|
64 |
+## + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ## |
|
65 |
+enlargeIntMat <- function(x, newDim){ |
|
66 |
+ if(!is.matrix(x)) |
|
67 |
+ stop("x must be matrix.") |
|
68 |
+ |
|
69 |
+ if(!is.numeric(newDim)) |
|
70 |
+ stop("newDim must be numeric.") |
|
71 |
+ |
|
72 |
+ newDim <- as.integer(newDim) |
|
73 |
+ |
|
74 |
+ if(length(newDim) != 2) |
|
75 |
+ stop("newDim must have length 2.") |
|
76 |
+ |
|
77 |
+ return(.Call("r_enlarge_int_mat", x, newDim, PACKAGE="seqTools")) |
|
78 |
+} |
|
79 |
+ |
|
80 |
+kMerIndex <- function(kMers, k=nchar(kMers)[1], base=1) |
|
81 |
+{ |
|
82 |
+ if(!is.character(kMers)) |
|
83 |
+ stop("kMers must be character.") |
|
84 |
+ |
|
85 |
+ if(!is.numeric(k)) |
|
86 |
+ stop("k must be numeric.") |
|
87 |
+ k <- as.integer(k) |
|
88 |
+ |
|
89 |
+ if(k<0 || k > max_k) |
|
90 |
+ stop("k must be in range 0, ... , ", max_k, ".") |
|
91 |
+ |
|
92 |
+ if(!all(nchar(kMers) == k)) |
|
93 |
+ stop("All kMers must have k characters!") |
|
94 |
+ |
|
95 |
+ if(!is.numeric(base)) |
|
96 |
+ stop("base must be numeric") |
|
97 |
+ |
|
98 |
+ if(length(base) > 1) |
|
99 |
+ stop("base must have length 1.") |
|
100 |
+ base<-as.integer(base) |
|
101 |
+ |
|
102 |
+ if(!(base %in% 0:1)) |
|
103 |
+ stop("base must be 0 or 1.") |
|
104 |
+ |
|
105 |
+ return(.Call("get_Kmer_Index", kMers, k, PACKAGE="seqTools") + base) |
|
106 |
+} |
|
107 |
+ |
|
108 |
+## + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ## |
|
109 |
+ |
|
110 |
+ |
|
111 |
+## + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ## |
|
112 |
+## END OF FILE |
|
113 |
+## + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ## |