/**
* For each line in the MULTIPLEX_PARAMS file create a FastqRecordsWriter and put it in the barcodeFastqWriterMap map,
* where the key to the map is the concatenation of all barcodes in order for the given line.
*/
private void populateWritersFromMultiplexParams() {
final TabbedTextFileWithHeaderParser libraryParamsParser = new TabbedTextFileWithHeaderParser(MULTIPLEX_PARAMS);
final Set<String> expectedColumnLabels = CollectionUtil.makeSet("OUTPUT_PREFIX");
final List<String> barcodeColumnLabels = new ArrayList<String>();
for (int i = 1; i <= readStructure.barcodes.length(); i++) {
barcodeColumnLabels.add("BARCODE_" + i);
}
expectedColumnLabels.addAll(barcodeColumnLabels);
assertExpectedColumns(libraryParamsParser.columnLabels(), expectedColumnLabels);
for (final TabbedTextFileWithHeaderParser.Row row : libraryParamsParser) {
List<String> barcodeValues = null;
if (barcodeColumnLabels.size() > 0) {
barcodeValues = new ArrayList<String>();
for (final String barcodeLabel : barcodeColumnLabels) {
barcodeValues.add(row.getField(barcodeLabel));
}
}
final String key = (barcodeValues == null || barcodeValues.contains("N")) ? null : StringUtil.join("", barcodeValues);
if (barcodeFastqWriterMap.containsKey(key)) { //This will catch the case of having more than 1 line in a non-barcoded MULTIPLEX_PARAMS file
throw new PicardException("Row for barcode " + key + " appears more than once in MULTIPLEX_PARAMS file " +
MULTIPLEX_PARAMS);
}
final FastqRecordsWriter writer = buildWriter(new File(row.getField("OUTPUT_PREFIX")));
barcodeFastqWriterMap.put(key, writer);
}
if (barcodeFastqWriterMap.isEmpty()) {
throw new PicardException("MULTIPLEX_PARAMS file " + MULTIPLEX_PARAMS + " does have any data rows.");
}
libraryParamsParser.close();
}