forked from BimberLab/DiscvrLabKeyModules
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSelectSNVsStep.java
More file actions
107 lines (91 loc) · 4.59 KB
/
SelectSNVsStep.java
File metadata and controls
107 lines (91 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package org.labkey.sequenceanalysis.run.variant;
import htsjdk.samtools.util.Interval;
import htsjdk.variant.variantcontext.VariantContext;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Nullable;
import org.json.JSONObject;
import org.labkey.api.pipeline.PipelineJobException;
import org.labkey.api.sequenceanalysis.pipeline.AbstractVariantProcessingStepProvider;
import org.labkey.api.sequenceanalysis.pipeline.PipelineContext;
import org.labkey.api.sequenceanalysis.pipeline.PipelineStepProvider;
import org.labkey.api.sequenceanalysis.pipeline.ReferenceGenome;
import org.labkey.api.sequenceanalysis.pipeline.ToolParameterDescriptor;
import org.labkey.api.sequenceanalysis.pipeline.VariantProcessingStep;
import org.labkey.api.sequenceanalysis.pipeline.VariantProcessingStepOutputImpl;
import org.labkey.api.sequenceanalysis.run.AbstractCommandPipelineStep;
import org.labkey.api.sequenceanalysis.run.SelectVariantsWrapper;
import org.labkey.api.util.PageFlowUtil;
import org.labkey.sequenceanalysis.pipeline.SequenceTaskHelper;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* User: bimber
* Date: 6/15/2014
* Time: 12:39 PM
*/
public class SelectSNVsStep extends AbstractCommandPipelineStep<SelectVariantsWrapper> implements VariantProcessingStep
{
public static String SELECT_TYPE_TO_INCLUDE = "selectType";
public static String SELECT_TYPE_TO_EXCLUDE = "selectTypeToExclude";
public SelectSNVsStep(PipelineStepProvider<?> provider, PipelineContext ctx)
{
super(provider, ctx, new SelectVariantsWrapper(ctx.getLogger()));
}
public static String getSelectTypes()
{
List<String> ret = new ArrayList<>();
for (VariantContext.Type t : VariantContext.Type.values())
{
ret.add(t.name());
}
return StringUtils.join(ret, ";");
}
public static class Provider extends AbstractVariantProcessingStepProvider<SelectSNVsStep> implements VariantProcessingStep.SupportsScatterGather
{
public Provider()
{
super("SelectSNVs", "Select Variants By Type", "GATK SelectVariants", "Select only variants of the desired type from the input VCF", Arrays.asList(
ToolParameterDescriptor.create(SELECT_TYPE_TO_INCLUDE, "Select Type(s) To Include", "Only variants of the selected type(s) will be included", "ldk-simplecombo", new JSONObject(){{
put("storeValues", getSelectTypes());
put("multiSelect", true);
}}, "SNV"),
ToolParameterDescriptor.create(SELECT_TYPE_TO_EXCLUDE, "Select Type(s) To Exclude", "Variants of the selected type(s) will be excluded", "ldk-simplecombo", new JSONObject(){{
put("storeValues", getSelectTypes());
put("multiSelect", true);
}}, null)
), PageFlowUtil.set("/ldk/field/SimpleCombo.js"), "https://software.broadinstitute.org/gatk/");
}
@Override
public SelectSNVsStep create(PipelineContext ctx)
{
return new SelectSNVsStep(this, ctx);
}
}
@Override
public Output processVariants(File inputVCF, File outputDirectory, ReferenceGenome genome, @Nullable List<Interval> intervals) throws PipelineJobException
{
VariantProcessingStepOutputImpl output = new VariantProcessingStepOutputImpl();
List<String> options = new ArrayList<>();
String toInclude = getProvider().getParameterByName(SELECT_TYPE_TO_INCLUDE).extractValue(getPipelineCtx().getJob(), getProvider(), getStepIdx(), String.class);
SelectVariantsStep.addSelectTypeOptions(toInclude, options, "--select-type-to-include");
String toExclude = getProvider().getParameterByName(SELECT_TYPE_TO_EXCLUDE).extractValue(getPipelineCtx().getJob(), getProvider(), getStepIdx(), String.class);
SelectVariantsStep.addSelectTypeOptions(toExclude, options, "--select-type-to-exclude");
if (intervals != null)
{
intervals.forEach(interval -> {
options.add("-L");
options.add(interval.getContig() + ":" + interval.getStart() + "-" + interval.getEnd());
});
}
File outputVcf = new File(outputDirectory, SequenceTaskHelper.getUnzippedBaseName(inputVCF) + ".selectType.vcf.gz");
getWrapper().execute(genome.getWorkingFastaFile(), inputVCF, outputVcf, options);
if (!outputVcf.exists())
{
throw new PipelineJobException("output not found: " + outputVcf);
}
output.setVcf(outputVcf);
return output;
}
}