annotate src/lib/ValidateData.R @ 0:e0b5980139d9

maaslin
author george-weingart
date Tue, 13 May 2014 22:00:40 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
1 #####################################################################################
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
2 #Copyright (C) <2012>
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
3 #
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
4 #Permission is hereby granted, free of charge, to any person obtaining a copy of
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
5 #this software and associated documentation files (the "Software"), to deal in the
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
6 #Software without restriction, including without limitation the rights to use, copy,
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
7 #modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
8 #and to permit persons to whom the Software is furnished to do so, subject to
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
9 #the following conditions:
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
10 #
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
11 #The above copyright notice and this permission notice shall be included in all copies
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
12 #or substantial portions of the Software.
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
13 #
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
14 #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
15 #INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
16 #PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
17 #HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
18 #OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
19 #SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
20 #
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
21 # This file is a component of the MaAsLin (Multivariate Associations Using Linear Models),
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
22 # authored by the Huttenhower lab at the Harvard School of Public Health
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
23 # (contact Timothy Tickle, ttickle@hsph.harvard.edu).
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
24 #####################################################################################
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
25
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
26 inlinedocs <- function(
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
27 ##author<< Curtis Huttenhower <chuttenh@hsph.harvard.edu> and Timothy Tickle <ttickle@hsph.harvard.edu>
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
28 ##description<< Minor validation files to check data typing when needed.
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
29 ) { return( pArgs ) }
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
30
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
31 funcIsValid <- function(
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
32 ### Requires a data to not be NA, not be NULL
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
33 ### Returns True on meeting these requirements, returns false otherwise
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
34 ### Return boolean Indicator of not being empty (TRUE = not empty)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
35 tempData = NA
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
36 ### Parameter tempData Is evaluated as not empty
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
37 ){
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
38 #If the data is not na or null return true
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
39 if(!is.null(tempData))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
40 {
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
41 if(length(tempData)==1){ return(!is.na(tempData)) }
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
42 return(TRUE)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
43 }
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
44 return(FALSE)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
45 ### True (Valid) false (invalid)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
46 }
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
47
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
48 funcIsValidString <- function(
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
49 ### Requires a data to not be NA, not be NULL, and to be of type Character
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
50 ### Returns True on meeting these requirements, returns false otherwise
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
51 ### Return boolean Indicator of identity as a string
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
52 tempData = NA
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
53 ### Parameter tempData Is evaluated as a string
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
54 ){
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
55 #If is not a valid data return false
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
56 if(!funcIsValid(tempData))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
57 {
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
58 return(FALSE)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
59 }
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
60 #If is a string return true
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
61 if((class(tempData)=="character")&&(length(tempData)==1))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
62 {
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
63 return(TRUE)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
64 }
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
65 return(FALSE)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
66 ### True (Valid) false (invalid)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
67 }
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
68
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
69 funcIsValidFileName <- function(
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
70 ### Requires a data to not be NA, not be NULL, and to be a valid string
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
71 ### which points to an existing file
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
72 ### Returns True on meeting these requirements, returns false otherwise
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
73 ### Return boolean Indicator of identity as a file name
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
74 tempData = NA,
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
75 ### Parameter tempData Is evaluated as a file name
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
76 fVerbose=FALSE
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
77 ### Verbose will print the file path when not valid.
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
78 ){
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
79 #If is not valid string return false
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
80 if(!(funcIsValidString(tempData)))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
81 {
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
82 if(fVerbose){print(paste("FunctIsValidFileName: InvalidString. Value=",tempData,sep=""))}
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
83 return(FALSE)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
84 }
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
85 #If is a valid string and points to a file
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
86 if(file.exists(tempData))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
87 {
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
88 return(TRUE)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
89 }
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
90 if(fVerbose){print(paste("FunctIsValidFileName: Path does not exist. Value=",tempData,sep=""))}
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
91 return(FALSE)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
92 ### True (Valid) false (invalid)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
93 }