Added ability to load a GATKReport from disk.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@5134 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
5e7a5cf924
commit
83dcca7e82
|
|
@ -1,6 +1,8 @@
|
|||
package org.broadinstitute.sting.gatk.report;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import org.broadinstitute.sting.utils.exceptions.StingException;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
|
|
@ -9,10 +11,88 @@ import java.util.TreeMap;
|
|||
public class GATKReport {
|
||||
private TreeMap<String, GATKReportTable> tables;
|
||||
|
||||
/**
|
||||
* Create a new, empty GATKReport.
|
||||
*/
|
||||
public GATKReport() {
|
||||
tables = new TreeMap<String, GATKReportTable>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new GATKReport with the contents of a GATKReport on disk.
|
||||
* @param filename the path to the file to load
|
||||
*/
|
||||
public GATKReport(String filename) {
|
||||
loadReport(new File(filename));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new GATKReport with the contents of a GATKReport on disk.
|
||||
* @param file the file to load
|
||||
*/
|
||||
public GATKReport(File file) {
|
||||
tables = new TreeMap<String, GATKReportTable>();
|
||||
loadReport(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a GATKReport file from disk
|
||||
* @param file the file to load
|
||||
*/
|
||||
private void loadReport(File file) {
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||
|
||||
GATKReportTable table = null;
|
||||
String[] header = null;
|
||||
int id = 0;
|
||||
|
||||
String line;
|
||||
while ( (line = reader.readLine()) != null ) {
|
||||
if (line.startsWith("##:GATKReport.v0.1 ")) {
|
||||
line = line.replaceFirst("##:GATKReport.v0.1 ", "");
|
||||
String[] pieces = line.split(" : ");
|
||||
|
||||
String tableName = pieces[0];
|
||||
String tableDesc = pieces[1];
|
||||
|
||||
addTable(tableName, tableDesc);
|
||||
table = getTable(tableName);
|
||||
|
||||
header = null;
|
||||
} else if ( line.isEmpty() ) {
|
||||
// do nothing
|
||||
} else {
|
||||
if (table != null) {
|
||||
if (header == null) {
|
||||
header = line.split("\\s+");
|
||||
|
||||
table.addPrimaryKey("id", false);
|
||||
|
||||
for ( String columnName : header ) {
|
||||
table.addColumn(columnName, "");
|
||||
}
|
||||
|
||||
id = 0;
|
||||
} else {
|
||||
String[] entries = line.split("\\s+");
|
||||
|
||||
for (int columnIndex = 0; columnIndex < header.length; columnIndex++) {
|
||||
table.set(id, header[columnIndex], entries[columnIndex]);
|
||||
}
|
||||
|
||||
id++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new StingException("Cannot read GATKReport: " + e);
|
||||
} catch (IOException e) {
|
||||
throw new StingException("Cannot read GATKReport: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new table to the collection
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue