@@ -25,7 +25,7 @@ setMethod("initialize", "Project", function(.Object, ...) {
2525 # check if file path provided
2626 .Object @ file = .makeAbsPath(ellipsis $ file , parent = path.expand(getwd()))
2727 # instantiate config object and stick it in the config slot
28- .Object @ config = Config(ellipsis $ file , ellipsis $ amendments )
28+ .Object @ config = Config(.Object @ file , ellipsis $ amendments )
2929 .Object = .loadSampleAnnotation(.Object )
3030 .Object = .modifySamples(.Object )
3131 }
@@ -479,40 +479,37 @@ setMethod(
479479}
480480
481481
482- # ' Merge samples defined in sample table with ones in subsample table
482+ # ' Load single subsample annotation
483483# '
484484# ' @param .Object an object of \code{"\linkS4class{Project}"}
485+ # ' @param path string, a path to the subsample table to read and incorporate
485486# '
486487# ' @return an object of \code{"\linkS4class{Project}"}
487- .mergeAttrs = function (.Object ){
488- cfg = config(.Object )
489- if (! CFG_SUBSAMPLE_TABLE_KEY %in% names(cfg )) return (.Object )
490- sampleSubannotationPath = cfg [[CFG_SUBSAMPLE_TABLE_KEY ]]
491- samples = sampleTable(.Object )
492- samples = .listifyDF(samples )
493- if (.safeFileExists(sampleSubannotationPath )) {
494- samplesSubannotation = data.table :: fread(sampleSubannotationPath )
488+ .loadSubsampleAnnotation = function (.Object , path ) {
489+ if (.safeFileExists(path )) {
490+ samplesSubannotation = data.table :: fread(path )
495491 } else {
496492 samplesSubannotation = data.table :: data.table()
497493 }
498494 subNames = unique(samplesSubannotation $ sample_name )
495+ samples = sampleTable(.Object )
496+ samples = .listifyDF(samples )
499497 rowNum = nrow(samples )
500498 # Creating a list to be populated in the loop and inserted
501499 # into the samples data.table as a column. This way the "cells"
502500 # in the samples table can consist of multiple elements
503- colList = vector(" list" , rowNum )
504501 for (iName in subNames ) {
505502 whichNames = which(samplesSubannotation $ sample_name == iName )
506503 subTable = samplesSubannotation [whichNames ,]
507504 dropCol = which(names(samplesSubannotation [whichNames ,]) == " sample_name" )
508505 subTable = subset(subTable , select = - dropCol )
506+ colList = vector(" list" , rowNum )
509507 for (iColumn in seq_len(ncol(subTable ))) {
510508 colName = names(subset(subTable , select = iColumn ))
511509 if (! any(names(samples ) == colName )) {
512510 # The column doesn't exist, creating
513511 samples [, colName ] = NULL
514512 } else {
515- # colList=as.list(unname(samples[, ..colName]))[[1]]
516513 colList = samples [[colName ]]
517514 }
518515 # The column exists
@@ -532,3 +529,20 @@ setMethod(
532529 .Object @ samples = samples
533530 return (.Object )
534531}
532+
533+
534+
535+ # ' Merge samples defined in sample table with ones in subsample table(s)
536+ # '
537+ # ' @param .Object an object of \code{"\linkS4class{Project}"}
538+ # '
539+ # ' @return an object of \code{"\linkS4class{Project}"}
540+ .mergeAttrs = function (.Object ){
541+ cfg = config(.Object )
542+ if (! CFG_SUBSAMPLE_TABLE_KEY %in% names(cfg )) return (.Object )
543+ sampleSubannotationPath = cfg [[CFG_SUBSAMPLE_TABLE_KEY ]]
544+ for (p in sampleSubannotationPath ){
545+ .Object = .loadSubsampleAnnotation(.Object , p )
546+ }
547+ return (.Object )
548+ }
0 commit comments