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