Skip to content

Commit d974114

Browse files
committed
R cannot handle extremely long strings when assigning variables
1 parent 88dc277 commit d974114

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

singlecell/api-src/org/labkey/api/singlecell/pipeline/AbstractSingleCellPipelineStep.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -348,38 +348,51 @@ public static void executeR(SequenceOutputHandler.JobContext ctx, String dockerC
348348
localBashScript.delete();
349349
}
350350

351-
protected String prepareValueForR(SeuratToolParameter pd)
351+
protected void addParameterVariables(SeuratToolParameter pd, List<String> body)
352352
{
353353
String val = StringUtils.trimToNull(pd.extractValue(getPipelineCtx().getJob(), getProvider(), getStepIdx()));
354354
if (val == null)
355355
{
356-
return "NULL";
356+
body.add((pd.getVariableName() + " <- NULL"));
357357
}
358358
else if ("false".equals(val))
359359
{
360-
return "FALSE";
360+
body.add((pd.getVariableName() + " <- FALSE"));
361361
}
362362
else if ("true".equals(val))
363363
{
364-
return "TRUE";
364+
body.add((pd.getVariableName() + " <- TRUE"));
365365
}
366366
else if (NumberUtils.isCreatable(val))
367367
{
368-
return val;
368+
body.add((pd.getVariableName() + " <- " + val));
369369
}
370370
else if ("sequenceanalysis-trimmingtextarea".equals(pd.getFieldXtype()))
371371
{
372372
val = val.replace("'", "\\\'");
373-
String[] vals = val.split(pd.getDelimiter());
374-
return "c('" + StringUtils.join(vals, "','") + "')";
373+
serializeMultiValueParam(pd, body, val);
374+
375375
}
376376
else if (pd.isMultiValue())
377377
{
378-
String[] vals = val.split(pd.getDelimiter());
379-
return "c('" + StringUtils.join(vals, "','") + "')";
378+
serializeMultiValueParam(pd, body, val);
380379
}
381380

382-
return "'" + val + "'";
381+
body.add((pd.getVariableName() + " <- '" + val + "'"));
382+
}
383+
384+
private void serializeMultiValueParam(SeuratToolParameter pd, List<String> body, String val)
385+
{
386+
String[] vals = val.split(pd.getDelimiter());
387+
final int batchSize = 75;
388+
int numBatches = (int)Math.ceil((double)vals.length / batchSize);
389+
390+
for (int i=0;i<numBatches;i++)
391+
{
392+
int start = (i * batchSize);
393+
int end = Math.min(start + batchSize, vals.length);
394+
body.add(pd.getVariableName() + " <- " + "c(" + (i == 0 ? "" : pd.getVariableName() + ", ") + "'" + StringUtils.join(Arrays.copyOfRange(vals, start, end), "','") + "')");
395+
}
383396
}
384397

385398
protected List<String> loadChunkFromFile() throws PipelineJobException
@@ -423,7 +436,7 @@ protected Chunk createParamChunk(SequenceOutputHandler.JobContext ctx, List<Seur
423436
SeuratToolParameter stp = (SeuratToolParameter)pd;
424437
if (stp.shouldIncludeInMarkdown(getPipelineCtx().getJob(), getProvider(), getStepIdx()))
425438
{
426-
body.add(((SeuratToolParameter) pd).getVariableName() + " <- " + prepareValueForR(stp));
439+
addParameterVariables(stp, body);
427440
}
428441
}
429442
}

singlecell/api-src/org/labkey/api/singlecell/pipeline/SeuratToolParameter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public String getVariableName()
5050
return _rName == null ? getName() : _rName;
5151
}
5252

53-
public boolean shouldIncludeInMarkdown(PipelineJob job, PipelineStepProvider provider, int stepIdx)
53+
public boolean shouldIncludeInMarkdown(PipelineJob job, PipelineStepProvider<?> provider, int stepIdx)
5454
{
5555
if (!_includeIfEmptyOrNull)
5656
{

0 commit comments

Comments
 (0)