1313import htsjdk .variant .vcf .VCFReader ;
1414import org .apache .commons .io .FileUtils ;
1515import org .apache .logging .log4j .Logger ;
16+ import org .jetbrains .annotations .Nullable ;
1617import org .json .JSONObject ;
1718import org .labkey .api .module .ModuleLoader ;
1819import org .labkey .api .pipeline .PipelineJob ;
3637import java .io .File ;
3738import java .io .IOException ;
3839import java .io .PrintWriter ;
39- import java .nio .file .StandardCopyOption ;
4040import java .nio .file .StandardOpenOption ;
4141import java .util .ArrayList ;
4242import java .util .Arrays ;
@@ -148,7 +148,7 @@ private SAMFileHeader getAndValidateHeaderForBam(SequenceOutputFile so, String n
148148 throw new PipelineJobException ("Sample and library names match in read group(s), aborting" );
149149 }
150150
151- log .info ("Readset name and header do not match: " + newRsName + " / " + distinctLibraries .stream ().distinct ().collect (Collectors .joining ()));
151+ log .info ("Readset name and header do not match: " + newRsName + " / existing library: " + distinctLibraries . stream (). distinct (). collect ( Collectors . joining ()) + ", existing sample: " + distinctSamples .stream ().distinct ().collect (Collectors .joining ()));
152152
153153 return header ;
154154 }
@@ -261,15 +261,15 @@ private void reheaderVcf(SequenceOutputFile so, JobContext ctx, String newRsName
261261 }
262262 FileUtils .moveFile (outputIdx , inputIndex );
263263
264- addTracker (so , existingSample , newRsName );
264+ addTracker (so , existingSample , newRsName , null );
265265 }
266266 catch (IOException e )
267267 {
268268 throw new PipelineJobException (e );
269269 }
270270 }
271271
272- private void addTracker (SequenceOutputFile so , String existingSample , String newRsName ) throws IOException
272+ private void addTracker (SequenceOutputFile so , String existingSample , String newRsName , @ Nullable String existingLibrary ) throws IOException
273273 {
274274 File tracker = new File (so .getFile ().getParentFile (), "reheaderHistory.txt" );
275275 boolean preExisting = tracker .exists ();
@@ -282,10 +282,10 @@ private void addTracker(SequenceOutputFile so, String existingSample, String new
282282 {
283283 if (!preExisting )
284284 {
285- writer .println ("OriginalSample\t NewSample" );
285+ writer .println ("OriginalSample\t NewSample\t OriginalLibrary " );
286286 }
287287
288- writer .println (existingSample + "\t " + newRsName );
288+ writer .println (existingSample + "\t " + newRsName + " \t " + ( existingLibrary == null ? "N/A" : existingLibrary ) );
289289 }
290290 }
291291
@@ -345,7 +345,7 @@ private void reheaderBamOrCram(SequenceOutputFile so, JobContext ctx, String new
345345 }
346346 FileUtils .moveFile (outputIdx , inputIndex );
347347
348- addTracker (so , existingSample , newRsName );
348+ addTracker (so , existingSample , newRsName , existingLibrary );
349349 }
350350 catch (IOException e )
351351 {
0 commit comments