@@ -468,4 +468,50 @@ public void liftOverBed(File chain, File input, File output, @Nullable File unma
468468 //sort resulting file
469469 SequenceUtil .sortROD (output , job .getLogger (), 2 );
470470 }
471+
472+ @ Override
473+ public void performAdditionalMergeTasks (JobContext ctx , PipelineJob job , ReferenceGenome genome , List <File > orderedScatterOutputs , List <String > orderedJobDirs ) throws PipelineJobException
474+ {
475+ boolean retainUnmapped = ctx .getParams ().optBoolean ("retainUnmapped" , true );
476+ if (retainUnmapped )
477+ {
478+ job .getLogger ().info ("Merging liftOver reject VCFs" );
479+ List <File > toConcat = orderedScatterOutputs .stream ().map (vcfFile -> {
480+ File f = getUnmappedOutputFile (vcfFile );
481+ if (!f .exists ())
482+ {
483+ throw new IllegalStateException ("Missing file: " + f .getPath ());
484+ }
485+
486+ ctx .getFileManager ().addIntermediateFile (f );
487+ ctx .getFileManager ().addIntermediateFile (new File (f .getPath () + ".tbi" ));
488+
489+ return f ;
490+ }).toList ();
491+
492+ job .getLogger ().debug ("Total VCFs to merge: " + toConcat .size ());
493+ if (toConcat .isEmpty ())
494+ {
495+ throw new PipelineJobException ("No unmapped VCF found" );
496+ }
497+
498+ File combined = getUnmappedOutputFile (orderedScatterOutputs .get (0 ));
499+ File combinedIdx = new File (combined .getPath () + ".tbi" );
500+ if (combinedIdx .exists ())
501+ {
502+ job .getLogger ().info ("VCF exists, will not recreate: " + combined .getPath ());
503+ }
504+ else
505+ {
506+ combined = SequenceAnalysisService .get ().combineVcfs (toConcat , combined , genome , job .getLogger (), true , null );
507+ }
508+
509+ SequenceOutputFile so = new SequenceOutputFile ();
510+ so .setName (orderedScatterOutputs .get (0 ).getName () + ": Lifted/Unmapped" );
511+ so .setFile (combined );
512+ so .setCategory ("VCF File" );
513+ so .setLibrary_id (genome .getGenomeId ());
514+ ctx .getFileManager ().addSequenceOutput (so );
515+ }
516+ }
471517}
0 commit comments