@@ -992,6 +992,8 @@ setMethod("results", "FraserDataSet", function(object,
992
992
aggregate = aggregate , collapse = collapse , geneColumn = geneColumn ,
993
993
subsetName = NULL , additionalColumns = additionalColumns ,
994
994
BPPARAM = BPPARAM )
995
+ # to restore previous column order
996
+ prevColOrder <- colnames(as.data.table(res ))
995
997
}
996
998
997
999
# add results for FDR_subsets if requested
@@ -1010,16 +1012,63 @@ setMethod("results", "FraserDataSet", function(object,
1010
1012
res <- unlist(GRangesList(unlist(list (res , resls_subsets ))))
1011
1013
} else {
1012
1014
res <- unlist(GRangesList(unlist(resls_subsets )))
1015
+ # restore previous column order
1016
+ prevColOrder <- colnames(as.data.table(resls_subsets [[1 ]]))
1013
1017
}
1018
+ }
1019
+
1020
+ # sort it if existing
1021
+ if (length(res ) > 0 ){
1022
+
1023
+ # dcast to have only one row per gene-sample combination
1024
+ res <- as.data.table(res )
1025
+ if (isTRUE(aggregate )){
1026
+ dcastCols <- c(" pValueGene" , " padjustGene" )
1027
+ } else {
1028
+ dcastCols <- " padjust"
1029
+ }
1030
+ res <- dcast(res , ... ~ FDR_set , value.var = dcastCols )
1014
1031
1015
- # sort it if existing
1016
- if (length(res ) > 0 ){
1017
- res <- res [order(res $ pValue )]
1032
+ # rename column back to padjust for tw results after dcast
1033
+ if (any(grepl(" transcriptome-wide" , colnames(res )))){
1034
+ if (isTRUE(aggregate )){
1035
+ setnames(res , " pValueGene_transcriptome-wide" , " pValueGene" )
1036
+ setnames(res , " padjustGene_transcriptome-wide" , " padjustGene" )
1037
+ } else {
1038
+ setnames(res , " transcriptome-wide" , " padjust" )
1039
+ }
1040
+
1041
+ } else {
1042
+ res [, padjust : = NA ]
1018
1043
if (isTRUE(aggregate )){
1019
- res <- res [! is.na(res $ pValueGene )]
1044
+ res [, pValueGene : = NA ]
1045
+ res [, padjustGene : = NA ]
1020
1046
}
1021
1047
}
1048
+
1049
+ # restore previous column order
1050
+ setcolorder(res , prevColOrder [prevColOrder != " FDR_set" ])
1051
+
1052
+ # rename padjust columns for other gene sets to padjust_setname
1053
+ for (setName in FDRsets ){
1054
+ setnames(res , setName , paste0(" padjust_" , setName ),
1055
+ skip_absent = TRUE )
1056
+ }
1057
+
1058
+ # revert back to GRanges
1059
+ res <- makeGRangesFromDataFrame(res , keep.extra.columns = TRUE )
1060
+
1061
+ # order rows based on transcriptome-wide FDR
1062
+ res <- res [order(res $ pValue )]
1063
+ if (isTRUE(aggregate ) & isTRUE(returnTranscriptomewideResults )){
1064
+ res <- res [! is.na(res $ pValueGene )]
1065
+ }
1066
+
1067
+
1068
+ } else {
1069
+ res $ FDR_set <- NULL
1022
1070
}
1071
+
1023
1072
return (res )
1024
1073
})
1025
1074
0 commit comments