Skip to content

Commit 0b9c1cb

Browse files
committed
Resolve merge conflicts
2 parents d50b66d + 6790e2d commit 0b9c1cb

File tree

24 files changed

+1971
-420
lines changed

24 files changed

+1971
-420
lines changed

SequenceAnalysis/api-src/org/labkey/api/sequenceanalysis/run/AbstractCommandWrapper.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ abstract public class AbstractCommandWrapper implements CommandWrapper
4444
private File _outputDir = null;
4545
private File _workingDir = null;
4646
private Logger _log;
47+
private boolean _logPath = false;
4748
private Level _logLevel = Level.DEBUG;
4849
private boolean _warnNonZeroExits = true;
4950
private boolean _throwNonZeroExits = true;
@@ -205,9 +206,11 @@ private void setPath(ProcessBuilder pb)
205206
{
206207
String path = System.getenv("PATH");
207208

208-
getLogger().debug("Existing PATH: " + path);
209-
getLogger().debug("toolDir: " + toolDir);
210-
209+
if (_logPath)
210+
{
211+
getLogger().debug("Existing PATH: " + path);
212+
getLogger().debug("toolDir: " + toolDir);
213+
}
211214

212215
if (path == null)
213216
{
@@ -229,11 +232,19 @@ private void setPath(ProcessBuilder pb)
229232
path = fileExe.getParent() + File.pathSeparatorChar + path;
230233
}
231234

232-
getLogger().debug("using path: " + path);
235+
if (_logPath)
236+
{
237+
getLogger().debug("using path: " + path);
238+
}
233239
pb.environment().put("PATH", path);
234240
}
235241
}
236242

