|
| 1 | +package org.labkey.sequenceanalysis.run.analysis; |
| 2 | + |
| 3 | +import org.json.JSONObject; |
| 4 | +import org.labkey.api.module.ModuleLoader; |
| 5 | +import org.labkey.api.pipeline.PipelineJob; |
| 6 | +import org.labkey.api.pipeline.PipelineJobException; |
| 7 | +import org.labkey.api.pipeline.RecordedAction; |
| 8 | +import org.labkey.api.sequenceanalysis.SequenceOutputFile; |
| 9 | +import org.labkey.api.sequenceanalysis.pipeline.AbstractParameterizedOutputHandler; |
| 10 | +import org.labkey.api.sequenceanalysis.pipeline.ReferenceGenome; |
| 11 | +import org.labkey.api.sequenceanalysis.pipeline.SequenceAnalysisJobSupport; |
| 12 | +import org.labkey.api.sequenceanalysis.pipeline.SequenceOutputHandler; |
| 13 | +import org.labkey.api.sequenceanalysis.pipeline.SequencePipelineService; |
| 14 | +import org.labkey.api.sequenceanalysis.pipeline.ToolParameterDescriptor; |
| 15 | +import org.labkey.api.sequenceanalysis.run.SimpleScriptWrapper; |
| 16 | +import org.labkey.api.util.FileType; |
| 17 | +import org.labkey.sequenceanalysis.SequenceAnalysisModule; |
| 18 | + |
| 19 | +import java.io.File; |
| 20 | +import java.util.ArrayList; |
| 21 | +import java.util.Arrays; |
| 22 | +import java.util.List; |
| 23 | + |
| 24 | +public class PbsvJointCallingHandler extends AbstractParameterizedOutputHandler<SequenceOutputHandler.SequenceOutputProcessor> |
| 25 | +{ |
| 26 | + private static final FileType FILE_TYPE = new FileType(".svsig.gz"); |
| 27 | + |
| 28 | + public PbsvJointCallingHandler() |
| 29 | + { |
| 30 | + super(ModuleLoader.getInstance().getModule(SequenceAnalysisModule.NAME), "Pbsv Call", "Runs pbsv call, which jointly calls genotypes from PacBio data", null, Arrays.asList( |
| 31 | + ToolParameterDescriptor.create("fileName", "VCF Filename", "The name of the resulting file.", "textfield", new JSONObject(){{ |
| 32 | + put("allowBlank", false); |
| 33 | + put("doNotIncludeInTemplates", true); |
| 34 | + }}, null) |
| 35 | + )); |
| 36 | + } |
| 37 | + |
| 38 | + @Override |
| 39 | + public boolean canProcess(SequenceOutputFile o) |
| 40 | + { |
| 41 | + return o.getFile() != null && FILE_TYPE.isType(o.getFile()); |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + public boolean doRunRemote() |
| 46 | + { |
| 47 | + return true; |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + public boolean doRunLocal() |
| 52 | + { |
| 53 | + return false; |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public SequenceOutputProcessor getProcessor() |
| 58 | + { |
| 59 | + return new Processor(); |
| 60 | + } |
| 61 | + |
| 62 | + public static class Processor implements SequenceOutputProcessor |
| 63 | + { |
| 64 | + @Override |
| 65 | + public void processFilesOnWebserver(PipelineJob job, SequenceAnalysisJobSupport support, List<SequenceOutputFile> inputFiles, JSONObject params, File outputDir, List<RecordedAction> actions, List<SequenceOutputFile> outputsToCreate) throws UnsupportedOperationException, PipelineJobException |
| 66 | + { |
| 67 | + |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + public void processFilesRemote(List<SequenceOutputFile> inputFiles, JobContext ctx) throws UnsupportedOperationException, PipelineJobException |
| 72 | + { |
| 73 | + List<String> args = new ArrayList<>(); |
| 74 | + args.add(getExe().getPath()); |
| 75 | + args.add("call"); |
| 76 | + |
| 77 | + Integer maxThreads = SequencePipelineService.get().getMaxThreads(ctx.getLogger()); |
| 78 | + if (maxThreads != null) |
| 79 | + { |
| 80 | + args.add("-j"); |
| 81 | + args.add(String.valueOf(maxThreads)); |
| 82 | + } |
| 83 | + |
| 84 | + ReferenceGenome genome = ctx.getSequenceSupport().getCachedGenomes().iterator().next(); |
| 85 | + args.add(genome.getWorkingFastaFile().getPath()); |
| 86 | + |
| 87 | + inputFiles.forEach(f -> { |
| 88 | + args.add(f.getFile().getPath()); |
| 89 | + }); |
| 90 | + |
| 91 | + String fileName = ctx.getParams().getString("fileName"); |
| 92 | + if (!fileName.toLowerCase().endsWith("vcf.gz")) |
| 93 | + { |
| 94 | + fileName = fileName + ".vcf.gz"; |
| 95 | + } |
| 96 | + |
| 97 | + File vcfOut = new File(ctx.getOutputDir(), fileName); |
| 98 | + args.add(vcfOut.getPath()); |
| 99 | + |
| 100 | + new SimpleScriptWrapper(ctx.getLogger()).execute(args); |
| 101 | + |
| 102 | + if (!vcfOut.exists()) |
| 103 | + { |
| 104 | + throw new PipelineJobException("Unable to find file: " + vcfOut.getPath()); |
| 105 | + } |
| 106 | + |
| 107 | + SequenceOutputFile so = new SequenceOutputFile(); |
| 108 | + so.setName("pbsv call: " + fileName); |
| 109 | + so.setFile(vcfOut); |
| 110 | + so.setCategory("PBSV VCF"); |
| 111 | + so.setLibrary_id(genome.getGenomeId()); |
| 112 | + |
| 113 | + ctx.addSequenceOutput(so); |
| 114 | + } |
| 115 | + |
| 116 | + private File getExe() |
| 117 | + { |
| 118 | + return SequencePipelineService.get().getExeForPackage("PBSVPATH", "pbsv"); |
| 119 | + } |
| 120 | + } |
| 121 | +} |
0 commit comments