|
1 | 1 | package org.labkey.singlecell.pipeline.singlecell; |
2 | 2 |
|
| 3 | +import au.com.bytecode.opencsv.CSVReader; |
3 | 4 | import org.json.old.JSONObject; |
| 5 | +import org.labkey.api.pipeline.PipelineJobException; |
| 6 | +import org.labkey.api.reader.Readers; |
| 7 | +import org.labkey.api.sequenceanalysis.SequenceOutputFile; |
4 | 8 | import org.labkey.api.sequenceanalysis.pipeline.AbstractPipelineStepProvider; |
5 | 9 | import org.labkey.api.sequenceanalysis.pipeline.PipelineContext; |
| 10 | +import org.labkey.api.sequenceanalysis.pipeline.SequenceOutputHandler; |
6 | 11 | import org.labkey.api.singlecell.pipeline.SeuratToolParameter; |
7 | 12 | import org.labkey.api.singlecell.pipeline.SingleCellStep; |
8 | 13 |
|
| 14 | +import java.io.File; |
| 15 | +import java.io.IOException; |
9 | 16 | import java.util.Arrays; |
| 17 | +import java.util.List; |
| 18 | +import java.util.Set; |
| 19 | +import java.util.stream.Collectors; |
10 | 20 |
|
11 | 21 | public class RunSDA extends AbstractCellMembraneStep |
12 | 22 | { |
@@ -68,6 +78,62 @@ public String getFileSuffix() |
68 | 78 | { |
69 | 79 | return "sda"; |
70 | 80 | } |
| 81 | + |
| 82 | + @Override |
| 83 | + public Output execute(SequenceOutputHandler.JobContext ctx, List<SeuratObjectWrapper> inputObjects, String outputPrefix) throws PipelineJobException |
| 84 | + { |
| 85 | + Output output = super.execute(ctx, inputObjects, outputPrefix); |
| 86 | + |
| 87 | + File saved = new File(ctx.getOutputDir(), "sdaFiles.txt"); |
| 88 | + if (!saved.exists()) |
| 89 | + { |
| 90 | + throw new PipelineJobException("Unable to find file: " + saved.getPath()); |
| 91 | + } |
| 92 | + |
| 93 | + try (CSVReader reader = new CSVReader(Readers.getReader(saved), '\t')) |
| 94 | + { |
| 95 | + String[] line; |
| 96 | + while ((line = reader.readNext()) != null) |
| 97 | + { |
| 98 | + File rds = new File(ctx.getOutputDir(), line[1]); |
| 99 | + if (!rds.exists()) |
| 100 | + { |
| 101 | + throw new PipelineJobException("Unable to find file: " + rds.getPath()); |
| 102 | + } |
| 103 | + |
| 104 | + final String datasetId = line[0]; |
| 105 | + Set<SeuratObjectWrapper> wrappers = inputObjects.stream().filter(x -> datasetId.equals(x.getDatasetId())).collect(Collectors.toSet()); |
| 106 | + if (wrappers.size() == 0) |
| 107 | + { |
| 108 | + throw new PipelineJobException("Unable to find seurat object wrapper for: " + datasetId); |
| 109 | + } |
| 110 | + else if (wrappers.size() > 1) |
| 111 | + { |
| 112 | + throw new PipelineJobException("More than one seurat object wrapper matched: " + datasetId + ", found: " + wrappers.stream().map(SeuratObjectWrapper::getDatasetId).collect(Collectors.joining(", "))); |
| 113 | + } |
| 114 | + |
| 115 | + SeuratObjectWrapper wrapper = wrappers.iterator().next(); |
| 116 | + |
| 117 | + SequenceOutputFile so = new SequenceOutputFile(); |
| 118 | + so.setFile(rds); |
| 119 | + so.setCategory("SDA Results"); |
| 120 | + so.setLibrary_id(ctx.getSequenceSupport().getCachedGenomes().iterator().next().getGenomeId()); |
| 121 | + so.setReadset(wrapper.getReadsetId()); |
| 122 | + so.setName(wrapper.getDatasetName() == null ? wrapper.getDatasetId() : wrapper.getDatasetName() + ": SDA Analysis"); |
| 123 | + |
| 124 | + ctx.getFileManager().addSequenceOutput(so); |
| 125 | + } |
| 126 | + } |
| 127 | + catch (IOException e) |
| 128 | + { |
| 129 | + throw new PipelineJobException(e); |
| 130 | + } |
| 131 | + |
| 132 | + ctx.getFileManager().addIntermediateFile(saved); |
| 133 | + |
| 134 | + return output; |
| 135 | + } |
| 136 | + |
71 | 137 | } |
72 | 138 |
|
73 | 139 |
|
0 commit comments