Skip to content

Commit

Permalink
SplitIntervals dynamic zero padding in filenames (#6587)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldgauthier committed May 18, 2020
1 parent 88cb338 commit 6d43103
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public class SplitIntervals extends GATKTool {
public static final String PICARD_INTERVAL_FILE_EXTENSION = "interval_list";
public static final String DEFAULT_EXTENSION = "-scattered." + PICARD_INTERVAL_FILE_EXTENSION;

public static final int DEFAULT_NUMBER_OF_DIGITS = 4; //to preserve backward compatibility

@Argument(fullName = SCATTER_COUNT_LONG_NAME, shortName = SCATTER_COUNT_SHORT_NAME,
doc = "scatter count: number of output interval files to split into", optional = true)
private int scatterCount = 1;
Expand Down Expand Up @@ -147,8 +149,9 @@ public void onTraversalStart() {
}) // turn the intervals back into an IntervalList
).collect(Collectors.toList());

final DecimalFormat formatter = new DecimalFormat("0000");
IntStream.range(0, scatteredFinal.size()).forEach(n -> scatteredFinal.get(n).write(new File(outputDir, formatter.format(n) + extension)));
final int maxNumberOfPlaces = Math.max((int)Math.floor(Math.log10(scatterCount-1))+1, DEFAULT_NUMBER_OF_DIGITS);
final String formatString = "%0" + maxNumberOfPlaces + "d";
IntStream.range(0, scatteredFinal.size()).forEach(n -> scatteredFinal.get(n).write(new File(outputDir, String.format(formatString, n) + extension)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ public void testAsInWGSJointCalling() {

//generates the files to look for given a scatter count, directory and extension
private static Stream<File> getExpectedScatteredFiles(final int scatterCount, final File outputDir, String extension) {
return IntStream.range(0, scatterCount).mapToObj(n -> new File(outputDir, formatter.format(n) + extension));
final int maxNumberOfPlaces = (int)Math.max(Math.floor(Math.log10(scatterCount-1))+1, SplitIntervals.DEFAULT_NUMBER_OF_DIGITS);
final String fileIndexFormatString = "%0" + maxNumberOfPlaces + "d";
return IntStream.range(0, scatterCount).mapToObj(n -> new File(outputDir, String.format(fileIndexFormatString, n) + extension));
}

private static void verifyScatteredFilesExist(final int scatterCount, final File outputDir, String extension) {
Expand Down

0 comments on commit 6d43103

Please sign in to comment.