@@ -71,7 +71,7 @@ omics <- R6::R6Class(
7171 invisible (self )
7272 } else stop(" Data input requires to be of the same class as `featureData`" )
7373 },
74- # ' @field countData A dense or sparse \link{Matrix}.
74+ # ' @field countData A dense or sparse \link[Matrix] {Matrix}.
7575 countData = function (value ) {
7676 # Restores omics class components
7777 private $ tmp_link(
@@ -103,7 +103,7 @@ omics <- R6::R6Class(
103103 # ' @description
104104 # ' Wrapper function that is inherited and adapted for each omics class.
105105 # ' The omics classes requires a metadata samplesheet, that is validated by the metadata_schema.json.
106- # ' It requires a column `SAMPLE_ID` and optionally a `SAMPLEPAIR_ID` or `FEATURE_ID` can be supplied.
106+ # ' It requires a column `SAMPLE_ID` and optionally a `SAMPLEPAIR_ID` can be supplied.
107107 # ' The `SAMPLE_ID` will be used to link the metaData to the countData, and will act as the key during subsetting of other columns.
108108 # ' To create a new object use [`new()`](#method-new) method. Do notice that the abstract class only checks if the metadata is valid!
109109 # ' The `countData` and `featureData` will not be checked, these are handled by the sub-classes.
@@ -125,24 +125,14 @@ omics <- R6::R6Class(
125125 cli :: cli_alert_success(" Metadata template passed the JSON validation." )
126126
127127 # --------------------------------------------------------------------#
128- # # Checking for duplicated sample and feature identifiers
128+ # # Checking for duplicated sample identifiers
129129 # --------------------------------------------------------------------#
130130
131131 cli :: cli_alert_info(" Checking for duplicated identifiers .." )
132132
133133 duplicated_sample_ids <- any(duplicated(private $ .metaData , by = private $ .sample_id ))
134-
135- if (column_exists(private $ .feature_id , private $ .metaData )) {
136- duplicated_feature_ids <- any(duplicated(private $ .metaData , by = private $ .feature_id ))
137- } else {
138- duplicated_feature_ids <- FALSE
139- }
140-
141- if (duplicated_sample_ids ) {
134+ if (duplicated_sample_ids )
142135 cli :: cli_abort(" Found duplicated SAMPLE_ID, make sure SAMPLE_ID column contains unique identifiers!" )
143- } else if (duplicated_feature_ids ) {
144- cli :: cli_abort(" Found duplicated FEATURE_ID, make sure FEATURE_ID column contains unique identifiers!" )
145- }
146136
147137 # --------------------------------------------------------------------#
148138 # # Disable samplepair_id if not supplied
@@ -167,15 +157,20 @@ omics <- R6::R6Class(
167157 # ## featureData ###
168158 # -------------------#
169159 if (! is.null(featureData )) {
160+ duplicated_feature_ids <- FALSE
170161 private $ .featureData <- private $ check_table(featureData )
171162
172- if (column_exists(private $ .feature_id , private $ .metaData )) {
173- FEATURE_ID <- private $ .metaData [[ private $ .feature_id ]]
163+ if (column_exists(private $ .feature_id , private $ .featureData )) {
164+ duplicated_feature_ids <- any(duplicated(private $ .featureData , by = private $ .feature_id ))
165+
166+ if (duplicated_feature_ids )
167+ cli :: cli_abort(" Found duplicated FEATURE_ID, make sure FEATURE_ID column contains unique identifiers!" )
168+
174169 } else {
170+
175171 FEATURE_ID <- paste0(" feature_" , 1 : nrow(private $ .featureData ))
172+ private $ .featureData [, private $ .feature_id : = FEATURE_ID ]
176173 }
177-
178- private $ .featureData [, private $ .feature_id : = FEATURE_ID ]
179174 cli :: cli_alert_success(" featureData is loaded." )
180175 }
181176
@@ -193,12 +188,13 @@ omics <- R6::R6Class(
193188 if (is.null(countData_with_rownames )) {
194189 FEATURE_ID <- paste0(" feature_" , 1 : nrow(private $ .countData ))
195190 private $ .featureData <- private $ .featureData [, (private $ .feature_id ) : = FEATURE_ID ]
191+ rownames(private $ .countData ) <- FEATURE_ID
196192 } else {
197193 private $ .featureData <- private $ .featureData [, (private $ .feature_id ) : = countData_with_rownames ]
198- }
199-
200- rownames(private $ .countData ) <- private $ .featureData [[ private $ .feature_id ]]
194+ }
201195 cli :: cli_alert_warning(" Placeholder featureData created." )
196+ } else {
197+ rownames(private $ .countData ) <- private $ .featureData [[ private $ .feature_id ]]
202198 }
203199 }
204200
@@ -223,7 +219,6 @@ omics <- R6::R6Class(
223219 # ' Acceptable column headers:
224220 # ' * SAMPLE_ID (required)
225221 # ' * SAMPLEPAIR_ID (optional)
226- # ' * FEATURE_ID (optional)
227222 # ' * CONTRAST_ (optional), used for [`autoFlow()`](#method-autoFlow).
228223 # ' * VARIABLE_ (optional), not supported yet.
229224 # '
@@ -864,7 +859,7 @@ omics <- R6::R6Class(
864859 if (! is.null(col_name ))
865860 self $ removeNAs(col_name )
866861
867- # Convert sparse matrix to data.table
862+ # Converts matrix to data.table
868863 counts <- matrix_to_dtable(private $ .countData )
869864
870865 # Fetch unfiltered and filtered features
@@ -1775,6 +1770,7 @@ omics <- R6::R6Class(
17751770
17761771 # Keep only common samples based on metaData
17771772 if (! is.null(private $ .countData )) {
1773+ private $ .countData <- private $ check_matrix(private $ .countData )
17781774 common_samples <- base :: intersect(private $ .metaData [[ private $ .sample_id ]], colnames(private $ .countData ))
17791775 private $ .countData <- private $ .countData [, common_samples , drop = FALSE ]
17801776 private $ .metaData <- private $ .metaData [private $ .metaData [[ private $ .sample_id ]] %in% common_samples , ]
@@ -1785,18 +1781,27 @@ omics <- R6::R6Class(
17851781 if (! column_exists(private $ .feature_id , private $ .featureData ))
17861782 cli :: cli_abort(" {private$.feature_id} doesn't exist in featureData." )
17871783
1784+ private $ .featureData <- private $ check_table(private $ .featureData )
17881785 colnames(private $ .featureData ) <- gsub(" \\ s+" , " _" , colnames(private $ .featureData ))
17891786
17901787 # Keep only common tips based on treeData
17911788 if (! is.null(private $ .treeData )) {
17921789 common_tips <- base :: intersect(private $ .treeData $ tip.label , private $ .featureData [[ private $ .feature_id ]])
1790+
1791+ if (length(common_tips ) == 0 )
1792+ cli :: cli_abort(" None FEATURE_IDs are matching, check if FEATURE_ID exists in `treeData` tip labels!" )
1793+
17931794 private $ .treeData <- ape :: keep.tip(private $ .treeData , common_tips )
17941795 private $ .featureData <- private $ .featureData [private $ .featureData [[ private $ .feature_id ]] %in% common_tips , ]
17951796 }
17961797
17971798 # Keep only common features based on countData
17981799 if (! is.null(private $ .countData )) {
17991800 common_features <- base :: intersect(private $ .featureData [[ private $ .feature_id ]], rownames(private $ .countData ))
1801+
1802+ if (length(common_features ) == 0 )
1803+ cli :: cli_abort(" None FEATURE_IDs are matching, check if FEATURE_ID exists in `countData` rownames!" )
1804+
18001805 private $ .featureData <- private $ .featureData [private $ .featureData [[ private $ .feature_id ]] %in% common_features , ]
18011806 private $ .countData <- private $ .countData [common_features , ]
18021807 private $ removeZeros()
@@ -1863,6 +1868,8 @@ omics <- R6::R6Class(
18631868 if (! is.null(dt $ V1 )) {
18641869 dt_rownames <- dt $ V1
18651870 dt [, V1 : = NULL ]
1871+ } else {
1872+ dt_rownames <- NULL
18661873 }
18671874 # Convert to matrix format
18681875 mat <- Matrix :: Matrix(
0 commit comments