annotate maaslin-4450aa4ecc84/src/lib/ValidateData.R @ 1:a87d5a5f2776

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