0
|
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<< Creates a summary of association detail files.
|
|
29 ) { return( pArgs ) }
|
|
30
|
|
31 #Logging class
|
|
32 suppressMessages(library(logging, warn.conflicts=FALSE, quietly=TRUE, verbose=FALSE))
|
|
33
|
|
34 # Get logger
|
|
35 c_logrMaaslin <- getLogger( "maaslin" )
|
|
36
|
|
37 funcSummarizeDirectory = function(
|
|
38 ### Summarizes the massline detail files into one file based on significance.
|
|
39 astrOutputDirectory,
|
|
40 ### The output directory to find the MaAsLin results.
|
|
41 strBaseName,
|
|
42 ### The prefix string used in maaslin to start the detail files.
|
|
43 astrSummaryFileName,
|
|
44 ### The summary file's name, should be a path not a file name
|
|
45 astrKeyword,
|
|
46 ### The column name of the data to check significance before adding a detail to the summary
|
|
47 afSignificanceLevel
|
|
48 ### The value of significance the data must be at or below to be included in the summary (0.0 is most significant; like p-values)
|
|
49 ){
|
|
50 #Store significant data elements
|
|
51 dfSignificantData = NULL
|
|
52
|
|
53 #Get detail files in output directory
|
|
54 astrlsDetailFiles = list.files(astrOutputDirectory, pattern=paste(strBaseName,"-","[[:print:]]*",c_sDetailFileSuffix,sep=""), full.names=TRUE)
|
|
55 logdebug(format(astrlsDetailFiles),c_logrMaaslin)
|
|
56
|
|
57 #For each file after the first file
|
|
58 for(astrFile in astrlsDetailFiles)
|
|
59 {
|
|
60 #Read in data and reduce to significance
|
|
61 dfDetails = read.table(astrFile, header=TRUE, sep=c_cTableDelimiter)
|
|
62 dfDetails = dfDetails[which(dfDetails[astrKeyword] <= afSignificanceLevel),]
|
|
63
|
|
64 #Combine with other data if it exists
|
|
65 if(is.null(dfSignificantData))
|
|
66 {
|
|
67 dfSignificantData = dfDetails
|
|
68 } else {
|
|
69 dfSignificantData = rbind(dfSignificantData,dfDetails)
|
|
70 }
|
|
71 }
|
|
72
|
|
73 #Write data to file
|
|
74 unlink(astrSummaryFileName)
|
|
75 if(is.null(dfSignificantData))
|
|
76 {
|
|
77 funcWrite("No significant data found.",astrSummaryFileName)
|
|
78 return( NULL )
|
|
79 } else {
|
|
80 #Sort by metadata and then significance
|
|
81 dfSignificantData = dfSignificantData[order(dfSignificantData$Value, dfSignificantData$P.value, decreasing = FALSE),]
|
|
82 funcWriteTable( dfSignificantData, astrSummaryFileName, fAppend = FALSE )
|
|
83 # Sort by q.value and return
|
|
84 return( dfSignificantData[ order( dfSignificantData$P.value, decreasing = FALSE ), ] )
|
|
85 }
|
|
86 }
|