git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/affxparser@74592 bc3139a8-67e5-0310-9ffc-ced21a209358
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/affxparser@19352 bc3139a8-67e5-0310-9ffc-ced21a209358
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,106 @@ |
1 |
+########################################################################/-Rdoc TURNED OFF-** |
|
2 |
+# @RdocFunction .readCelHeaderV3 |
|
3 |
+# |
|
4 |
+# @title "Read the header of a CEL v3 (ASCII) file" |
|
5 |
+# |
|
6 |
+# \description{ |
|
7 |
+# @get "title". |
|
8 |
+# } |
|
9 |
+# |
|
10 |
+# @synopsis |
|
11 |
+# |
|
12 |
+# \arguments{ |
|
13 |
+# \item{con}{An open and readable @connection.} |
|
14 |
+# } |
|
15 |
+# |
|
16 |
+# \value{ |
|
17 |
+# Returns a named @list structure. |
|
18 |
+# } |
|
19 |
+# |
|
20 |
+# \details{ |
|
21 |
+# When the header is read, the file pointer is at the line after the |
|
22 |
+# header. Empty lines should be expected before the intensity section. |
|
23 |
+# This function does not make use of Fusion SDK. |
|
24 |
+# } |
|
25 |
+# |
|
26 |
+# @author |
|
27 |
+# |
|
28 |
+# @keyword IO |
|
29 |
+# @keyword File |
|
30 |
+# @keyword internal |
|
31 |
+#**-Rdoc TURNED OFF-/####################################################################### |
|
32 |
+.readCelHeaderV3 <- function(con, ...) { |
|
33 |
+ trim <- function(s, ...) { |
|
34 |
+ s <- gsub("^[ \t]*", "", s); |
|
35 |
+ s <- gsub("[ \t]*$", "", s); |
|
36 |
+ s; |
|
37 |
+ } |
|
38 |
+ |
|
39 |
+ # Read "[CEL]" |
|
40 |
+ while (TRUE) { |
|
41 |
+ tag <- trim(readLines(con, n=1)); |
|
42 |
+ if (!identical(tag, "")) |
|
43 |
+ break; |
|
44 |
+ } |
|
45 |
+ if (!identical(tag, "[CEL]")) { |
|
46 |
+ stop("Could not read CEL v3 file header. File format error: File does not start with [CEL]: ", tag); |
|
47 |
+ } |
|
48 |
+ |
|
49 |
+ # Read version |
|
50 |
+ version <- trim(readLines(con, n=1)); |
|
51 |
+ if (!identical(version, "Version=3")) { |
|
52 |
+ stop("Could not read CEL v3 file header. Not a version 3 file: ", version); |
|
53 |
+ } |
|
54 |
+ |
|
55 |
+ # Read "[HEADER]" |
|
56 |
+ while (TRUE) { |
|
57 |
+ tag <- trim(readLines(con, n=1)); |
|
58 |
+ if (!identical(tag, "")) |
|
59 |
+ break; |
|
60 |
+ } |
|
61 |
+ if (!identical(tag, "[HEADER]")) { |
|
62 |
+ stop("Could not read CEL v3 file header. Expected HEADER section, but got: ", tag); |
|
63 |
+ } |
|
64 |
+ |
|
65 |
+ # Read header fields |
|
66 |
+ header <- list( |
|
67 |
+ version = as.integer(3) |
|
68 |
+ ); |
|
69 |
+ while (TRUE) { |
|
70 |
+ field <- trim(readLines(con, n=1)); |
|
71 |
+ if (identical(field, "")) |
|
72 |
+ break; |
|
73 |
+ field <- unlist(strsplit(field, split="=")); |
|
74 |
+ key <- field[1]; |
|
75 |
+ value <- paste(field[-1], collapse="="); |
|
76 |
+ header[[key]] <- value; |
|
77 |
+ } |
|
78 |
+ |
|
79 |
+ # Fields to be converted to integers |
|
80 |
+ intFields <- c("Cols", "Rows", "TotalX", "TotalY", |
|
81 |
+ "OffsetX", "OffsetY", "swapXY"); |
|
82 |
+ # Ad hoc, but the "Axis" fields are sometimes misspelled. |
|
83 |
+ axisFields <- grep("^Axis[-]*(i|I)nvert(X|Y)$", names(header), value=TRUE); |
|
84 |
+ intFields <- c(intFields, axisFields); |
|
85 |
+ for (ff in intersect(names(header), intFields)) { |
|
86 |
+ header[[ff]] <- as.integer(header[[ff]]); |
|
87 |
+ } |
|
88 |
+ |
|
89 |
+ # Vector fields |
|
90 |
+ for (ff in grep("GridCorner", names(header))) { |
|
91 |
+ value <- header[[ff]]; |
|
92 |
+ value <- unlist(strsplit(value, split=" ")); |
|
93 |
+ value <- trim(value); |
|
94 |
+ value <- as.integer(value); |
|
95 |
+ header[[ff]] <- value; |
|
96 |
+ } |
|
97 |
+ |
|
98 |
+ header; |
|
99 |
+} # .readCelHeaderV3() |
|
100 |
+ |
|
101 |
+ |
|
102 |
+############################################################################ |
|
103 |
+# HISTORY: |
|
104 |
+# 2006-07-10 |
|
105 |
+# o Created from .readCelHeaderV3(). |
|
106 |
+############################################################################ |