Skip to content

Commit ec490bd

Browse files
committed
Allow pbmv handle to copy inputs locally
1 parent f19c774 commit ec490bd

File tree

1 file changed

+42
-5
lines changed

1 file changed

+42
-5
lines changed

SequenceAnalysis/src/org/labkey/sequenceanalysis/run/analysis/PbsvJointCallingHandler.java

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.labkey.sequenceanalysis.run.analysis;
22

3+
import org.apache.commons.io.FileUtils;
34
import org.json.JSONObject;
45
import org.labkey.api.module.ModuleLoader;
56
import org.labkey.api.pipeline.PipelineJob;
@@ -16,14 +17,13 @@
1617
import org.labkey.api.sequenceanalysis.run.SimpleScriptWrapper;
1718
import org.labkey.api.util.FileType;
1819
import org.labkey.sequenceanalysis.SequenceAnalysisModule;
19-
import org.labkey.sequenceanalysis.run.util.BgzipRunner;
2020

2121
import java.io.File;
2222
import java.io.IOException;
23-
import java.lang.reflect.InaccessibleObjectException;
2423
import java.util.ArrayList;
2524
import java.util.Arrays;
2625
import java.util.List;
26+
import java.util.stream.Collectors;
2727

2828
public class PbsvJointCallingHandler extends AbstractParameterizedOutputHandler<SequenceOutputHandler.SequenceOutputProcessor>
2929
{
@@ -35,7 +35,10 @@ public PbsvJointCallingHandler()
3535
ToolParameterDescriptor.create("fileName", "VCF Filename", "The name of the resulting file.", "textfield", new JSONObject(){{
3636
put("allowBlank", false);
3737
put("doNotIncludeInTemplates", true);
38-
}}, null)
38+
}}, null),
39+
ToolParameterDescriptor.create("doCopyLocal", "Copy Inputs Locally", "If checked, the input file(s) willbe copied to the job working directory.", "checkbox", new JSONObject(){{
40+
put("checked", true);
41+
}}, true)
3942
));
4043
}
4144

@@ -74,6 +77,40 @@ public void processFilesOnWebserver(PipelineJob job, SequenceAnalysisJobSupport
7477
@Override
7578
public void processFilesRemote(List<SequenceOutputFile> inputFiles, JobContext ctx) throws UnsupportedOperationException, PipelineJobException
7679
{
80+
List<File> inputs = inputFiles.stream().map(SequenceOutputFile::getFile).collect(Collectors.toList());
81+
if (ctx.getParams().optBoolean("doCopyLocal", false))
82+
{
83+
ctx.getLogger().info("Copying inputs locally");
84+
try
85+
{
86+
List<File> copiedInputs = new ArrayList<>();
87+
for (File f : inputs)
88+
{
89+
File copied = new File(ctx.getWorkingDirectory(), f.getName());
90+
if (copiedInputs.contains(copied))
91+
{
92+
throw new PipelineJobException("Duplicate input filenames, cannot use with copyLocally option: " + copied.getName());
93+
}
94+
95+
if (copied.exists())
96+
{
97+
copied.delete();
98+
}
99+
100+
FileUtils.copyFile(f, copied);
101+
copiedInputs.add(copied);
102+
103+
ctx.getFileManager().addIntermediateFile(copied);
104+
}
105+
106+
inputs = copiedInputs;
107+
}
108+
catch (IOException e)
109+
{
110+
throw new PipelineJobException(e);
111+
}
112+
}
113+
77114
List<String> args = new ArrayList<>();
78115
args.add(getExe().getPath());
79116
args.add("call");
@@ -88,8 +125,8 @@ public void processFilesRemote(List<SequenceOutputFile> inputFiles, JobContext c
88125
ReferenceGenome genome = ctx.getSequenceSupport().getCachedGenomes().iterator().next();
89126
args.add(genome.getWorkingFastaFile().getPath());
90127

91-
inputFiles.forEach(f -> {
92-
args.add(f.getFile().getPath());
128+
inputs.forEach(f -> {
129+
args.add(f.getPath());
93130
});
94131

95132
String fileName = ctx.getParams().getString("fileName");

0 commit comments

Comments
 (0)