curLineNum++;
if (line == null || line.startsWith(">")) {
//The last line can have a different number of bases/bytes
if (numInconsistentLines >= 2) {
throw new DataLoadException("Fasta file has uneven line lengths in contig " + curContig, inputPath);
}
//Done with old contig
if (curContig != null) {
writeLine(writer, curContig, size, location, basesPerLine, bytesPerLine);
}
if (line == null) {
haveTasks = false;
break;
}
//Header line
curContig = WHITE_SPACE.split(line)[0];
curContig = curContig.substring(1);
if(allContigs.contains(curContig)){
throw new DataLoadException("Contig '" + curContig + "' found multiple times in file.", inputPath);
}else{
allContigs.add(curContig);
}
//Should be starting position of next line
location = reader.getPosition();
size = 0;
basesPerLine = -1;
bytesPerLine = -1;
numInconsistentLines = -1;
} else {
basesThisLine = line.length();
bytesThisLine = (int) (reader.getPosition() - lastPosition);
//Calculate stats per line if first line, otherwise
//check for consistency
if (numInconsistentLines < 0) {
basesPerLine = basesThisLine;
bytesPerLine = bytesThisLine;
numInconsistentLines = 0;
numBlanks = 0;
} else {
if ((basesPerLine != basesThisLine || bytesPerLine != bytesThisLine) && basesThisLine > 0) {
numInconsistentLines++;
}
}
//Empty line. This is allowed if it's at the end of the contig);
if (basesThisLine == 0) {
numBlanks++;
lastBlankLineNum = curLineNum;
} else if (numBlanks >= 1) {
throw new DataLoadException(String.format("Blank line at line number %d, followed by data line at %d, in contig %s\nBlank lines are only allowed at the end of a contig", lastBlankLineNum, curLineNum, curContig), inputPath);
}
size += basesThisLine;
}
lastPosition = reader.getPosition();