Skip to content

Commit 92003de

Browse files
authored
Merge pull request #305 from BimberLab/24.11_fb_merge
Merge discvr-24.7 to discvr-24.11
2 parents 49560a5 + e73ac51 commit 92003de

File tree

4 files changed

+297
-68
lines changed

4 files changed

+297
-68
lines changed

SequenceAnalysis/src/org/labkey/sequenceanalysis/run/alignment/ParagraphStep.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ public ParagraphStep()
4545
put("allowBlank", false);
4646
}}, null),
4747
ToolParameterDescriptor.create("doBndSubset", "Remove BNDs", "If the reference VCF contains BNDs, selecting this option will cause the job to remove them prior to paragraph", "checkbox", new JSONObject(){{
48-
put("checked", true);
48+
put("checked", false);
4949
}}, false),
5050
ToolParameterDescriptor.create("useOutputFileContainer", "Submit to Source File Workbook", "If checked, each job will be submitted to the same workbook as the input file, as opposed to submitting all jobs to the same workbook. This is primarily useful if submitting a large batch of files to process separately. This only applies if 'Run Separately' is selected.", "checkbox", new JSONObject(){{
51-
put("checked", true);
51+
put("checked", false);
5252
}}, false)
5353
));
5454
}
@@ -113,20 +113,21 @@ else if (!svVcf.exists())
113113
boolean doBndSubset = ctx.getParams().optBoolean("doBndSubset", false);
114114
if (doBndSubset)
115115
{
116-
File vcfNoBnd = new File(ctx.getOutputDir(), SequenceAnalysisService.get().getUnzippedBaseName(svVcf.getName()) + "nobnd.vcf.gz");
116+
File vcfNoBnd = new File(ctx.getOutputDir(), SequenceAnalysisService.get().getUnzippedBaseName(svVcf.getName()) + "pgSubset.vcf.gz");
117117
File vcfNoBndIdx = new File(vcfNoBnd.getPath() + ".tbi");
118118
if (vcfNoBndIdx.exists())
119119
{
120-
ctx.getLogger().debug("Index exists, will no repeat BND subset");
120+
ctx.getLogger().debug("Index exists, will no repeat VCF subset");
121121
}
122122
else
123123
{
124124
SelectVariantsWrapper svw = new SelectVariantsWrapper(ctx.getLogger());
125125
List<String> selectArgs = new ArrayList<>();
126126
selectArgs.add("-select");
127-
selectArgs.add("SVTYPE != 'BND'");
127+
selectArgs.add("SVTYPE != 'BND' && POS > 150 && !(vc.hasAttribute('SVTYPE') && vc.getAttribute('SVTYPE') == 'INS' && vc.hasSymbolicAlleles() && !vc.hasAttribute('SEQ'))");
128128
selectArgs.add("--exclude-filtered");
129-
selectArgs.add("--exclude-non-variants");
129+
selectArgs.add("--exclude-filtered");
130+
selectArgs.add("--sites-only-vcf-output");
130131

131132
svw.execute(ctx.getSequenceSupport().getCachedGenome(inputFiles.get(0).getLibrary_id()).getWorkingFastaFile(), svVcf, vcfNoBnd, selectArgs);
132133

@@ -173,7 +174,7 @@ else if (!svVcf.exists())
173174
try (PrintWriter writer = PrintWriters.getPrintWriter(coverageFile); SamReader reader = SamReaderFactory.makeDefault().open(so.getFile()))
174175
{
175176
SAMFileHeader header = reader.getFileHeader();
176-
if (header.getReadGroups().size() == 0)
177+
if (header.getReadGroups().isEmpty())
177178
{
178179
throw new PipelineJobException("No read groups found in input BAM");
179180
}

singlecell/src/org/labkey/singlecell/SingleCellModule.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
import org.labkey.singlecell.run.CellRangerVDJWrapper;
110110
import org.labkey.singlecell.run.NimbleAlignmentStep;
111111
import org.labkey.singlecell.run.NimbleAnalysis;
112+
import org.labkey.singlecell.run.RepeatNimbleReportHandler;
112113
import org.labkey.singlecell.run.VelocytoAlignmentStep;
113114
import org.labkey.singlecell.run.VelocytoAnalysisStep;
114115

@@ -221,6 +222,7 @@ public static void registerPipelineSteps()
221222
SequenceAnalysisService.get().registerFileHandler(new CellRangerRawDataHandler());
222223
SequenceAnalysisService.get().registerFileHandler(new ProcessSingleCellHandler());
223224
SequenceAnalysisService.get().registerFileHandler(new ProcessSeuratObjectHandler());
225+
SequenceAnalysisService.get().registerFileHandler(new RepeatNimbleReportHandler());
224226

225227
//Single-cell:
226228
SequencePipelineService.get().registerPipelineStep(new AppendCiteSeq.Provider());

singlecell/src/org/labkey/singlecell/run/NimbleHelper.java

Lines changed: 79 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public class NimbleHelper
5353
private final PipelineStepProvider<?> _provider;
5454
private final int _stepIdx;
5555

56+
public static final String NIMBLE_REPORT_CATEGORY = "Nimble Report";
57+
5658
public NimbleHelper(PipelineContext ctx, PipelineStepProvider<?> provider, int stepIdx)
5759
{
5860
_ctx = ctx;
@@ -300,7 +302,7 @@ public void doNimbleAlign(File bam, PipelineStepOutput output, Readset rs, Strin
300302
}
301303
else
302304
{
303-
output.addSequenceOutput(reportHtml, basename + ": nimble report", "Nimble Report", rs.getRowId(), null, genome.getGenomeId(), description);
305+
output.addSequenceOutput(reportHtml, basename + ": nimble report", NIMBLE_REPORT_CATEGORY, rs.getRowId(), null, genome.getGenomeId(), description);
304306
}
305307
}
306308
}
@@ -474,76 +476,82 @@ private Map<NimbleGenome, File> doAlignment(List<NimbleGenome> genomes, List<Fil
474476
}
475477

476478
// Now run nimble report. Always re-run since this is fast:
477-
List<String> reportArgs = new ArrayList<>();
478-
reportArgs.add("python3");
479-
reportArgs.add("-m");
480-
reportArgs.add("nimble");
479+
File reportResultsGz = runNimbleReport(alignResultsGz, genome.genomeId, output, getPipelineCtx());
480+
resultMap.put(genome, reportResultsGz);
481+
}
481482

482-
reportArgs.add("report");
483-
reportArgs.add("-i");
484-
reportArgs.add("/work/" + alignResultsGz.getName());
483+
return resultMap;
484+
}
485485