243+
public void setLogPath(boolean logPath)
244+
{
245+
_logPath = logPath;
246+
}
247+
237248
public void setOutputDir(File outputDir)
238249
{
239250
_outputDir = outputDir;

SequenceAnalysis/pipeline_code/extra_tools_install.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,17 @@ then
319319
else
320320
echo "Already installed"
321321
fi
322+
323+
if [[ ! -e ${LKTOOLS_DIR}/sawfish || ! -z $FORCE_REINSTALL ]];
324+
then
325+
echo "Cleaning up previous installs"
326+
rm -Rf $LKTOOLS_DIR/sawfish*
327+
328+
wget https://github.com/PacificBiosciences/sawfish/releases/download/v2.0.0/sawfish-v2.0.0-x86_64-unknown-linux-gnu.tar.gz
329+
tar -xzf sawfish-v2.0.0-x86_64-unknown-linux-gnu.tar.gz
330+
331+
mv sawfish-v2.0.0-x86_64-unknown-linux-gnu $LKTOOLS_DIR/
332+
ln -s $LKTOOLS_DIR/sawfish-v2.0.0/bin/sawfish $LKTOOLS_DIR/
333+
else
334+
echo "Already installed"
335+
fi

SequenceAnalysis/src/org/labkey/sequenceanalysis/SequenceAnalysisModule.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@
123123
import org.labkey.sequenceanalysis.run.analysis.PbsvAnalysis;
124124
import org.labkey.sequenceanalysis.run.analysis.PbsvJointCallingHandler;
125125
import org.labkey.sequenceanalysis.run.analysis.PindelAnalysis;
126+
import org.labkey.sequenceanalysis.run.analysis.SawfishAnalysis;
127+
import org.labkey.sequenceanalysis.run.analysis.SawfishJointCallingHandler;
126128
import org.labkey.sequenceanalysis.run.analysis.SequenceBasedTypingAnalysis;
127129
import org.labkey.sequenceanalysis.run.analysis.SnpCountAnalysis;
128130
import org.labkey.sequenceanalysis.run.analysis.SubreadAnalysis;
@@ -342,6 +344,7 @@ public static void registerPipelineSteps()
342344
SequencePipelineService.get().registerPipelineStep(new PindelAnalysis.Provider());
343345
SequencePipelineService.get().registerPipelineStep(new PbsvAnalysis.Provider());
344346
SequencePipelineService.get().registerPipelineStep(new GenrichStep.Provider());
347+
SequencePipelineService.get().registerPipelineStep(new SawfishAnalysis.Provider());
345348

346349
SequencePipelineService.get().registerPipelineStep(new PARalyzerAnalysis.Provider());
347350
SequencePipelineService.get().registerPipelineStep(new RnaSeQCStep.Provider());
@@ -400,6 +403,7 @@ public static void registerPipelineSteps()
400403
SequenceAnalysisService.get().registerFileHandler(new NextCladeHandler());
401404
SequenceAnalysisService.get().registerFileHandler(new ConvertToCramHandler());
402405
SequenceAnalysisService.get().registerFileHandler(new PbsvJointCallingHandler());
406+
SequenceAnalysisService.get().registerFileHandler(new SawfishJointCallingHandler());
403407
SequenceAnalysisService.get().registerFileHandler(new DeepVariantHandler());
404408
SequenceAnalysisService.get().registerFileHandler(new GLNexusHandler());
405409
SequenceAnalysisService.get().registerFileHandler(new ParagraphStep());
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package org.labkey.sequenceanalysis.run.analysis;
2+
3+
import org.apache.logging.log4j.Logger;
4+
import org.jetbrains.annotations.Nullable;
5+
import org.labkey.api.pipeline.PipelineJobException;
6+
import org.labkey.api.sequenceanalysis.model.AnalysisModel;
7+
import org.labkey.api.sequenceanalysis.model.Readset;
8+
import org.labkey.api.sequenceanalysis.pipeline.AbstractAnalysisStepProvider;
9+
import org.labkey.api.sequenceanalysis.pipeline.AbstractPipelineStep;
10+
import org.labkey.api.sequenceanalysis.pipeline.AnalysisOutputImpl;
11+
import org.labkey.api.sequenceanalysis.pipeline.AnalysisStep;
12+
import org.labkey.api.sequenceanalysis.pipeline.PipelineContext;
13+
import org.labkey.api.sequenceanalysis.pipeline.PipelineStepProvider;
14+
import org.labkey.api.sequenceanalysis.pipeline.ReferenceGenome;
15+
import org.labkey.api.sequenceanalysis.pipeline.SamtoolsIndexer;
16+
import org.labkey.api.sequenceanalysis.pipeline.SamtoolsRunner;
17+
import org.labkey.api.sequenceanalysis.pipeline.SequencePipelineService;
18+
import org.labkey.api.sequenceanalysis.run.SimpleScriptWrapper;
19+
import org.labkey.sequenceanalysis.util.SequenceUtil;
20+
21+
import java.io.File;
22+
import java.util.ArrayList;
23+
import java.util.List;
24+
25+
public class SawfishAnalysis extends AbstractPipelineStep implements AnalysisStep
26+
{
27+
public SawfishAnalysis(PipelineStepProvider<?> provider, PipelineContext ctx)
28+
{
29+
super(provider, ctx);
30+
}
31+
32+
public static class Provider extends AbstractAnalysisStepProvider<SawfishAnalysis>
33+
{
34+
public Provider()
35+
{
36+
super("sawfish", "Sawfish Analysis", null, "This will run sawfish SV dicvoery and calling on the selected BAMs", List.of(), null, null);
37+
}
38+
39+
40+
@Override
41+
public SawfishAnalysis create(PipelineContext ctx)
42+
{
43+
return new SawfishAnalysis(this, ctx);
44+
}
45+
}
46+
47+
@Override
48+
public Output performAnalysisPerSampleRemote(Readset rs, File inputBam, ReferenceGenome referenceGenome, File outputDir) throws PipelineJobException
49+
{
50+
AnalysisOutputImpl output = new AnalysisOutputImpl();
51+
52+
List<String> args = new ArrayList<>();
53+
args.add(getExe().getPath());
54+
args.add("discover");
55+
56+
args.add("--bam");
57+
args.add(inputBam.getPath());
58+
59+
// NOTE: sawfish stores the absolute path of the FASTA in the output JSON, so dont rely on working copies:
60+
args.add("--ref");
61+
args.add(referenceGenome.getSourceFastaFile().getPath());
62+
63+
File svOutDir = new File(outputDir, "sawfish");
64+
args.add("--output-dir");
65+
args.add(svOutDir.getPath());
66+
67+
Integer maxThreads = SequencePipelineService.get().getMaxThreads(getPipelineCtx().getLogger());
68+
if (maxThreads != null)
69+
{
70+
args.add("--threads");
71+
args.add(String.valueOf(maxThreads));
72+
}
73+
74+
File bcf = new File(svOutDir, "candidate.sv.bcf");
75+
File bcfIdx = new File(bcf.getPath() + ".csi");
76+
if (bcfIdx.exists())
77+
{
78+
getPipelineCtx().getLogger().debug("BCF index already exists, reusing output");
79+
}
80+
else
81+
{
82+
new SimpleScriptWrapper(getPipelineCtx().getLogger()).execute(args);
83+
}
84+
85+
if (!bcf.exists())
86+
{
87+
throw new PipelineJobException("Unable to find file: " + bcf.getPath());
88+
}
89+
90+
output.addSequenceOutput(bcf, rs.getName() + ": sawfish", "Sawfish SV Discovery", rs.getReadsetId(), null, referenceGenome.getGenomeId(), null);
91+
92+
return output;
93+
}
94+
95+
@Override
96+
public Output performAnalysisPerSampleLocal(AnalysisModel model, File inputBam, File referenceFasta, File outDir) throws PipelineJobException
97+
{
98+
return null;
99+
}
100+
101+
private File getExe()
102+
{
103+
return SequencePipelineService.get().getExeForPackage("SAWFISHPATH", "sawfish");
104+
}
105+
}
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
package org.labkey.sequenceanalysis.run.analysis;
2+
3+
import org.apache.commons.io.FileUtils;
4+
import org.json.JSONObject;
5+
import org.labkey.api.module.ModuleLoader;
6+
import org.labkey.api.pipeline.PipelineJob;
7+
import org.labkey.api.pipeline.PipelineJobException;
8+
import org.labkey.api.pipeline.RecordedAction;
9+
import org.labkey.api.sequenceanalysis.SequenceAnalysisService;
10+
import org.labkey.api.sequenceanalysis.SequenceOutputFile;
11+
import org.labkey.api.sequenceanalysis.pipeline.AbstractParameterizedOutputHandler;
12+
import org.labkey.api.sequenceanalysis.pipeline.ReferenceGenome;
13+
import org.labkey.api.sequenceanalysis.pipeline.SequenceAnalysisJobSupport;
14+
import org.labkey.api.sequenceanalysis.pipeline.SequenceOutputHandler;
15+
import org.labkey.api.sequenceanalysis.pipeline.SequencePipelineService;
16+
import org.labkey.api.sequenceanalysis.pipeline.ToolParameterDescriptor;
17+
import org.labkey.api.sequenceanalysis.run.SimpleScriptWrapper;
18+
import org.labkey.sequenceanalysis.SequenceAnalysisModule;
19+
import org.labkey.sequenceanalysis.util.SequenceUtil;
20+
21+
import java.io.File;
22+
import java.io.IOException;
23+
import java.util.ArrayList;
24+
import java.util.Arrays;
25+
import java.util.LinkedHashSet;
26+
import java.util.List;
27+
import java.util.stream.Collectors;
28+
29+
public class SawfishJointCallingHandler extends AbstractParameterizedOutputHandler<SequenceOutputHandler.SequenceOutputProcessor>
30+
{
31+
private static final String OUTPUT_CATEGORY = "Sawfish VCF";
32+
33+
public SawfishJointCallingHandler()
34+
{
35+
super(ModuleLoader.getInstance().getModule(SequenceAnalysisModule.NAME), "Sawfish Joint-Call", "Runs sawfish joint-call, which jointly calls SVs from PacBio CCS data", new LinkedHashSet<>(List.of("sequenceanalysis/panel/VariantScatterGatherPanel.js")), Arrays.asList(
36+
ToolParameterDescriptor.create("fileName", "VCF Filename", "The name of the resulting file.", "textfield", new JSONObject(){{
37+
put("allowBlank", false);
38+
put("doNotIncludeInTemplates", true);
39+
}}, null)
40+
));
41+
}
42+
43+
@Override
44+
public boolean canProcess(SequenceOutputFile o)
45+
{
46+
return o.getFile() != null && SequenceUtil.FILETYPE.bcf.getFileType().isType(o.getFile());
47+
}
48+
49+
@Override
50+
public boolean doRunRemote()
51+
{
52+
return true;
53+
}
54+
55+
@Override
56+
public boolean doRunLocal()
57+
{
58+
return false;
59+
}
60+
61+
@Override
62+
public SequenceOutputProcessor getProcessor()
63+
{
64+
return new Processor();
65+
}
66+
67+
public static class Processor implements SequenceOutputProcessor
68+
{
69+
@Override
70+
public void processFilesOnWebserver(PipelineJob job, SequenceAnalysisJobSupport support, List<SequenceOutputFile> inputFiles, JSONObject params, File outputDir, List<RecordedAction> actions, List<SequenceOutputFile> outputsToCreate) throws UnsupportedOperationException, PipelineJobException
71+
{
72+
73+
}
74+
75+
@Override
76+
public void processFilesRemote(List<SequenceOutputFile> inputFiles, JobContext ctx) throws UnsupportedOperationException, PipelineJobException
77+
{
78+
List<File> filesToProcess = inputFiles.stream().map(SequenceOutputFile::getFile).collect(Collectors.toList());
79+
80+
ReferenceGenome genome = ctx.getSequenceSupport().getCachedGenomes().iterator().next();
81+
String outputBaseName = ctx.getParams().getString("fileName");
82+
if (!outputBaseName.toLowerCase().endsWith(".gz"))
83+
{
84+
outputBaseName = outputBaseName.replaceAll(".gz$", "");
85+
}
86+
87+
if (!outputBaseName.toLowerCase().endsWith(".vcf"))
88+
{
89+
outputBaseName = outputBaseName.replaceAll(".vcf$", "");
90+
}
91+
92+
File expectedFinalOutput = new File(ctx.getOutputDir(), outputBaseName + ".vcf.gz");
93+
94+
File ouputVcf = runSawfishCall(ctx, filesToProcess, genome, outputBaseName);
95+
96+
SequenceOutputFile so = new SequenceOutputFile();
97+
so.setName("Sawfish call: " + outputBaseName);
98+
so.setFile(ouputVcf);
99+
so.setCategory(OUTPUT_CATEGORY);
100+
so.setLibrary_id(genome.getGenomeId());
101+
102+
ctx.addSequenceOutput(so);
103+
}
104+
105+
private File runSawfishCall(JobContext ctx, List<File> inputs, ReferenceGenome genome, String outputBaseName) throws PipelineJobException
106+
{
107+
if (inputs.isEmpty())
108+
{
109+
throw new PipelineJobException("No inputs provided");
110+
}
111+
112+
List<String> args = new ArrayList<>();
113+
args.add(getExe().getPath());
114+
args.add("joint-call");
115+
116+
Integer maxThreads = SequencePipelineService.get().getMaxThreads(ctx.getLogger());
117+
if (maxThreads != null)
118+
{
119+
args.add("--threads");
120+
args.add(String.valueOf(maxThreads));
121+
}
122+
123+
for (File sample : inputs)
124+
{
125+
args.add("--sample");
126+
args.add(sample.getParentFile().getPath());
127+
}
128+
129+
File outDir = new File(ctx.getOutputDir(), "sawfish");
130+
args.add("--output-dir");
131+
args.add(outDir.getPath());
132+
133+
new SimpleScriptWrapper(ctx.getLogger()).execute(args);
134+
135+
File vcfOut = new File(outDir, "genotyped.sv.vcf.gz");
136+
if (!vcfOut.exists())
137+
{
138+
throw new PipelineJobException("Unable to find file: " + vcfOut.getPath());
139+
}
140+
141+
File vcfOutFinal = new File(ctx.getOutputDir(), outputBaseName + ".vcf.gz");
142+
143+
try
144+
{
145+
if (vcfOutFinal.exists())
146+
{
147+
vcfOutFinal.delete();
148+
}
149+
FileUtils.moveFile(vcfOut, vcfOutFinal);
150+
151+
File targetIndex = new File(vcfOutFinal.getPath() + ".tbi");
152+
if (targetIndex.exists())
153+
{
154+
targetIndex.delete();
155+
}
156+
157+
File origIndex = new File(vcfOut.getPath() + ".tbi");
158+
if (origIndex.exists())
159+
{
160+
FileUtils.moveFile(origIndex, targetIndex);
161+
}
162+
else
163+
{
164+
SequenceAnalysisService.get().ensureVcfIndex(vcfOutFinal, ctx.getLogger(), true);
165+
}
166+
}
167+
catch (IOException e)
168+
{
169+
throw new PipelineJobException(e);
170+
}
171+
172+
return vcfOutFinal;
173+
}
174+
175+
private File getExe()
176+
{
177+
return SequencePipelineService.get().getExeForPackage("SAWFISHPATH", "sawfish");
178+
}
179+
}
180+
}

0 commit comments

Comments
 (0)