3434import org .labkey .api .sequenceanalysis .pipeline .SequencePipelineService ;
3535import org .labkey .api .sequenceanalysis .run .SimpleScriptWrapper ;
3636import org .labkey .api .util .Compress ;
37- import org .labkey .api .util .FileUtil ;
3837import org .labkey .api .util .PageFlowUtil ;
3938import org .labkey .api .writer .PrintWriters ;
4039import org .labkey .singlecell .SingleCellSchema ;
@@ -350,13 +349,13 @@ private Map<NimbleGenome, File> doAlignment(List<NimbleGenome> genomes, List<Fil
350349 alignArgs .add (strandedness );
351350 }
352351
353- File resultsTsvBase = new File (getPipelineCtx ().getWorkingDirectory (), "results .txt" );
352+ File alignmentTsvBase = new File (getPipelineCtx ().getWorkingDirectory (), "alignResults .txt" );
354353
355354 alignArgs .add ("--reference" );
356355 alignArgs .add (localRefJsons .stream ().map (x -> "/work/" + x .getName ()).collect (Collectors .joining ("," )));
357356
358357 alignArgs .add ("--output" );
359- alignArgs .add ("/work/" + resultsTsvBase .getName ());
358+ alignArgs .add ("/work/" + alignmentTsvBase .getName ());
360359
361360 alignArgs .add ("--input" );
362361 alignArgs .add ("/work/" + localBam .getName ());
@@ -366,37 +365,37 @@ private Map<NimbleGenome, File> doAlignment(List<NimbleGenome> genomes, List<Fil
366365 boolean dockerRan = runUsingDocker (alignArgs , output , "align.all" );
367366 for (NimbleGenome genome : genomes )
368367 {
369- File resultsTsv = new File (getPipelineCtx ().getWorkingDirectory (), "results ." + genome .genomeId + ".txt" );
370- if (dockerRan && !resultsTsv .exists ())
368+ File alignResultsTsv = new File (getPipelineCtx ().getWorkingDirectory (), "alignResults ." + genome .genomeId + ".txt" );
369+ if (dockerRan && !alignResultsTsv .exists ())
371370 {
372371 if (doneFile .exists ())
373372 {
374373 doneFile .delete ();
375374 }
376375
377- throw new PipelineJobException ("Expected to find file: " + resultsTsv .getPath ());
376+ throw new PipelineJobException ("Expected to find file: " + alignResultsTsv .getPath ());
378377 }
379378
380- File resultsGz = new File (resultsTsv .getPath () + ".gz" );
379+ File alignResultsGz = new File (alignResultsTsv .getPath () + ".gz" );
381380 if (dockerRan )
382381 {
383- if (resultsGz .exists ())
382+ if (alignResultsGz .exists ())
384383 {
385- getPipelineCtx ().getLogger ().debug ("Deleting pre-existing gz output: " + resultsGz .getName ());
386- resultsGz .delete ();
384+ getPipelineCtx ().getLogger ().debug ("Deleting pre-existing gz output: " + alignResultsGz .getName ());
385+ alignResultsGz .delete ();
387386 }
388387
389388 // NOTE: perform compression outside of nimble until nimble bugs fixed
390389 getPipelineCtx ().getLogger ().debug ("Compressing results TSV file" );
391- resultsGz = Compress .compressGzip (resultsTsv );
392- resultsTsv .delete ();
390+ alignResultsGz = Compress .compressGzip (alignResultsTsv );
391+ alignResultsTsv .delete ();
393392 }
394- else if (!resultsGz .exists ())
393+ else if (!alignResultsGz .exists ())
395394 {
396- throw new PipelineJobException ("Expected to find gz file: " + resultsGz .getPath ());
395+ throw new PipelineJobException ("Expected to find gz file: " + alignResultsGz .getPath ());
397396 }
398397
399- File log = getNimbleLogFile (resultsGz .getParentFile (), genome .genomeId );
398+ File log = getNimbleLogFile (alignResultsGz .getParentFile (), genome .genomeId );
400399 if (!log .exists ())
401400 {
402401 throw new PipelineJobException ("Expected to find file: " + log .getPath ());
@@ -416,7 +415,33 @@ else if (!resultsGz.exists())
416415 throw new PipelineJobException (e );
417416 }
418417
419- resultMap .put (genome , resultsGz );
418+ // Now run nimble report. Always re-run since this is fast:
419+ List <String > reportArgs = new ArrayList <>();
420+ reportArgs .add ("python3" );
421+ reportArgs .add ("-m" );
422+ reportArgs .add ("nimble" );
423+
424+ reportArgs .add ("report" );
425+ reportArgs .add ("-i" );
426+ reportArgs .add ("/work/" + alignResultsGz .getPath ());
427+
428+ File reportResultsGz = new File (getPipelineCtx ().getWorkingDirectory (), "reportResults." + genome .genomeId + ".txt" );
429+ if (reportResultsGz .exists ())
430+ {
431+ reportResultsGz .delete ();
432+ }
433+
434+ reportArgs .add ("-o" );
435+ reportArgs .add ("/work/" + reportResultsGz .getPath ());
436+
437+ runUsingDocker (reportArgs , output , null );
438+
439+ if (!reportResultsGz .exists ())
440+ {
441+ throw new PipelineJobException ("Missing file: " + reportResultsGz .getPath ());
442+ }
443+
444+ resultMap .put (genome , reportResultsGz );
420445 }
421446
422447 return resultMap ;
@@ -434,7 +459,7 @@ private File getNimbleDoneFile(File parentDir, String resumeString)
434459
435460 public static String DOCKER_CONTAINER_NAME = "ghcr.io/bimberlab/nimble:latest" ;
436461
437- private boolean runUsingDocker (List <String > nimbleArgs , PipelineStepOutput output , String resumeString ) throws PipelineJobException
462+ private boolean runUsingDocker (List <String > nimbleArgs , PipelineStepOutput output , @ Nullable String resumeString ) throws PipelineJobException
438463 {
439464 File localBashScript = new File (getPipelineCtx ().getWorkingDirectory (), "docker.sh" );
440465 File dockerBashScript = new File (getPipelineCtx ().getWorkingDirectory (), "dockerRun.sh" );
@@ -504,26 +529,33 @@ private boolean runUsingDocker(List<String> nimbleArgs, PipelineStepOutput outpu
504529 throw new PipelineJobException (e );
505530 }
506531
507- File doneFile = getNimbleDoneFile (getPipelineCtx ().getWorkingDirectory (), resumeString );
508- output .addIntermediateFile (doneFile );
509-
510- if (doneFile .exists ())
532+ File doneFile = null ;
533+ if (resumeString != null )
511534 {
512- getPipelineCtx ().getLogger ().info ("Nimble already completed, resuming: " + resumeString );
513- return false ;
535+ doneFile = getNimbleDoneFile (getPipelineCtx ().getWorkingDirectory (), resumeString );
536+ output .addIntermediateFile (doneFile );
537+
538+ if (doneFile .exists ())
539+ {
540+ getPipelineCtx ().getLogger ().info ("Nimble already completed, resuming: " + resumeString );
541+ return false ;
542+ }
514543 }
515544
516545 SimpleScriptWrapper rWrapper = new SimpleScriptWrapper (getPipelineCtx ().getLogger ());
517546 rWrapper .setWorkingDir (getPipelineCtx ().getWorkingDirectory ());
518547 rWrapper .execute (Arrays .asList ("/bin/bash" , localBashScript .getName ()));
519548
520- try
549+ if ( doneFile != null )
521550 {
522- FileUtils .touch (doneFile );
523- }
524- catch (IOException e )
525- {
526- throw new PipelineJobException (e );
551+ try
552+ {
553+ FileUtils .touch (doneFile );
554+ }
555+ catch (IOException e )
556+ {
557+ throw new PipelineJobException (e );
558+ }
527559 }
528560
529561 return true ;
0 commit comments