@@ -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