|
| 1 | +package org.labkey.sequenceanalysis.run.util; |
| 2 | + |
| 3 | +import htsjdk.samtools.util.Interval; |
| 4 | +import org.apache.logging.log4j.Logger; |
| 5 | +import org.json.JSONObject; |
| 6 | +import org.labkey.api.pipeline.PipelineJobException; |
| 7 | +import org.labkey.api.sequenceanalysis.pipeline.AbstractVariantProcessingStepProvider; |
| 8 | +import org.labkey.api.sequenceanalysis.pipeline.PipelineContext; |
| 9 | +import org.labkey.api.sequenceanalysis.pipeline.PipelineStepProvider; |
| 10 | +import org.labkey.api.sequenceanalysis.pipeline.ReferenceGenome; |
| 11 | +import org.labkey.api.sequenceanalysis.pipeline.ToolParameterDescriptor; |
| 12 | +import org.labkey.api.sequenceanalysis.pipeline.VariantProcessingStep; |
| 13 | +import org.labkey.api.sequenceanalysis.pipeline.VariantProcessingStepOutputImpl; |
| 14 | +import org.labkey.api.sequenceanalysis.run.AbstractCommandPipelineStep; |
| 15 | +import org.labkey.api.sequenceanalysis.run.AbstractGatk4Wrapper; |
| 16 | +import org.labkey.api.util.PageFlowUtil; |
| 17 | +import org.labkey.sequenceanalysis.pipeline.SequenceTaskHelper; |
| 18 | + |
| 19 | +import javax.annotation.Nullable; |
| 20 | +import java.io.File; |
| 21 | +import java.util.ArrayList; |
| 22 | +import java.util.Arrays; |
| 23 | +import java.util.List; |
| 24 | + |
| 25 | +public class SVAnnotateStep extends AbstractCommandPipelineStep<SVAnnotateStep.SNAnnotateWrapper> implements VariantProcessingStep |
| 26 | +{ |
| 27 | + public static final String GENE_PARAM = "gene_file"; |
| 28 | + |
| 29 | + public SVAnnotateStep(PipelineStepProvider<?> provider, PipelineContext ctx) |
| 30 | + { |
| 31 | + super(provider, ctx, new SNAnnotateWrapper(ctx.getLogger())); |
| 32 | + } |
| 33 | + |
| 34 | + public static class Provider extends AbstractVariantProcessingStepProvider<SVAnnotateStep> |
| 35 | + { |
| 36 | + public Provider() |
| 37 | + { |
| 38 | + super("SVAnnotateStep", "GATK SVAnnotate", "GATK", "This will run GATK's SVAnnotate to classify SVs by impact", Arrays.asList( |
| 39 | + ToolParameterDescriptor.createExpDataParam(GENE_PARAM, "Gene File", "This is the ID of a GTF or GFF3 file containing genes from this genome.", "sequenceanalysis-genomefileselectorfield", new JSONObject() |
| 40 | + {{ |
| 41 | + put("extensions", Arrays.asList("gtf")); |
| 42 | + put("width", 400); |
| 43 | + put("allowBlank", false); |
| 44 | + }}, null) |
| 45 | + ), PageFlowUtil.set("sequenceanalysis/field/GenomeFileSelectorField.js"), ""); |
| 46 | + |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + public SVAnnotateStep create(PipelineContext ctx) |
| 51 | + { |
| 52 | + return new SVAnnotateStep(this, ctx); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public Output processVariants(File inputVCF, File outputDirectory, ReferenceGenome genome, @Nullable List<Interval> intervals) throws PipelineJobException |
| 58 | + { |
| 59 | + VariantProcessingStepOutputImpl output = new VariantProcessingStepOutputImpl(); |
| 60 | + |
| 61 | + output.addInput(inputVCF, "Input VCF"); |
| 62 | + output.addInput(genome.getWorkingFastaFile(), "Reference Genome"); |
| 63 | + |
| 64 | + List<String> args = new ArrayList<>(getWrapper().getBaseArgs("SVAnnotate")); |
| 65 | + args.add("-V"); |
| 66 | + args.add(inputVCF.getPath()); |
| 67 | + |
| 68 | + if (intervals != null) |
| 69 | + { |
| 70 | + intervals.forEach(interval -> { |
| 71 | + args.add("-L"); |
| 72 | + args.add(interval.getContig() + ":" + interval.getStart() + "-" + interval.getEnd()); |
| 73 | + }); |
| 74 | + } |
| 75 | + |
| 76 | + Integer geneFileId = getProvider().getParameterByName(GENE_PARAM).extractValue(getPipelineCtx().getJob(), getProvider(), getStepIdx(), Integer.class); |
| 77 | + File geneFile = getPipelineCtx().getSequenceSupport().getCachedData(geneFileId); |
| 78 | + if (!geneFile.exists()) |
| 79 | + { |
| 80 | + throw new PipelineJobException("Unable to find file: " + geneFile.getPath()); |
| 81 | + } |
| 82 | + args.add("--protein-coding-gtf"); |
| 83 | + args.add(geneFile.getPath()); |
| 84 | + |
| 85 | + File outputVcf = new File(outputDirectory, SequenceTaskHelper.getUnzippedBaseName(inputVCF) + ".svannotate.vcf.gz"); |
| 86 | + getWrapper().execute(args); |
| 87 | + if (!outputVcf.exists()) |
| 88 | + { |
| 89 | + throw new PipelineJobException("output not found: " + outputVcf); |
| 90 | + } |
| 91 | + |
| 92 | + output.setVcf(outputVcf); |
| 93 | + |
| 94 | + return output; |
| 95 | + } |
| 96 | + |
| 97 | + public static class SNAnnotateWrapper extends AbstractGatk4Wrapper |
| 98 | + { |
| 99 | + public SNAnnotateWrapper(@Nullable Logger logger) |
| 100 | + { |
| 101 | + super(logger); |
| 102 | + } |
| 103 | + } |
| 104 | +} |
0 commit comments