11package org .labkey .sequenceanalysis .util ;
22
3+ import com .google .common .io .Files ;
34import htsjdk .samtools .SAMFileHeader ;
45import htsjdk .samtools .SAMFormatException ;
56import htsjdk .samtools .SAMReadGroupRecord ;
@@ -514,13 +515,23 @@ else if (!samples.equals(header.getGenotypeSamples()))
514515 writer .write ("} | bgzip -f" + (compressionLevel == null ? "" : " --compress-level 9" ) + (threads == null ? "" : " --threads " + threads ) + " > '" + outputGzip .getPath () + "'\n " );
515516 }
516517
517- SimpleScriptWrapper wrapper = new SimpleScriptWrapper (log );
518- wrapper .execute (Arrays .asList ("/bin/bash" , bashTmp .getPath ()));
519-
520- if (sortAfterMerge )
518+ File mergeDone = new File (outputGzip .getParentFile (), "merge.done" );
519+ if (mergeDone .exists ())
521520 {
522- log .debug ("sorting VCF" );
523- sortROD (outputGzip , log , 2 );
521+ log .debug ("Merge done file exists, will not repeat merge" );
522+ }
523+ else
524+ {
525+ SimpleScriptWrapper wrapper = new SimpleScriptWrapper (log );
526+ wrapper .execute (Arrays .asList ("/bin/bash" , bashTmp .getPath ()));
527+
528+ if (sortAfterMerge )
529+ {
530+ log .debug ("sorting VCF" );
531+ sortROD (outputGzip , log , 2 );
532+ }
533+
534+ Files .touch (mergeDone );
524535 }
525536
526537 SequenceAnalysisService .get ().ensureVcfIndex (outputGzip , log );
@@ -539,6 +550,8 @@ else if (!samples.equals(header.getGenotypeSamples()))
539550 {
540551 headerIdx .delete ();
541552 }
553+
554+ mergeDone .delete ();
542555 }
543556 catch (IOException e )
544557 {
0 commit comments