@@ -134,6 +134,11 @@ public void processFilesRemote(List<SequenceOutputFile> inputFiles, JobContext c
134134 new SamtoolsCramConverter (ctx .getLogger ()).convert (so .getFile (), outputFile , genome .getWorkingFastaFileGzipped (), true , threads , doCramArchivalMode );
135135 }
136136
137+ if (!outputFile .exists ())
138+ {
139+ throw new PipelineJobException ("Missing CRAM: " + outputFile .getPath ());
140+ }
141+
137142 if (replaceOriginal )
138143 {
139144 ctx .getLogger ().info ("Deleting original BAM/CRAM: {}" , so .getFile ().getPath ());
@@ -148,6 +153,31 @@ public void processFilesRemote(List<SequenceOutputFile> inputFiles, JobContext c
148153 {
149154 ctx .getLogger ().debug ("Input BAM not found, possibly deleted in earlier job iteration?" );
150155 }
156+
157+ ctx .getLogger ().debug ("Moving CRAM to replace original BAM file: " + so .getFile ().getPath ());
158+ try
159+ {
160+ File targetCram = new File (so .getFile ().getParentFile (), outputFile .getName ());
161+ if (targetCram .exists ())
162+ {
163+ ctx .getLogger ().debug ("Deleting file: " + targetCram .getPath ());
164+ targetCram .delete ();
165+ }
166+
167+ File targetCramIdx = new File (so .getFile ().getParentFile (), outputFile .getName () + ".crai" );
168+ if (targetCramIdx .exists ())
169+ {
170+ ctx .getLogger ().debug ("Deleting file: " + targetCramIdx .getPath ());
171+ targetCramIdx .delete ();
172+ }
173+
174+ FileUtils .moveFile (outputFile , targetCram );
175+ FileUtils .moveFile (new File (outputFile .getPath () + ".crai" ), targetCramIdx );
176+ }
177+ catch (IOException e )
178+ {
179+ throw new PipelineJobException (e );
180+ }
151181 }
152182 else if (SequenceUtil .FILETYPE .cram .getFileType ().isType (so .getFile ()))
153183 {
0 commit comments