Skip to content

Commit 4611fc8

Browse files
committed
Add option to sort VCFs prior to merge
1 parent b471ef0 commit 4611fc8

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

SequenceAnalysis/src/org/labkey/sequenceanalysis/run/variant/MergeVcfsAndGenotypesHandler.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.labkey.api.sequenceanalysis.pipeline.ReferenceGenome;
1111
import org.labkey.api.sequenceanalysis.pipeline.SequenceAnalysisJobSupport;
1212
import org.labkey.api.sequenceanalysis.pipeline.SequenceOutputHandler;
13+
import org.labkey.api.sequenceanalysis.pipeline.SequencePipelineService;
1314
import org.labkey.api.sequenceanalysis.pipeline.ToolParameterDescriptor;
1415
import org.labkey.api.util.PageFlowUtil;
1516
import org.labkey.sequenceanalysis.SequenceAnalysisModule;
@@ -31,7 +32,8 @@ public class MergeVcfsAndGenotypesHandler extends AbstractParameterizedOutputHan
3132
public MergeVcfsAndGenotypesHandler()
3233
{
3334
super(ModuleLoader.getInstance().getModule(SequenceAnalysisModule.class), "Merge Vcfs And Genotypes", "Combine multiple VCF files", null, List.of(
34-
ToolParameterDescriptor.create("basename", "Output File Name", "This will be used as the name for the output VCF.", "textfield", null, "")
35+
ToolParameterDescriptor.create("basename", "Output File Name", "This will be used as the name for the output VCF.", "textfield", null, ""),
36+
ToolParameterDescriptor.create("doSort", "Sort Inputs", "If checked, the input VCFs will be sorted prior to merge. This is usually not necessary", "checkbox", null, false)
3537
));
3638
}
3739

@@ -78,6 +80,7 @@ public void processFilesOnWebserver(PipelineJob job, SequenceAnalysisJobSupport
7880
public void processFilesRemote(List<SequenceOutputFile> inputFiles, JobContext ctx) throws UnsupportedOperationException, PipelineJobException
7981
{
8082
File outputVcf = new File(ctx.getOutputDir(), ctx.getParams().getString("basename") + ".combined.vcf.gz");
83+
boolean doSort = ctx.getParams().optBoolean("doSort", false);
8184

8285
RecordedAction action = new RecordedAction(getName());
8386

@@ -90,7 +93,7 @@ public void processFilesRemote(List<SequenceOutputFile> inputFiles, JobContext c
9093

9194
List<File> inputVCFs = new ArrayList<>();
9295
inputFiles.forEach(x -> inputVCFs.add(x.getFile()));
93-
inputFiles.forEach(x -> action.addInput(x.getFile(), "Combined VCF"));
96+
inputFiles.forEach(x -> action.addInput(x.getFile(), "Input VCF"));
9497

9598
ReferenceGenome genome = ctx.getSequenceSupport().getCachedGenome(genomeIds.iterator().next());
9699
new MergeVcfsAndGenotypesWrapper(ctx.getLogger()).execute(genome.getWorkingFastaFile(), inputVCFs, outputVcf, null);
@@ -99,6 +102,15 @@ public void processFilesRemote(List<SequenceOutputFile> inputFiles, JobContext c
99102
throw new PipelineJobException("unable to find output: " + outputVcf.getPath());
100103
}
101104

105+
if (doSort)
106+
{
107+
ctx.getLogger().info("Sorting VCFs");
108+
for (File f : inputVCFs)
109+
{
110+
SequencePipelineService.get().sortVcf(f, null, genome.getSequenceDictionary(), ctx.getLogger());
111+
}
112+
}
113+
102114
action.addOutput(outputVcf, "Combined VCF", false);
103115
SequenceOutputFile so = new SequenceOutputFile();
104116
so.setName(outputVcf.getName());

0 commit comments

Comments
 (0)