Browse code

now accomodates the different sort order of file names returned by list.files on macos and linux

git-svn-id: https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/MotifDb@75309 bc3139a8-67e5-0310-9ffc-ced21a209358

p.shannon authored on 04/04/2013 21:11:54
Showing 2 changed files

... ...
@@ -94,7 +94,6 @@ parsePWMfromText = function (lines.of.text)
94 94
 {
95 95
   stopifnot (sum (sapply (c ('A', 'C', 'T', 'G'), function (token) length (grep (token, lines.of.text)))) == 4)
96 96
 
97
-
98 97
   for (line in lines.of.text) {
99 98
     tokens = strsplit (line, '\\s*[:\\|]') [[1]]
100 99
     nucleotide = tokens [1]
... ...
@@ -118,11 +117,10 @@ readAndParse = function (filenames)
118 117
   matrices = list ()
119 118
 
120 119
   for (filename in filenames) {
121
-    lines.of.text = scan (filename, what=character(0), sep='\n', comment='#', quiet=TRUE)
122
-    mtx = parsePWMfromText (lines.of.text)
123
-    #mtx.normalized = apply (mtx, 2, function (colvector) colvector / sum (colvector))
124
-    matrices [[basename(filename)]] = mtx
125
-    }
120
+      lines.of.text = scan (filename, what=character(0), sep='\n', comment='#', quiet=TRUE)
121
+      mtx = parsePWMfromText (lines.of.text)
122
+      matrices [[basename(filename)]] = mtx
123
+       }
126 124
  
127 125
    invisible (matrices)
128 126
 
... ...
@@ -4,7 +4,10 @@ library (RUnit)
4 4
 #-------------------------------------------------------------------------------
5 5
 source("import.R")
6 6
 #-------------------------------------------------------------------------------
7
-run.tests = function (flyFactorSurveyRootDir="~/s/data/public/TFBS/flyFactorSurvey/unpacked")
7
+#kDataDir <- "~/s/data/public/TFBS/flyFactorSurvey/unpacked"
8
+kDataDir <- "/shared/silo_researcher/Morgan_M/BioC/MotifDb/flyFactorSurvey"
9
+#-------------------------------------------------------------------------------
10
+run.tests = function (flyFactorSurveyRootDir=kDataDir)
8 11
 {
9 12
     freshStart ()
10 13
     test.fbgnToIDs()
... ...
@@ -60,10 +63,11 @@ test.getMatrixFilenames = function (flyFactorSurveyRootDir)
60 63
        # as of (03 apr 2013): 614 matrix files, one binding domains extra
61 64
        # file, TFfile2b.tsv
62 65
     
63
-    checkEquals (length (filenames), 615)
64
-    checkEquals(filenames[1:3],
65
-                c("Abd-A_FlyReg_FBgn0000014.pfm", "Abd-B_FlyReg_FBgn0000015.pfm",
66
-                  "AbdA_Cell_FBgn0000014.pfm"))
66
+    checkTrue(length (filenames) > 600)
67
+    sample.files <- c("Abd-A_FlyReg_FBgn0000014.pfm", "Abd-B_FlyReg_FBgn0000015.pfm",
68
+                      "AbdA_Cell_FBgn0000014.pfm")
69
+    checkTrue(all(sample.files %in% filenames))
70
+
67 71
     invisible (filenames)
68 72
 
69 73
 } # test.getMatrixFilenames
... ...
@@ -81,8 +85,9 @@ test.createExperimentRefTable = function ()
81 85
 test.parsePWMfromText = function (flyFactorSurveyRootDir)
82 86
 {
83 87
     print ('--- test.parsePWMfromText')
84
-    path <- file.path(flyFactorSurveyRootDir, 'Tup_SOLEXA_10_FBgn0003896.pfm')
85
-
88
+    path <- file.path(flyFactorSurveyRootDir, 'tup_SOLEXA_10_FBgn0003896.pfm')
89
+    checkTrue(file.exists(path))
90
+    
86 91
     lines.of.text =  scan (path, sep='\n',
87 92
                            what=character(0), comment='#', quiet=TRUE)
88 93
     pwm.tup =  parsePWMfromText (lines.of.text)
... ...
@@ -101,8 +106,12 @@ test.readAndParse = function (flyFactorSurveyRootDir)
101 106
     all.files = file.path(flyFactorSurveyRootDir,
102 107
                           getMatrixFilenames (flyFactorSurveyRootDir))
103 108
     
104
-    sample.files = all.files [1:3]   # grep ('FBgn0003896', all.files)
105
-    checkEquals (length (sample.files), 3)
109
+    sample.files <- c("Abd-A_FlyReg_FBgn0000014.pfm",
110
+                      "Abd-B_FlyReg_FBgn0000015.pfm",
111
+                      "AbdA_Cell_FBgn0000014.pfm")
112
+
113
+    checkTrue(all(sample.files %in% list.files(flyFactorSurveyRootDir)))
114
+    sample.files <- file.path(flyFactorSurveyRootDir, sample.files)
106 115
     checkTrue(all(file.exists(sample.files)))
107 116
 
108 117
       # by sorting these filenames, we know the order of the three returned
... ...
@@ -111,6 +120,8 @@ test.readAndParse = function (flyFactorSurveyRootDir)
111 120
     mtx.test = readAndParse (sample.files)
112 121
 
113 122
     checkEquals (length (mtx.test), 3)
123
+        # names are alphabetized, and sort differently in linux and macos
124
+        # work around that by 
114 125
     expected.names = c("Abd-A_FlyReg_FBgn0000014.pfm",
115 126
                        "Abd-B_FlyReg_FBgn0000015.pfm",
116 127
                        "AbdA_Cell_FBgn0000014.pfm")
... ...
@@ -160,6 +171,21 @@ test.createMetadata = function (matrices, tbl.ref, xref, list.BD)
160 171
 
161 172
 } # test.createMetadata
162 173
 #-------------------------------------------------------------------------------
174
+test.normalizeMatrices = function (matrices)
175
+{
176
+  print ('--- test.normalizeMatrices')
177
+
178
+  colsums = as.integer (sapply (matrices, function (mtx) as.integer (mean (round (colSums (mtx))))))
179
+  checkTrue (all (colsums > 1))
180
+
181
+  matrices.norm = normalizeMatrices (matrices)
182
+
183
+  colsums = as.integer (sapply (matrices.norm, function (mtx) as.integer (mean (round (colSums (mtx))))))
184
+  checkTrue (all (colsums == 1))
185
+  invisible (matrices.norm)
186
+
187
+} # test.normalizeMatrices
188
+#------------------------------------------------------------------------------------------------------------------------
163 189
 test.renameMatrices = function (matrices, tbl.md)
164 190
 {
165 191
     print ('--- test.renameMatrices')