@@ -81,35 +81,47 @@ public AlignmentOutput performAlignment(Readset rs, List<File> inputFastqs1, @Nu
8181 File localBamIdx = new File (localBam .getPath () + ".bai" );
8282 AlignmentOutputImpl output = new AlignmentOutputImpl ();;
8383
84+ String idParam = StringUtils .trimToNull (getProvider ().getParameterByName ("id" ).extractValue (getPipelineCtx ().getJob (), getProvider (), getStepIdx (), String .class ));
85+ File cellrangerOutdir = new File (outputDirectory , CellRangerWrapper .getId (idParam , rs ));
86+
8487 if (localBam .exists () && localBamIdx .exists ())
8588 {
8689 getPipelineCtx ().getLogger ().info ("Existing BAM found, re-using: " + localBam .getPath ());
8790 }
8891 else
8992 {
90- getPipelineCtx ().getLogger ().info ("Running cellranger" );
91- AlignmentOutput crOutput = super .performAlignment (rs , inputFastqs1 , inputFastqs2 , outputDirectory , referenceGenome , basename , readGroupId , platformUnit );
93+ File crBam = new File (cellrangerOutdir , "outs/possorted_genome_bam.bam" );
94+ if (crBam .exists ())
95+ {
96+ getPipelineCtx ().getLogger ().info ("Using previous cellranger count run" );
97+ }
98+ else
99+ {
100+ getPipelineCtx ().getLogger ().info ("Running cellranger" );
101+ AlignmentOutput crOutput = super .performAlignment (rs , inputFastqs1 , inputFastqs2 , outputDirectory , referenceGenome , basename , readGroupId , platformUnit );
102+ crBam = crOutput .getBAM ();
92103
93- // Remove all the normal 10x outputs:
94- output .addCommandsExecuted (crOutput .getCommandsExecuted ());
95- output .addIntermediateFiles (crOutput .getIntermediateFiles ());
104+ // Remove all the normal 10x outputs:
105+ output .addCommandsExecuted (crOutput .getCommandsExecuted ());
106+ output .addIntermediateFiles (crOutput .getIntermediateFiles ());
107+ }
96108
97109 // Remove the whole 10x folder:
98- output .addIntermediateFile (crOutput . getBAM (). getParentFile (). getParentFile () );
110+ output .addIntermediateFile (cellrangerOutdir );
99111
100112 try
101113 {
102114 if (localBam .exists ())
103115 {
104116 localBam .delete ();
105117 }
106- FileUtils .copyFile ( crOutput . getBAM () , localBam );
118+ FileUtils .moveFile ( crBam , localBam );
107119
108120 if (localBamIdx .exists ())
109121 {
110122 localBamIdx .delete ();
111123 }
112- FileUtils .copyFile (new File (crOutput . getBAM () .getPath () + ".bai" ), localBamIdx );
124+ FileUtils .moveFile (new File (crBam .getPath () + ".bai" ), localBamIdx );
113125 }
114126 catch (IOException e )
115127 {
@@ -119,6 +131,7 @@ public AlignmentOutput performAlignment(Readset rs, List<File> inputFastqs1, @Nu
119131
120132 // Now run nimble itself:
121133 doNimbleAlign (localBam , output , rs , basename );
134+ output .setBAM (localBam );
122135
123136 return output ;
124137 }
0 commit comments