|
| 1 | +package org.labkey.sequenceanalysis.run.variant; |
| 2 | + |
| 3 | +import htsjdk.samtools.util.Interval; |
| 4 | +import org.apache.logging.log4j.Logger; |
| 5 | +import org.jetbrains.annotations.Nullable; |
| 6 | +import org.labkey.api.pipeline.PipelineJobException; |
| 7 | +import org.labkey.api.sequenceanalysis.SequenceAnalysisService; |
| 8 | +import org.labkey.api.sequenceanalysis.pipeline.AbstractVariantProcessingStepProvider; |
| 9 | +import org.labkey.api.sequenceanalysis.pipeline.CommandLineParam; |
| 10 | +import org.labkey.api.sequenceanalysis.pipeline.PipelineContext; |
| 11 | +import org.labkey.api.sequenceanalysis.pipeline.PipelineStep; |
| 12 | +import org.labkey.api.sequenceanalysis.pipeline.PipelineStepProvider; |
| 13 | +import org.labkey.api.sequenceanalysis.pipeline.ReferenceGenome; |
| 14 | +import org.labkey.api.sequenceanalysis.pipeline.ToolParameterDescriptor; |
| 15 | +import org.labkey.api.sequenceanalysis.pipeline.VariantProcessingStep; |
| 16 | +import org.labkey.api.sequenceanalysis.pipeline.VariantProcessingStepOutputImpl; |
| 17 | +import org.labkey.api.sequenceanalysis.run.AbstractCommandPipelineStep; |
| 18 | +import org.labkey.api.sequenceanalysis.run.AbstractDiscvrSeqWrapper; |
| 19 | +import org.labkey.sequenceanalysis.util.SequenceUtil; |
| 20 | + |
| 21 | +import java.io.File; |
| 22 | +import java.util.ArrayList; |
| 23 | +import java.util.Arrays; |
| 24 | +import java.util.List; |
| 25 | + |
| 26 | +public class SplitVcfBySamplesStep extends AbstractCommandPipelineStep<SplitVcfBySamplesStep.Wrapper> implements VariantProcessingStep |
| 27 | +{ |
| 28 | + public SplitVcfBySamplesStep(PipelineStepProvider<?> provider, PipelineContext ctx) |
| 29 | + { |
| 30 | + super(provider, ctx, new Wrapper(ctx.getLogger())); |
| 31 | + } |
| 32 | + |
| 33 | + public static class Provider extends AbstractVariantProcessingStepProvider<SelectSamplesStep> |
| 34 | + { |
| 35 | + public Provider() |
| 36 | + { |
| 37 | + super("SplitVcfBySamples", "Split VCF By Sample", "DISCVRseq", "A VCF will be generated containing only the samples specified below.", Arrays.asList( |
| 38 | + ToolParameterDescriptor.createCommandLineParam(CommandLineParam.create("--samplesPerVcf"), "samplesPerVcf", "Samples Per VCF", "The max number of samples to write per VCF", "ldk-integerfield", null, null), |
| 39 | + ToolParameterDescriptor.createCommandLineParam(CommandLineParam.create("--minAllowableInFinalVcf"), "minAllowableInFinalVcf", "Min Allowable in Final VCF", "If the final VCF in the split has fewer than this number of samples, it will be merged with the second to last VCF", "ldk-integerfield", null, null) |
| 40 | + ), null, null); |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + public PipelineStep create(PipelineContext context) |
| 45 | + { |
| 46 | + return new SplitVcfBySamplesStep(this, context); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + public Output processVariants(File inputVCF, File outputDirectory, ReferenceGenome genome, @Nullable List<Interval> intervals) throws PipelineJobException |
| 52 | + { |
| 53 | + VariantProcessingStepOutputImpl output = new VariantProcessingStepOutputImpl(); |
| 54 | + getPipelineCtx().getLogger().info("Running SplitVcfBySamples"); |
| 55 | + |
| 56 | + List<String> args = new ArrayList<>(getWrapper().getBaseArgs()); |
| 57 | + args.add("SplitVcfBySamples"); |
| 58 | + args.add("-V"); |
| 59 | + args.add(inputVCF.getPath()); |
| 60 | + args.add("-O"); |
| 61 | + args.add(outputDirectory.getPath()); |
| 62 | + |
| 63 | + args.addAll(getClientCommandArgs()); |
| 64 | + |
| 65 | + getWrapper().execute(args); |
| 66 | + |
| 67 | + output.addInput(inputVCF, "Input VCF"); |
| 68 | + |
| 69 | + String basename = SequenceAnalysisService.get().getUnzippedBaseName(inputVCF.getName()); |
| 70 | + for (File f : outputDirectory.listFiles()) |
| 71 | + { |
| 72 | + if (!f.getName().equals(inputVCF.getName()) && f.getName().startsWith(basename) && SequenceUtil.FILETYPE.vcf.getFileType().isType(f)) |
| 73 | + { |
| 74 | + output.addOutput(f, "Subset VCF"); |
| 75 | + output.addSequenceOutput(f, "Subset VCF: " + f.getName(), "VCF", null, null, genome.getGenomeId(), null); |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + return output; |
| 80 | + } |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + public static class Wrapper extends AbstractDiscvrSeqWrapper |
| 85 | + { |
| 86 | + public Wrapper(Logger log) |
| 87 | + { |
| 88 | + super(log); |
| 89 | + } |
| 90 | + } |
| 91 | +} |
0 commit comments