Fixing GATKReport exception handling when loading a report
* allowing tables with no description to go through * GATKReportTable should be more lenient with the format requirements (added to-dos for roger)
This commit is contained in:
parent
4a54a4b11c
commit
539da9e3e1
|
|
@ -28,10 +28,7 @@ import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
|
||||||
import org.broadinstitute.sting.utils.exceptions.StingException;
|
import org.broadinstitute.sting.utils.exceptions.StingException;
|
||||||
import org.broadinstitute.sting.utils.exceptions.UserException;
|
import org.broadinstitute.sting.utils.exceptions.UserException;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.*;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
|
@ -85,10 +82,17 @@ public class GATKReport {
|
||||||
* @param file the file to load
|
* @param file the file to load
|
||||||
*/
|
*/
|
||||||
private void loadReport(File file) {
|
private void loadReport(File file) {
|
||||||
|
BufferedReader reader;
|
||||||
|
String reportHeader;
|
||||||
try {
|
try {
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
reader = new BufferedReader(new FileReader(file));
|
||||||
|
reportHeader = reader.readLine();
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
throw new ReviewedStingException("Could not open file : " + file);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new ReviewedStingException("Could not read file : " + file);
|
||||||
|
}
|
||||||
|
|
||||||
String reportHeader = reader.readLine();
|
|
||||||
|
|
||||||
// Read the first line for the version and number of tables.
|
// Read the first line for the version and number of tables.
|
||||||
version = GATKReportVersion.fromHeader(reportHeader);
|
version = GATKReportVersion.fromHeader(reportHeader);
|
||||||
|
|
@ -101,20 +105,9 @@ public class GATKReport {
|
||||||
// Read each tables according ot the number of tables
|
// Read each tables according ot the number of tables
|
||||||
for (int i = 0; i < nTables; i++) {
|
for (int i = 0; i < nTables; i++) {
|
||||||
addTable(new GATKReportTable(reader, version));
|
addTable(new GATKReportTable(reader, version));
|
||||||
|
|
||||||
/*
|
|
||||||
if ( !blankLine.equals("") ) {
|
|
||||||
throw new StingException("The GATK Report File is corrupted or not formatted correctly");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
// todo - improve exception handling
|
|
||||||
//throw new StingException("Cannot read GATKReport: " + e);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
|
||||||
import org.broadinstitute.sting.utils.text.TextFormattingUtils;
|
import org.broadinstitute.sting.utils.text.TextFormattingUtils;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
|
@ -54,9 +55,13 @@ public class GATKReportTable {
|
||||||
|
|
||||||
private GATKReportColumns columns;
|
private GATKReportColumns columns;
|
||||||
|
|
||||||
public GATKReportTable(BufferedReader reader, GATKReportVersion version) {
|
private static final String COULD_NOT_READ_HEADER = "Could not read the header of this file -- ";
|
||||||
try {
|
private static final String COULD_NOT_READ_COLUMN_NAMES = "Could not read the column names of this file -- ";
|
||||||
|
private static final String COULD_NOT_READ_DATA_LINE = "Could not read a data line of this table -- ";
|
||||||
|
private static final String COULD_NOT_READ_EMPTY_LINE = "Could not read the last empty line of this table -- ";
|
||||||
|
private static final String OLD_GATK_TABLE_VERSION = "We no longer support older versions of the GATK Tables";
|
||||||
|
|
||||||
|
public GATKReportTable(BufferedReader reader, GATKReportVersion version) {
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
|
||||||
switch (version) {
|
switch (version) {
|
||||||
|
|
@ -66,14 +71,18 @@ public class GATKReportTable {
|
||||||
|
|
||||||
// Read in the headers
|
// Read in the headers
|
||||||
for (int i = 0; i < nHeaders; i++) {
|
for (int i = 0; i < nHeaders; i++) {
|
||||||
|
try {
|
||||||
tableHeaders[i] = reader.readLine();
|
tableHeaders[i] = reader.readLine();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new ReviewedStingException(COULD_NOT_READ_HEADER + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
String[] tableData = tableHeaders[0].split(":");
|
String[] tableData = tableHeaders[0].split(":");
|
||||||
String[] userData = tableHeaders[1].split(":");
|
String[] userData = tableHeaders[1].split(":");
|
||||||
|
|
||||||
// Fill in the fields
|
// Fill in the fields
|
||||||
tableName = userData[2];
|
tableName = userData[2];
|
||||||
tableDescription = userData[3];
|
tableDescription = (userData.length <= 3) ? "" : userData[3]; // table may have no description! (and that's okay)
|
||||||
primaryKeyDisplay = Boolean.parseBoolean(tableData[2]);
|
primaryKeyDisplay = Boolean.parseBoolean(tableData[2]);
|
||||||
columns = new GATKReportColumns();
|
columns = new GATKReportColumns();
|
||||||
|
|
||||||
|
|
@ -82,7 +91,12 @@ public class GATKReportTable {
|
||||||
|
|
||||||
|
|
||||||
// Read column names
|
// Read column names
|
||||||
String columnLine = reader.readLine();
|
String columnLine;
|
||||||
|
try {
|
||||||
|
columnLine = reader.readLine();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new ReviewedStingException(COULD_NOT_READ_COLUMN_NAMES);
|
||||||
|
}
|
||||||
|
|
||||||
List<Integer> columnStarts = TextFormattingUtils.getWordStarts(columnLine);
|
List<Integer> columnStarts = TextFormattingUtils.getWordStarts(columnLine);
|
||||||
String[] columnNames = TextFormattingUtils.splitFixedWidth(columnLine, columnStarts);
|
String[] columnNames = TextFormattingUtils.splitFixedWidth(columnLine, columnStarts);
|
||||||
|
|
@ -106,7 +120,13 @@ public class GATKReportTable {
|
||||||
|
|
||||||
for (int i = 0; i < nRows; i++) {
|
for (int i = 0; i < nRows; i++) {
|
||||||
// read line
|
// read line
|
||||||
List<String> lineSplits = Arrays.asList(TextFormattingUtils.splitFixedWidth(reader.readLine(), columnStarts));
|
String dataLine;
|
||||||
|
try {
|
||||||
|
dataLine = reader.readLine();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new ReviewedStingException(COULD_NOT_READ_DATA_LINE + e.getMessage());
|
||||||
|
}
|
||||||
|
List<String> lineSplits = Arrays.asList(TextFormattingUtils.splitFixedWidth(dataLine, columnStarts));
|
||||||
|
|
||||||
for (int columnIndex = 0; columnIndex < nColumns; columnIndex++) {
|
for (int columnIndex = 0; columnIndex < nColumns; columnIndex++) {
|
||||||
|
|
||||||
|
|
@ -127,12 +147,15 @@ public class GATKReportTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
reader.readLine();
|
reader.readLine();
|
||||||
// When you see empty line or null, quit out
|
} catch (IOException e) {
|
||||||
|
throw new ReviewedStingException(COULD_NOT_READ_EMPTY_LINE + e.getMessage());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
break;
|
||||||
//throw new StingException("Cannot read GATKReport: " + e);
|
|
||||||
e.printStackTrace();
|
default:
|
||||||
|
throw new ReviewedStingException(OLD_GATK_TABLE_VERSION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -418,12 +441,11 @@ public class GATKReportTable {
|
||||||
if (newValue != null)
|
if (newValue != null)
|
||||||
value = newValue;
|
value = newValue;
|
||||||
|
|
||||||
if (column.getDataType().equals(GATKReportDataType.fromObject(value)) ||
|
// todo -- Types have to be more flexible. For example, %d should accept Integers, Shorts and Bytes.
|
||||||
column.getDataType().equals(GATKReportDataType.Unknown) )
|
if (column.getDataType().equals(GATKReportDataType.fromObject(value)) || column.getDataType().equals(GATKReportDataType.Unknown) )
|
||||||
columns.get(columnName).put(primaryKey, value);
|
columns.get(columnName).put(primaryKey, value);
|
||||||
else
|
else
|
||||||
throw new ReviewedStingException(String.format("Tried to add an object of type: %s to a column of type: %s",
|
throw new ReviewedStingException(String.format("Tried to add an object of type: %s to a column of type: %s", GATKReportDataType.fromObject(value).name(), column.getDataType().name()));
|
||||||
GATKReportDataType.fromObject(value).name(), column.getDataType().name()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue