5555import java .util .ArrayList ;
5656import java .util .Arrays ;
5757import java .util .HashMap ;
58+ import java .util .HashSet ;
5859import java .util .List ;
5960import java .util .Map ;
6061import java .util .Set ;
@@ -604,7 +605,7 @@ private Map<String, Object> parseUnknownBarcodes(File unknownBarcodeFile, File l
604605 return ret ;
605606 }
606607
607- private File ensureLocalCopy (File input , File outputDir , Logger log ) throws PipelineJobException
608+ private File ensureLocalCopy (File input , File outputDir , Logger log , Set < File > toDelete ) throws PipelineJobException
608609 {
609610 if (!outputDir .equals (input .getParentFile ()))
610611 {
@@ -633,6 +634,9 @@ private File ensureLocalCopy(File input, File outputDir, Logger log) throws Pipe
633634 {
634635 FileUtils .copyFile (input , dest );
635636 }
637+
638+ toDelete .add (dest );
639+
636640 return dest ;
637641 }
638642 catch (IOException e )
@@ -650,13 +654,15 @@ public File generateFinalCalls(File citeSeqCountOutDir, File outputDir, String b
650654
651655 String scriptWrapper = getScriptPath ("sequenceanalysis" , "/external/scRNAseq/htoClassifier.sh" );
652656
657+ Set <File > toDelete = new HashSet <>();
658+
653659 SimpleScriptWrapper rWrapper = new SimpleScriptWrapper (log );
654660 rWrapper .setWorkingDir (outputDir );
655661
656- citeSeqCountOutDir = ensureLocalCopy (citeSeqCountOutDir , outputDir , log );
662+ citeSeqCountOutDir = ensureLocalCopy (citeSeqCountOutDir , outputDir , log , toDelete );
657663 if (cellBarcodeWhitelist != null )
658664 {
659- cellBarcodeWhitelist = ensureLocalCopy (cellBarcodeWhitelist , outputDir , log );
665+ cellBarcodeWhitelist = ensureLocalCopy (cellBarcodeWhitelist , outputDir , log , toDelete );
660666 }
661667
662668 File rScript = new File (getScriptPath ("sequenceanalysis" , "/external/scRNAseq/htoClassifier.Rmd" ));
@@ -707,6 +713,26 @@ public File generateFinalCalls(File citeSeqCountOutDir, File outputDir, String b
707713 throw new PipelineJobException ("Unable to find HTO calls file: " + callsFile .getPath ());
708714 }
709715
716+ try
717+ {
718+ for (File f : toDelete )
719+ {
720+ log .debug ("deleting local copy: " + f .getPath ());
721+ if (f .isDirectory ())
722+ {
723+ FileUtils .deleteDirectory (f );
724+ }
725+ else
726+ {
727+ f .delete ();
728+ }
729+ }
730+ }
731+ catch (IOException e )
732+ {
733+ throw new PipelineJobException (e );
734+ }
735+
710736 return callsFile ;
711737 }
712738
@@ -830,12 +856,12 @@ private HtoMergeResult possiblyMergeHtoFastqs(Readset htoReadset, File outdir, L
830856 return ret ;
831857 }
832858
833- public File runCiteSeqCount (PipelineStepOutput output , String category , Readset htoReadset , File htoList , File cellBarcodeList , File outputDir , String basename , Logger log , List <String > extraArgs , boolean doHtoFiltering , @ Nullable Integer minCountPerCell , File localPipelineDir , @ Nullable Integer editDistance , boolean scanEditDistances , Readset parentReadset , @ Nullable Integer genomeId , BARCODE_TYPE type ) throws PipelineJobException
859+ public File runCiteSeqCount (PipelineStepOutput output , String category , Readset htoReadset , File htoList , File cellBarcodeList , File outputDir , String basename , Logger log , List <String > extraArgs , boolean doHtoFiltering , @ Nullable Integer minCountPerCell , File localPipelineDir , @ Nullable Integer editDistance , boolean scanEditDistances , Readset parentReadset , @ Nullable Integer genomeId , BARCODE_TYPE type , boolean createOutputFiles ) throws PipelineJobException
834860 {
835861 HtoMergeResult htoFastqs = possiblyMergeHtoFastqs (htoReadset , outputDir , log );
836862 if (!htoFastqs .intermediateFiles .isEmpty ())
837863 {
838- htoFastqs .intermediateFiles .forEach (x -> output . addIntermediateFile ( x ) );
864+ htoFastqs .intermediateFiles .forEach (output :: addIntermediateFile );
839865 }
840866
841867 if (scanEditDistances && !type .isSupportsScan ())
@@ -915,8 +941,8 @@ public File runCiteSeqCount(PipelineStepOutput output, String category, Readset
915941 File unknownBarcodeFile = getCiteSeqCountUnknownOutput (localPipelineDir == null ? outputDir : localPipelineDir , type , ed );
916942 toolArgs .add (unknownBarcodeFile .getPath ());
917943
918- File citeSeqCountOutDir = new File (outputDir , basename + ".citeSeqCounts." + ed );
919- String outputBasename = basename + "." + ed ;
944+ File citeSeqCountOutDir = new File (outputDir , basename + ".citeSeqCounts." + ed + "." + type . name () );
945+ String outputBasename = basename + "." + ed + "." + type . name () ;
920946 Map <String , Object > callMap = executeCiteSeqCountWithJobCtx (outputDir , outputBasename , citeSeqCountOutDir , htoFastqs .files .getLeft (), htoFastqs .files .getRight (), toolArgs , ed , log , cellBarcodeList , doHtoFiltering , minCountPerCell , localPipelineDir , unknownBarcodeFile , type );
921947 results .put (ed , callMap );
922948
@@ -978,11 +1004,15 @@ public File runCiteSeqCount(PipelineStepOutput output, String category, Readset
9781004 throw new PipelineJobException ("html file was null" );
9791005 }
9801006
981- if (category != null )
1007+ if (createOutputFiles && category != null )
9821008 {
9831009 output .addSequenceOutput (htoCalls , parentReadset .getName () + ": Cell Hashing Calls" , category , parentReadset .getReadsetId (), null , genomeId , description );
9841010 output .addSequenceOutput (html , parentReadset .getName () + ": Cell Hashing Report" , category + ": Report" , parentReadset .getReadsetId (), null , genomeId , description );
9851011 }
1012+ else
1013+ {
1014+ log .debug ("Output files will not be created" );
1015+ }
9861016
9871017 return htoCalls ;
9881018 }
@@ -992,7 +1022,15 @@ public File runCiteSeqCount(PipelineStepOutput output, String category, Readset
9921022
9931023 String description = String .format ("%% Mapped: %s\n %% Unmapped: %s" , callMap .get ("PercentageMapped" ), callMap .get ("PercentageUnmapped" ));
9941024 File citeSeqCount = (File ) callMap .get ("citeSeqCountMatrix" );
995- output .addSequenceOutput (citeSeqCount , parentReadset .getName () + ": CITE-Seq Count Matrix" , (category == null ? "CITE-Seq Count Matrix" : category ), parentReadset .getReadsetId (), null , genomeId , description );
1025+
1026+ if (createOutputFiles )
1027+ {
1028+ output .addSequenceOutput (citeSeqCount , parentReadset .getName () + ": CITE-Seq Count Matrix" , (category == null ? "CITE-Seq Count Matrix" : category ), parentReadset .getReadsetId (), null , genomeId , description );
1029+ }
1030+ else
1031+ {
1032+ log .debug ("Output files will not be created" );
1033+ }
9961034
9971035 File outDir = (File ) callMap .get ("outputDir" );
9981036 output .removeIntermediateFiles (outDir );
0 commit comments