Skip to content

Commit 28f2b53

Browse files
committed
update markdown
1 parent cb2d580 commit 28f2b53

File tree

2 files changed

+80
-32
lines changed

2 files changed

+80
-32
lines changed

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

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ protected File createRmd(SequenceOutputHandler.JobContext ctx, List<SeuratObject
128128
try (PrintWriter out = PrintWriters.getPrintWriter(outfile))
129129
{
130130
Markdown markdown = new Markdown();
131-
markdown.headerYml = getDefaultHeader();
131+
markdown.headerYml = markdown.getDefaultHeader();
132132
markdown.setup = new SetupChunk(getRLibraries());
133133
markdown.chunks = new ArrayList<>();
134134
markdown.chunks.add(createParamChunk(inputObjects, outputPrefix));
@@ -145,28 +145,6 @@ protected File createRmd(SequenceOutputHandler.JobContext ctx, List<SeuratObject
145145
return outfile;
146146
}
147147

148-
protected List<String> getDefaultHeader()
149-
{
150-
List<String> ret = new ArrayList<>();
151-
152-
ret.add("title: \"Single Cell Report\"");
153-
ret.add("date: \"`r Sys.Date()`\"");
154-
ret.add("output:");
155-
ret.add(" rmdformats::html_clean:");
156-
ret.add(" highlight: kate");
157-
ret.add(" self_contained: true");
158-
ret.add(" thumbnails: true");
159-
ret.add(" fig_width: 12");
160-
ret.add(" code_folding: hide");
161-
ret.add(" keep_md: true");
162-
ret.add(" gallery: true");
163-
ret.add(" lightbox: true");
164-
ret.add(" cache: false");
165-
ret.add(" df_print: paged");
166-
167-
return ret;
168-
}
169-
170148
protected List<Chunk> getChunks() throws PipelineJobException
171149
{
172150
List<Chunk> ret = new ArrayList<>();
@@ -183,9 +161,9 @@ public boolean requiresHashingOrCiteSeq()
183161

184162
public static class Markdown
185163
{
186-
List<Chunk> chunks;
187-
Chunk setup;
188-
List<String> headerYml;
164+
public List<Chunk> chunks;
165+
public Chunk setup;
166+
public List<String> headerYml;
189167

190168
public void print(PrintWriter out)
191169
{
@@ -196,6 +174,28 @@ public void print(PrintWriter out)
196174

197175
chunks.forEach(chunk -> chunk.print(out));
198176
}
177+
178+
public List<String> getDefaultHeader()
179+
{
180+
List<String> ret = new ArrayList<>();
181+
182+
ret.add("title: \"Single Cell Report\"");
183+
ret.add("date: \"`r Sys.Date()`\"");
184+
ret.add("output:");
185+
ret.add(" rmdformats::html_clean:");
186+
ret.add(" highlight: kate");
187+
ret.add(" self_contained: true");
188+
ret.add(" thumbnails: true");
189+
ret.add(" fig_width: 12");
190+
ret.add(" code_folding: hide");
191+
ret.add(" keep_md: true");
192+
ret.add(" gallery: true");
193+
ret.add(" lightbox: true");
194+
ret.add(" cache: false");
195+
ret.add(" df_print: paged");
196+
197+
return ret;
198+
}
199199
}
200200

201201
protected void executeR(SequenceOutputHandler.JobContext ctx, File rmd, String outputPrefix) throws PipelineJobException
@@ -383,11 +383,17 @@ public static class Chunk
383383
List<String> bodyLines;
384384

385385
public Chunk(String chunkName, @Nullable String header, @Nullable String extraText, List<String> bodyLines)
386+
{
387+
this(chunkName, header, extraText, bodyLines, null);
388+
}
389+
390+
public Chunk(String chunkName, @Nullable String header, @Nullable String extraText, List<String> bodyLines, String chunkOpts)
386391
{
387392
this.chunkName = chunkName;
388393
this.extraText = extraText;
389394
this.header = header;
390395
this.bodyLines = new ArrayList<>(bodyLines);
396+
this.chunkOpts = chunkOpts;
391397
}
392398

393399
public void print(PrintWriter out)
@@ -423,4 +429,13 @@ public SetupChunk(Collection<String> libraries)
423429
chunkOpts = "include=FALSE";
424430
}
425431
}
432+
433+
public static class SessionInfoChunk extends Chunk
434+
{
435+
public SessionInfoChunk()
436+
{
437+
super("sessionInfo", "Session Info", null, new ArrayList<>());
438+
bodyLines.add("sessionInfo()");
439+
}
440+
}
426441
}

