|
| 1 | +package org.labkey.jbrowse.pipeline; |
| 2 | + |
| 3 | +import htsjdk.samtools.util.Interval; |
| 4 | +import org.apache.commons.io.FileUtils; |
| 5 | +import org.apache.commons.lang3.StringUtils; |
| 6 | +import org.apache.commons.lang3.SystemUtils; |
| 7 | +import org.labkey.api.pipeline.PipelineJobException; |
| 8 | +import org.labkey.api.sequenceanalysis.pipeline.AbstractVariantProcessingStepProvider; |
| 9 | +import org.labkey.api.sequenceanalysis.pipeline.PipelineContext; |
| 10 | +import org.labkey.api.sequenceanalysis.pipeline.PipelineStepProvider; |
| 11 | +import org.labkey.api.sequenceanalysis.pipeline.ReferenceGenome; |
| 12 | +import org.labkey.api.sequenceanalysis.pipeline.ToolParameterDescriptor; |
| 13 | +import org.labkey.api.sequenceanalysis.pipeline.VariantProcessingStep; |
| 14 | +import org.labkey.api.sequenceanalysis.pipeline.VariantProcessingStepOutputImpl; |
| 15 | +import org.labkey.api.sequenceanalysis.run.AbstractCommandPipelineStep; |
| 16 | +import org.labkey.api.sequenceanalysis.run.SelectVariantsWrapper; |
| 17 | +import org.labkey.api.writer.PrintWriters; |
| 18 | + |
| 19 | +import javax.annotation.Nullable; |
| 20 | +import java.io.File; |
| 21 | +import java.io.IOException; |
| 22 | +import java.io.PrintWriter; |
| 23 | +import java.util.Arrays; |
| 24 | +import java.util.List; |
| 25 | + |
| 26 | +public class IndexVariantsStep extends AbstractCommandPipelineStep<SelectVariantsWrapper> implements VariantProcessingStep |
| 27 | +{ |
| 28 | + public static final String CATEGORY = "VCF Lucene Index"; |
| 29 | + |
| 30 | + public IndexVariantsStep(PipelineStepProvider<?> provider, PipelineContext ctx) |
| 31 | + { |
| 32 | + super(provider, ctx, new SelectVariantsWrapper(ctx.getLogger())); |
| 33 | + } |
| 34 | + |
| 35 | + public static class Provider extends AbstractVariantProcessingStepProvider<IndexVariantsStep> implements VariantProcessingStep.SupportsScatterGather |
| 36 | + { |
| 37 | + public Provider() |
| 38 | + { |
| 39 | + super("IndexVariantsStep", "Index Variants", "DISCVR-seq", "Create a lucene index for the selected fields", Arrays.asList( |
| 40 | + ToolParameterDescriptor.create("infoFieldsToIndex", "INFO fields to index", "A list of INFO fields to index", "sequenceanalysis-trimmingtextarea", null, null), |
| 41 | + ToolParameterDescriptor.create("allowLenientProcessing", "Allow Lenient Processing", "If selected, many error types will be logged but ignored.", "checkbox", null, false) |
| 42 | + ), Arrays.asList("/sequenceanalysis/field/TrimmingTextArea.js"), "https://github.com/BimberLab/DISCVRSeq"); |
| 43 | + } |
| 44 | + |
| 45 | + @Override |
| 46 | + public IndexVariantsStep create(PipelineContext ctx) |
| 47 | + { |
| 48 | + return new IndexVariantsStep(this, ctx); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public Output processVariants(File inputVCF, File outputDirectory, ReferenceGenome genome, @Nullable List<Interval> intervals) throws PipelineJobException |
| 54 | + { |
| 55 | + VariantProcessingStepOutputImpl output = new VariantProcessingStepOutputImpl(); |
| 56 | + |
| 57 | + String infoFieldsRaw = StringUtils.trimToNull(getProvider().getParameterByName("infoFieldsToIndex").extractValue(getPipelineCtx().getJob(), getProvider(), getStepIdx(), String.class)); |
| 58 | + if (infoFieldsRaw == null) |
| 59 | + { |
| 60 | + throw new PipelineJobException("Missing info fields to index"); |
| 61 | + } |
| 62 | + |
| 63 | + List<String> infoFields = Arrays.stream(infoFieldsRaw.split(";")).sorted().toList(); |
| 64 | + boolean allowLenientProcessing = getProvider().getParameterByName("allowLenientProcessing").extractValue(getPipelineCtx().getJob(), getProvider(), getStepIdx(), Boolean.class, false); |
| 65 | + |
| 66 | + File indexDir = new File(outputDirectory, "lucene"); |
| 67 | + JBrowseLucenePipelineJob.prepareLuceneIndex(inputVCF, indexDir, getPipelineCtx().getLogger(), infoFields, allowLenientProcessing); |
| 68 | + |
| 69 | + File idx = new File(indexDir, "write.lock"); |
| 70 | + if (!idx.exists()) |
| 71 | + { |
| 72 | + throw new PipelineJobException("Unable to find file: " + idx.getPath()); |
| 73 | + } |
| 74 | + |
| 75 | + output.addSequenceOutput(idx, "Lucene index: " + inputVCF.getName(), CATEGORY, null, null, genome.getGenomeId(), "Fields indexed: " + infoFieldsRaw); |
| 76 | + |
| 77 | + return output; |
| 78 | + } |
| 79 | +} |
0 commit comments