486-
File reportResultsGz = new File(getPipelineCtx().getWorkingDirectory(), "reportResults." + genome.genomeId + ".txt");
487-
if (reportResultsGz.exists())
488-
{
489-
reportResultsGz.delete();
490-
}
486+
public static File runNimbleReport(File alignResultsGz, int genomeId, PipelineStepOutput output, PipelineContext ctx) throws PipelineJobException
487+
{
488+
List<String> reportArgs = new ArrayList<>();
489+
reportArgs.add("python3");
490+
reportArgs.add("-m");
491+
reportArgs.add("nimble");
491492

492-
reportArgs.add("-o");
493-
reportArgs.add("/work/" + reportResultsGz.getName());
493+
reportArgs.add("report");
494+
reportArgs.add("-i");
495+
reportArgs.add("/work/" + alignResultsGz.getName());
494496

495-
runUsingDocker(reportArgs, output, null);
497+
File reportResultsGz = new File(ctx.getWorkingDirectory(), "reportResults." + genomeId + ".txt");
498+
if (reportResultsGz.exists())
499+
{
500+
reportResultsGz.delete();
501+
}
496502

497-
if (!reportResultsGz.exists())
498-
{
499-
throw new PipelineJobException("Missing file: " + reportResultsGz.getPath());
500-
}
503+
reportArgs.add("-o");
504+
reportArgs.add("/work/" + reportResultsGz.getName());
501505

502-
resultMap.put(genome, reportResultsGz);
506+
runUsingDocker(reportArgs, output, null, ctx);
503507

504-
if (SequencePipelineService.get().hasMinLineCount(alignResultsGz, 2))
505-
{
506-
// Also run nimble plot. Always re-run since this is fast:
507-
List<String> plotArgs = new ArrayList<>();
508-
plotArgs.add("python3");
509-
plotArgs.add("-m");
510-
plotArgs.add("nimble");
508+
if (!reportResultsGz.exists())
509+
{
510+
throw new PipelineJobException("Missing file: " + reportResultsGz.getPath());
511+
}
511512

512-
plotArgs.add("plot");
513-
plotArgs.add("--input_file");
514-
plotArgs.add("/work/" + alignResultsGz.getName());
513+
if (SequencePipelineService.get().hasMinLineCount(alignResultsGz, 2))
514+
{
515+
// Also run nimble plot. Always re-run since this is fast:
516+
List<String> plotArgs = new ArrayList<>();
517+
plotArgs.add("python3");
518+
plotArgs.add("-m");
519+
plotArgs.add("nimble");
515520

516-
File plotResultsHtml = getReportHtmlFileFromResults(reportResultsGz);
517-
if (reportResultsGz.exists())
518-
{
519-
plotResultsHtml.delete();
520-
}
521+
plotArgs.add("plot");
522+
plotArgs.add("--input_file");
523+
plotArgs.add("/work/" + alignResultsGz.getName());
521524

522-
plotArgs.add("--output_file");
523-
plotArgs.add("/work/" + plotResultsHtml.getName());
525+
File plotResultsHtml = getReportHtmlFileFromResults(reportResultsGz);
526+
if (plotResultsHtml.exists())
527+
{
528+
plotResultsHtml.delete();
529+
}
524530

525-
runUsingDocker(plotArgs, output, null);
531+
plotArgs.add("--output_file");
532+
plotArgs.add("/work/" + plotResultsHtml.getName());
526533

527-
if (!plotResultsHtml.exists())
528-
{
529-
throw new PipelineJobException("Missing file: " + plotResultsHtml.getPath());
530-
}
531-
}
532-
else
534+
runUsingDocker(plotArgs, output, null, ctx);
535+
536+
if (!plotResultsHtml.exists())
533537
{
534-
getPipelineCtx().getLogger().info("Only single line found in results, skipping nimble plot");
538+
throw new PipelineJobException("Missing file: " + plotResultsHtml.getPath());
535539
}
536540
}
541+
else
542+
{
543+
ctx.getLogger().info("Only single line found in results, skipping nimble plot");
544+
}
537545

538-
return resultMap;
546+
return reportResultsGz;
539547
}
540548

