// File and Directory Validation
IOUtil.assertDirectoryIsReadable(BASECALLS_DIR);
if (OUTPUT == null) OUTPUT = new File(BASECALLS_DIR, String.format("LANE%s_basecalling_metrics", LANE));
IOUtil.assertFileIsWritable(OUTPUT);
final IlluminaDataProviderFactory factory;
final ReadStructure readStructure = new ReadStructure(READ_STRUCTURE);
final BclQualityEvaluationStrategy bclQualityEvaluationStrategy = new BclQualityEvaluationStrategy(BclQualityEvaluationStrategy.ILLUMINA_ALLEGED_MINIMUM_QUALITY);
if (INPUT == null) {
// TODO: Legacy support. Remove when INPUT is required, after all old workflows are through
factory = new IlluminaDataProviderFactory(BASECALLS_DIR, LANE, readStructure, bclQualityEvaluationStrategy,
IlluminaDataType.PF, IlluminaDataType.Position);
} else {
// Grab expected barcode data from barcodeData.<LANE>
IOUtil.assertFileIsReadable(INPUT);
final TabbedTextFileWithHeaderParser barcodesParser = new TabbedTextFileWithHeaderParser(INPUT);
for (final TabbedTextFileWithHeaderParser.Row row : barcodesParser) {
final String barcodeName = row.getField(BARCODE_NAME_COLUMN);
final StringBuilder barcode = new StringBuilder();
for (int i = 1; i <= readStructure.barcodes.length(); i++) {
barcode.append(row.getField(BARCODE_SEQUENCE_COLUMN_NAME_STUB + i));
if (barcodeLength == 0) barcodeLength = barcode.length();
}
// Only add the barcode to the hash if it has sequences. For libraries
// that don't have barcodes this won't be set in the file.
if (barcode.length() > 0) {
barcodeToMetricCounts.put(barcode.toString(), new IlluminaMetricCounts(barcode.toString(), barcodeName, LANE));
}
}
factory = barcodeToMetricCounts.isEmpty()
? new IlluminaDataProviderFactory(
BASECALLS_DIR,
LANE,
readStructure,
bclQualityEvaluationStrategy,
IlluminaDataType.PF,
IlluminaDataType.Position)
: new IlluminaDataProviderFactory(
BASECALLS_DIR,
LANE,
readStructure,
bclQualityEvaluationStrategy,
IlluminaDataType.PF,
IlluminaDataType.Position,
IlluminaDataType.Barcodes);
}
unmatched_barcode = StringUtil.repeatCharNTimes('N', barcodeLength);
//Initialize data provider, iterate over clusters, and collect statistics
final IlluminaDataProvider provider = factory.makeDataProvider();
while (provider.hasNext()) {
final ClusterData cluster = provider.next();
addCluster(cluster);
}