try {
endPosition = Integer.parseInt(tokens[2].trim());
} catch (NumberFormatException numberFormatException) {
log.error("Column 2 is not a number");
throw new ParserException("Column 2 must be numeric." + " Found: " + tokens[1],
lineNumber, nextLine);
}
int startPosition = endPosition - 1;
if (startPosition < lastPosition) {
unsortedChromosomes.add(chr);
}
lastPosition = startPosition;
float value = Float.parseFloat(tokens[4].trim());
if (tokens[3].trim().equals("R")) {
value = -value;
}
addData(chr, startPosition, endPosition, value);
}
} else if (type.equals(Type.BED_GRAPH) || type.equals(Type.EXPR)) {
if (nTokens > 3) {
chr = tokens[chrColumn].trim();
if (!chr.equals(lastChr)) {
changedChromosome(dataset, lastChr);
//If we are seeing this chromosome again with something
//in-between, assume it's unsorted
if(dataset.containsChromosome(chr)){
unsortedChromosomes.add(chr);
}
}
lastChr = chr;
int startPosition = -1;
try {
startPosition = Integer.parseInt(tokens[startColumn].trim());
} catch (NumberFormatException numberFormatException) {
log.error("Column " + (startColumn + 1) + " is not a number");
throw new ParserException("Column (startColumn + 1) must be numeric." + " Found: " +
tokens[startColumn],
lineNumber, nextLine);
}
if (startPosition < lastPosition) {
unsortedChromosomes.add(chr);
}
lastPosition = startPosition;
int endPosition = -1;
try {
endPosition = Integer.parseInt(tokens[endColumn].trim());
int length = endPosition - startPosition;
updateLongestFeature(length);
} catch (NumberFormatException numberFormatException) {
log.error("Column " + (endColumn + 1) + " is not a number");
throw new ParserException("Column " + (endColumn + 1) +
" must be numeric." + " Found: " + tokens[endColumn],
lineNumber, nextLine);
}
addData(chr, startPosition, endPosition, Float.parseFloat(tokens[dataColumn].trim()));
}
} else if (type.equals(Type.VARIABLE)) {
if (nTokens > 1) {
// Per UCSC specification variable and fixed step coordinates are "1" based.
// We need to subtract 1 to convert to the internal "zero" based coordinates.
int startPosition = Integer.parseInt(tokens[0]) - 1;
if (startPosition < lastPosition) {
unsortedChromosomes.add(chr);
}
lastPosition = startPosition;
int endPosition = startPosition + windowSpan;
addData(chr, startPosition, endPosition, Float.parseFloat(tokens[1]));
}
} else { // Fixed step -- sorting is checked when step line is parsed
if (position >= 0) {
if (dataArray == null) {
dataArray = new float[nTokens];
}
for (int ii = 0; ii < dataArray.length; ii++) {
dataArray[ii] = Float.parseFloat(tokens[ii].trim());
}
int endPosition = position + windowSpan;
addData(chr, position, endPosition, dataArray);
}
position += step;
lastPosition = position;
}
} catch (NumberFormatException e) {
log.error(e);
throw new ParserException(e.getMessage(), lineNumber, nextLine);
}
}
}
// The last chromosome
changedChromosome(dataset, lastChr);
} catch (ParserException pe) {
throw (pe);
} catch (Exception e) {
if (nextLine != null && lineNumber != 0) {
throw new ParserException(e.getMessage(), e, lineNumber, nextLine);
} else {
throw new RuntimeException(e);
}
} finally {
if (reader != null) {