singlecell/src/org/labkey/singlecell/analysis/ProcessSingleCellHandler.java

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,18 @@
3232
import org.labkey.api.util.FileType;
3333
import org.labkey.api.util.FileUtil;
3434
import org.labkey.api.view.ActionURL;
35+
import org.labkey.api.writer.PrintWriters;
3536
import org.labkey.singlecell.SingleCellModule;
3637
import org.labkey.singlecell.pipeline.singlecell.AbstractCellMembraneStep;
3738
import org.labkey.singlecell.pipeline.singlecell.PrepareRawCounts;
3839

3940
import java.io.File;
4041
import java.io.IOException;
42+
import java.io.PrintWriter;
4143
import java.util.ArrayList;
4244
import java.util.Arrays;
4345
import java.util.Collection;
46+
import java.util.Collections;
4447
import java.util.Date;
4548
import java.util.HashMap;
4649
import java.util.HashSet;
@@ -347,11 +350,30 @@ else if (step.createsSeuratObjects())
347350
}
348351

349352
//process with pandoc
350-
List<String> lines = new ArrayList<>();
351-
List<String> markdownNames = _resumer.getMarkdownsInOrder().stream().map(File::getName).collect(Collectors.toList());
352-
lines.add("knitr::pandoc(input = c('" + StringUtils.join(markdownNames, "','") + "'))");
353+
AbstractSingleCellPipelineStep.Markdown finalMarkdown = new AbstractSingleCellPipelineStep.Markdown();
354+
finalMarkdown.headerYml = finalMarkdown.getDefaultHeader();
355+
finalMarkdown.chunks = new ArrayList<>();
356+
for (File markdown : _resumer.getMarkdownsInOrder())
357+
{
358+
finalMarkdown.chunks.add(new AbstractSingleCellPipelineStep.Chunk(null, null, null, Collections.emptyList(), "child='" + markdown.getName() + "'"));
359+
}
360+
finalMarkdown.chunks.add(new AbstractSingleCellPipelineStep.SessionInfoChunk());
353361

362+
File finalMarkdownFile = new File(ctx.getOutputDir(), "final.rmd");
363+
try (PrintWriter writer = PrintWriters.getPrintWriter(finalMarkdownFile))
364+
{
365+
finalMarkdown.print(writer);
366+
}
367+
catch (IOException e)
368+
{
369+
throw new PipelineJobException(e);
370+
}
371+
372+
File finalHtml = new File(ctx.getOutputDir(), "finalHtml.html");
373+
List<String> lines = new ArrayList<>();
374+
lines.add("rmarkdown::render(output_file = '" + finalHtml.getName() + "', input = '" + finalMarkdownFile.getName() + "', intermediates_dir = '/work')");
354375
AbstractSingleCellPipelineStep.executeR(ctx, AbstractCellMembraneStep.CONTINAER_NAME, "pandoc", lines);
376+
_resumer.getFileManager().addIntermediateFile(finalMarkdownFile);
355377

356378
for (SingleCellStep.SeuratObjectWrapper output : currentFiles)
357379
{
@@ -372,9 +394,9 @@ else if (step.createsSeuratObjects())
372394
}
373395
else
374396
{
375-
SequenceOutputFile o = inputFiles.get(id);
376-
so.setLibrary_id(o.getLibrary_id());
377-
so.setReadset(o.getReadset());
397+
SequenceOutputFile o1 = inputMap.get(id);
398+
so.setLibrary_id(o1.getLibrary_id());
399+
so.setReadset(o1.getReadset());
378400
}
379401
}
380402
catch (NumberFormatException e)
@@ -384,6 +406,17 @@ else if (step.createsSeuratObjects())
384406
}
385407

386408
_resumer.getFileManager().addSequenceOutput(so);
409+
410+
// This could be a little confusing, but add one record out seurat output, even though there is one HTML file::
411+
SequenceOutputFile o = new SequenceOutputFile();
412+
o.setCategory("Seurat Report");
413+
o.setContainer(ctx.getJob().getContainer().getId());
414+
o.setFile(finalHtml);
415+
o.setLibrary_id(so.getLibrary_id());
416+
o.setReadset(so.getReadset());
417+
o.setName("Seurat Report: " + so.getName());
418+
419+
_resumer.getFileManager().addSequenceOutput(o);
387420
}
388421

389422
_resumer.markComplete(ctx);

0 commit comments

Comments
 (0)