541-
private File getReportHtmlFileFromResults(File reportResults)
549+
public static File getReportHtmlFileFromResults(File reportResults)
542550
{
543551
return new File(reportResults.getPath().replaceAll("txt(.gz)*$", "html"));
544552
}
545553

546-
private File getNimbleDoneFile(File parentDir, String resumeString)
554+
private static File getNimbleDoneFile(File parentDir, String resumeString)
547555
{
548556
return new File(parentDir, "nimble." + resumeString + ".done");
549557
}
@@ -552,13 +560,18 @@ private File getNimbleDoneFile(File parentDir, String resumeString)
552560

553561
private boolean runUsingDocker(List<String> nimbleArgs, PipelineStepOutput output, @Nullable String resumeString) throws PipelineJobException
554562
{
555-
File localBashScript = new File(getPipelineCtx().getWorkingDirectory(), "docker.sh");
556-
File dockerBashScript = new File(getPipelineCtx().getWorkingDirectory(), "dockerRun.sh");
563+
return runUsingDocker(nimbleArgs, output, resumeString, getPipelineCtx());
564+
}
565+
566+
private static boolean runUsingDocker(List<String> nimbleArgs, PipelineStepOutput output, @Nullable String resumeString, PipelineContext ctx) throws PipelineJobException
567+
{
568+
File localBashScript = new File(ctx.getWorkingDirectory(), "docker.sh");
569+
File dockerBashScript = new File(ctx.getWorkingDirectory(), "dockerRun.sh");
557570
output.addIntermediateFile(localBashScript);
558571
output.addIntermediateFile(dockerBashScript);
559572

560573
// Create temp folder:
561-
File tmpDir = new File(getPipelineCtx().getWorkingDirectory(), "tmpDir");
574+
File tmpDir = new File(ctx.getWorkingDirectory(), "tmpDir");
562575
if (tmpDir.exists())
563576
{
564577
try
@@ -592,7 +605,7 @@ private boolean runUsingDocker(List<String> nimbleArgs, PipelineStepOutput outpu
592605
writer.println("\t--memory='" + maxRam + "g' \\");
593606
}
594607

595-
getPipelineCtx().getDockerVolumes().forEach(ln -> writer.println(ln + " \\"));
608+
ctx.getDockerVolumes().forEach(ln -> writer.println(ln + " \\"));
596609
writer.println("\t-v \"${WD}:/work\" \\");
597610
writer.println("\t-v \"${HOME}:/homeDir\" \\");
598611
writer.println("\t-u $UID \\");
@@ -623,22 +636,22 @@ private boolean runUsingDocker(List<String> nimbleArgs, PipelineStepOutput outpu
623636
File doneFile = null;
624637
if (resumeString != null)
625638
{
626-
doneFile = getNimbleDoneFile(getPipelineCtx().getWorkingDirectory(), resumeString);
639+
doneFile = getNimbleDoneFile(ctx.getWorkingDirectory(), resumeString);
627640
output.addIntermediateFile(doneFile);
628641

629642
if (doneFile.exists())
630643
{
631-
getPipelineCtx().getLogger().info("Nimble already completed, resuming: " + resumeString);
644+
ctx.getLogger().info("Nimble already completed, resuming: " + resumeString);
632645
return false;
633646
}
634647
else
635648
{
636-
getPipelineCtx().getLogger().debug("done file not found: " + doneFile.getPath());
649+
ctx.getLogger().debug("done file not found: " + doneFile.getPath());
637650
}
638651
}
639652

640-
SimpleScriptWrapper rWrapper = new SimpleScriptWrapper(getPipelineCtx().getLogger());
641-
rWrapper.setWorkingDir(getPipelineCtx().getWorkingDirectory());
653+
SimpleScriptWrapper rWrapper = new SimpleScriptWrapper(ctx.getLogger());
654+
rWrapper.setWorkingDir(ctx.getWorkingDirectory());
642655
rWrapper.execute(Arrays.asList("/bin/bash", localBashScript.getName()));
643656

644657
if (doneFile != null)
@@ -657,18 +670,23 @@ private boolean runUsingDocker(List<String> nimbleArgs, PipelineStepOutput outpu
657670
}
658671

659672
private File ensureLocalCopy(File input, PipelineStepOutput output) throws PipelineJobException
673+
{
674+
return ensureLocalCopy(input, output, getPipelineCtx());
675+
}
676+
677+
public static File ensureLocalCopy(File input, PipelineStepOutput output, PipelineContext ctx) throws PipelineJobException
660678
{
661679
try
662680
{
663-
if (getPipelineCtx().getWorkingDirectory().equals(input.getParentFile()))
681+
if (ctx.getWorkingDirectory().equals(input.getParentFile()))
664682
{
665683
return input;
666684
}
667685

668-
File local = new File(getPipelineCtx().getWorkingDirectory(), input.getName());
686+
File local = new File(ctx.getWorkingDirectory(), input.getName());
669687
if (!local.exists())
670688
{
671-
getPipelineCtx().getLogger().debug("Copying file locally: " + input.getPath());
689+
ctx.getLogger().debug("Copying file locally: " + input.getPath());
672690
FileUtils.copyFile(input, local);
673691
}
674692

0 commit comments

Comments
 (0)