|
1 | 1 | package org.labkey.sequenceanalysis.run.analysis; |
2 | 2 |
|
3 | 3 | import au.com.bytecode.opencsv.CSVReader; |
| 4 | +import au.com.bytecode.opencsv.CSVWriter; |
4 | 5 | import htsjdk.samtools.SAMFileHeader; |
5 | 6 | import org.apache.commons.lang3.StringUtils; |
6 | 7 | import org.apache.log4j.Logger; |
7 | 8 | import org.json.JSONObject; |
| 9 | +import org.labkey.api.data.CompareType; |
8 | 10 | import org.labkey.api.data.Container; |
9 | 11 | import org.labkey.api.data.DbScope; |
10 | 12 | import org.labkey.api.data.SimpleFilter; |
11 | 13 | import org.labkey.api.data.Table; |
12 | 14 | import org.labkey.api.data.TableInfo; |
| 15 | +import org.labkey.api.data.TableSelector; |
13 | 16 | import org.labkey.api.exp.api.ExperimentService; |
14 | 17 | import org.labkey.api.pipeline.PipelineJobException; |
15 | 18 | import org.labkey.api.query.FieldKey; |
|
25 | 28 | import org.labkey.api.sequenceanalysis.pipeline.PipelineStepProvider; |
26 | 29 | import org.labkey.api.sequenceanalysis.pipeline.ReferenceGenome; |
27 | 30 | import org.labkey.api.sequenceanalysis.pipeline.SamSorter; |
| 31 | +import org.labkey.api.sequenceanalysis.pipeline.SequenceAnalysisJobSupport; |
28 | 32 | import org.labkey.api.sequenceanalysis.pipeline.SequencePipelineService; |
29 | 33 | import org.labkey.api.sequenceanalysis.pipeline.ToolParameterDescriptor; |
30 | 34 | import org.labkey.api.sequenceanalysis.run.AbstractCommandPipelineStep; |
31 | 35 | import org.labkey.api.util.FileUtil; |
| 36 | +import org.labkey.api.util.PageFlowUtil; |
| 37 | +import org.labkey.api.writer.PrintWriters; |
32 | 38 | import org.labkey.sequenceanalysis.SequenceAnalysisSchema; |
33 | 39 | import org.labkey.sequenceanalysis.run.util.ImmunoGenotypingWrapper; |
34 | 40 | import org.labkey.sequenceanalysis.util.ReferenceLibraryHelperImpl; |
@@ -117,6 +123,26 @@ public static List<ToolParameterDescriptor> getDefaultParams(boolean includeExpo |
117 | 123 | return ret; |
118 | 124 | } |
119 | 125 |
|
| 126 | + @Override |
| 127 | + public void init(SequenceAnalysisJobSupport support) throws PipelineJobException |
| 128 | + { |
| 129 | + for (ReferenceGenome genome : support.getCachedGenomes()) |
| 130 | + { |
| 131 | + File output = getLineageMapFile(getPipelineCtx(), genome); |
| 132 | + try (CSVWriter writer = new CSVWriter(PrintWriters.getPrintWriter(output), '\t', CSVWriter.NO_QUOTE_CHARACTER)) |
| 133 | + { |
| 134 | + List<Integer> refNtIds = new TableSelector(SequenceAnalysisSchema.getInstance().getSchema().getTable(SequenceAnalysisSchema.TABLE_REF_LIBRARY_MEMBERS), PageFlowUtil.set("ref_nt_id"), new SimpleFilter(FieldKey.fromString("library_id"), genome.getGenomeId()), null).getArrayList(Integer.class); |
| 135 | + new TableSelector(SequenceAnalysisSchema.getInstance().getSchema().getTable(SequenceAnalysisSchema.TABLE_REF_NT_SEQUENCES), PageFlowUtil.set("rowid", "name", "lineage"), new SimpleFilter(FieldKey.fromString("rowid"), refNtIds, CompareType.IN), null).forEachResults(rs -> { |
| 136 | + writer.writeNext(new String[]{rs.getString(FieldKey.fromString("name")), rs.getString(FieldKey.fromString("lineage"))}); |
| 137 | + }); |
| 138 | + } |
| 139 | + catch (IOException e) |
| 140 | + { |
| 141 | + throw new PipelineJobException(e); |
| 142 | + } |
| 143 | + } |
| 144 | + } |
| 145 | + |
120 | 146 | @Override |
121 | 147 | public Output performAnalysisPerSampleLocal(AnalysisModel model, File inputBam, File referenceFasta, File outDir) throws PipelineJobException |
122 | 148 | { |
@@ -152,6 +178,11 @@ public Output performAnalysisPerSampleLocal(AnalysisModel model, File inputBam, |
152 | 178 | return null; |
153 | 179 | } |
154 | 180 |
|
| 181 | + private File getLineageMapFile(PipelineContext ctx, ReferenceGenome referenceGenome) |
| 182 | + { |
| 183 | + return new File(getPipelineCtx().getSourceDirectory(), referenceGenome.getGenomeId() + "_lineageMap.txt"); |
| 184 | + } |
| 185 | + |
155 | 186 | @Override |
156 | 187 | public Output performAnalysisPerSampleRemote(Readset rs, File inputBam, ReferenceGenome referenceGenome, File outputDir) throws PipelineJobException |
157 | 188 | { |
@@ -179,7 +210,7 @@ public Output performAnalysisPerSampleRemote(Readset rs, File inputBam, Referenc |
179 | 210 | } |
180 | 211 |
|
181 | 212 | List<String> options = new ArrayList<>(); |
182 | | - File lineageMapFile = new File(getPipelineCtx().getSourceDirectory(), referenceGenome.getGenomeId() + "_lineageMap.txt"); |
| 213 | + File lineageMapFile = getLineageMapFile(getPipelineCtx(), referenceGenome); |
183 | 214 | if (lineageMapFile.exists()) |
184 | 215 | { |
185 | 216 | options.add("-referenceToLineageFile"); |
|
0 commit comments