99import org .labkey .api .singlecell .pipeline .SingleCellStep ;
1010
1111import java .util .ArrayList ;
12- import java .util .Arrays ;
1312import java .util .Collection ;
1413import java .util .HashSet ;
1514import java .util .List ;
@@ -34,7 +33,8 @@ public Provider()
3433 put ("height" , 150 );
3534 put ("width" , 600 );
3635 put ("delimiter" , DELIM );
37- }}, null )
36+ }}, null ),
37+ ToolParameterDescriptor .create ("useDplyr" , "Use dplyr" , "If checked, the subset will be executed using dplyr::filter rather than Seurat::subset. This should allow more complex expressions to be used, including negations" , "checkbox" , null , false )
3838 ), List .of ("/sequenceanalysis/field/TrimmingTextArea.js" ), null );
3939 }
4040
@@ -71,6 +71,9 @@ protected List<String> loadChunkFromFile() throws PipelineJobException
7171
7272 final String [] values = val .split (DELIM );
7373
74+ ToolParameterDescriptor pd2 = getProvider ().getParameterByName ("useDplyr" );
75+ final boolean useDplyr = pd2 .extractValue (getPipelineCtx ().getJob (), getProvider (), getStepIdx (), Boolean .class , false );
76+
7477 List <String > ret = new ArrayList <>();
7578 for (String line : super .loadChunkFromFile ())
7679 {
@@ -82,15 +85,23 @@ protected List<String> loadChunkFromFile() throws PipelineJobException
8285
8386 ret .add ("\t if (!is.null(seuratObj)) {" );
8487 ret .add ("\t print(paste0('Subsetting dataset: ', datasetId, ' with the expression: " + subsetEscaped + "'))" );
85- ret .add ("\t \t cells <- c()" );
86- ret .add ("\t \t tryCatch({" );
87- ret .add ("\t \t \t cells <- WhichCells(seuratObj, expression = " + subset + ")" );
88- ret .add ("\t \t }, error = function(e){" );
89- ret .add ("\t \t \t if (!is.null(e) && e$message == 'Cannot find cells provided') {" );
90- ret .add ("\t \t \t \t print(paste0('There were no cells remaining after the subset: ', '" + subsetEscaped + "'))" );
91- ret .add ("\t \t \t }" );
92- ret .add ("\t \t })" );
93- ret .add ("" );
88+ if (useDplyr )
89+ {
90+ ret .add ("\t \t \t cells <- rownames(seuratObj@meta.data %>% dplyr::filter( " + subset + " ))" );
91+ }
92+ else
93+ {
94+ ret .add ("\t \t cells <- c()" );
95+ ret .add ("\t \t tryCatch({" );
96+ ret .add ("\t \t \t cells <- WhichCells(seuratObj, expression = " + subset + ")" );
97+ ret .add ("\t \t }, error = function(e){" );
98+ ret .add ("\t \t \t if (!is.null(e) && e$message == 'Cannot find cells provided') {" );
99+ ret .add ("\t \t \t \t print(paste0('There were no cells remaining after the subset: ', '" + subsetEscaped + "'))" );
100+ ret .add ("\t \t \t }" );
101+ ret .add ("\t \t })" );
102+ ret .add ("" );
103+ }
104+
94105 ret .add ("\t \t if (length(cells) == 0) {" );
95106 ret .add ("\t \t \t print(paste0('There were no cells after subsetting for dataset: ', datasetId, ', with subset: ', '" + subsetEscaped + "'))" );
96107 ret .add ("\t \t \t seuratObj <- NULL" );
0 commit comments