some cleanup for the output system.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@3032 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
c78fc23ec5
commit
8a5f0b746e
|
|
@ -1,7 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) 2010. The Broad Institute
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.broadinstitute.sting.playground.utils.report;
|
||||
|
||||
import org.broadinstitute.sting.playground.utils.report.tags.Analysis;
|
||||
import org.broadinstitute.sting.playground.utils.report.tags.Datum;
|
||||
import org.broadinstitute.sting.playground.utils.report.tags.DataPoint;
|
||||
import org.broadinstitute.sting.playground.utils.report.tags.Param;
|
||||
import org.broadinstitute.sting.playground.utils.report.tags.Table;
|
||||
import org.broadinstitute.sting.utils.StingException;
|
||||
|
|
@ -23,9 +46,9 @@ import java.util.Map;
|
|||
public class AnalysisModuleScanner {
|
||||
|
||||
// what we extracted from the class
|
||||
private Map<Param, Field> parameters = new HashMap<Param, Field>(); // the parameter annotations
|
||||
private Map<Table, Field> tables = new HashMap<Table, Field>(); // the table annotations
|
||||
private Map<Datum, Field> datums = new HashMap<Datum, Field>(); // the data we've discovered
|
||||
private Map<Field, Param> parameters = new HashMap<Field, Param>(); // the parameter annotations
|
||||
private Map<Field, Table> tables = new HashMap<Field, Table>(); // the table annotations
|
||||
private Map<Field, DataPoint> datums = new HashMap<Field, DataPoint>(); // the data we've discovered
|
||||
private Analysis analysis; // the analysis annotation
|
||||
|
||||
// private storage of the class type
|
||||
|
|
@ -68,11 +91,11 @@ public class AnalysisModuleScanner {
|
|||
for (Field f : cls.getDeclaredFields())
|
||||
for (Annotation annotation : f.getAnnotations()) {
|
||||
if (annotation.annotationType().equals(Param.class))
|
||||
parameters.put((Param) annotation, f);
|
||||
parameters.put(f, (Param) annotation);
|
||||
if (annotation.annotationType().equals(Table.class))
|
||||
tables.put((Table) annotation, f);
|
||||
if (annotation.annotationType().equals(Datum.class))
|
||||
datums.put((Datum) annotation, f);
|
||||
tables.put(f,(Table) annotation);
|
||||
if (annotation.annotationType().equals(DataPoint.class))
|
||||
datums.put(f,(DataPoint) annotation);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -80,7 +103,7 @@ public class AnalysisModuleScanner {
|
|||
*
|
||||
* @return get the list of parameters we found
|
||||
*/
|
||||
public Map<Param, Field> getParameters() {
|
||||
public Map<Field, Param> getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +111,7 @@ public class AnalysisModuleScanner {
|
|||
*
|
||||
* @return a list of table annotations found
|
||||
*/
|
||||
public Map<Table, Field> getTables() {
|
||||
public Map<Field,Table> getTables() {
|
||||
return tables;
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +119,7 @@ public class AnalysisModuleScanner {
|
|||
*
|
||||
* @return a map of the datum annotations found
|
||||
*/
|
||||
public Map<Datum, Field> getData() {
|
||||
public Map<Field, DataPoint> getData() {
|
||||
return datums;
|
||||
}
|
||||
|
||||
|
|
@ -107,4 +130,8 @@ public class AnalysisModuleScanner {
|
|||
public Analysis getAnalysis() {
|
||||
return analysis;
|
||||
}
|
||||
|
||||
public Class getModuleClass() {
|
||||
return cls;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,88 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2010. The Broad Institute
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.broadinstitute.sting.playground.utils.report;
|
||||
|
||||
import org.broadinstitute.sting.playground.utils.report.formats.OutputFormater;
|
||||
import org.broadinstitute.sting.playground.utils.report.tags.*;
|
||||
import org.broadinstitute.sting.utils.StingException;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author aaron
|
||||
* <p/>
|
||||
* Class Marshaller
|
||||
* <p/>
|
||||
* Given an analysis scan, an object, and a formatter, this class emits
|
||||
* a report to disk (or other source).
|
||||
*/
|
||||
public class Marshaller {
|
||||
private String report;
|
||||
private OutputFormater formatter;
|
||||
|
||||
/**
|
||||
* create a report
|
||||
* @param reportName the report name
|
||||
* @param formater the formater to use
|
||||
*/
|
||||
public void createReport(String reportName, OutputFormater formater) {
|
||||
this.formatter = formater;
|
||||
report = reportName;
|
||||
formatter.startReport(report);
|
||||
}
|
||||
|
||||
/**
|
||||
* add an analysis module to the output source
|
||||
* @param toMarshall the object to marshall
|
||||
*/
|
||||
public void write(Object toMarshall) {
|
||||
AnalysisModuleScanner moduleScanner = new AnalysisModuleScanner(toMarshall);
|
||||
formatter.addAnalysis(moduleScanner.getAnalysis());
|
||||
for (Param p : moduleScanner.getParameters().keySet())
|
||||
try {
|
||||
formatter.addParam(p, moduleScanner.getParameters().get(p).get(toMarshall).toString());
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new StingException("Unable to access variable " + moduleScanner.getParameters().get(p), e);
|
||||
}
|
||||
for (Datum d : moduleScanner.getData().keySet())
|
||||
try {
|
||||
formatter.addDatum(d, moduleScanner.getData().get(d).get(toMarshall).toString());
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new StingException("Unable to access variable " + moduleScanner.getParameters().get(d), e);
|
||||
}
|
||||
for (Table t : moduleScanner.getTables().keySet())
|
||||
try {
|
||||
formatter.addTable(t, new TableContainer((Collection<Object>) moduleScanner.getTables().get(t).get(toMarshall),t.columns()));
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new StingException("Unable to access variable " + moduleScanner.getParameters().get(t), e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void endReport() {
|
||||
formatter.endReport();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,205 @@
|
|||
/*
|
||||
* Copyright (c) 2010. The Broad Institute
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.broadinstitute.sting.playground.utils.report;
|
||||
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.DefaultObjectWrapper;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateException;
|
||||
import org.broadinstitute.sting.playground.utils.report.chunks.AnalysisChunk;
|
||||
import org.broadinstitute.sting.playground.utils.report.chunks.DataPointChunk;
|
||||
import org.broadinstitute.sting.playground.utils.report.chunks.ParameterChunk;
|
||||
import org.broadinstitute.sting.playground.utils.report.chunks.TableChunk;
|
||||
import org.broadinstitute.sting.utils.Pair;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author aaron
|
||||
* <p/>
|
||||
* Class ReportMarshaller
|
||||
* <p/>
|
||||
* marshall report data out of the GATK.
|
||||
*/
|
||||
public class ReportMarshaller {
|
||||
private Template temp;
|
||||
|
||||
// the aggregation of all our analyses
|
||||
private HashMap map;
|
||||
private List<Map> analysisObjects;
|
||||
private final File writeLocation;
|
||||
/**
|
||||
* create a marshaled object
|
||||
*
|
||||
* @param reportName the report name
|
||||
* @param template the template to use
|
||||
*/
|
||||
public ReportMarshaller(String reportName, File filename, Template template) {
|
||||
map = new HashMap();
|
||||
analysisObjects = new ArrayList<Map>();
|
||||
map.put("title",reportName);
|
||||
temp = template;
|
||||
this.writeLocation = filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* create a marshaled object
|
||||
*
|
||||
* @param reportName the report name
|
||||
*/
|
||||
public ReportMarshaller(String reportName, File filename) {
|
||||
map = new HashMap();
|
||||
analysisObjects = new ArrayList<Map>();
|
||||
map.put("title",reportName);
|
||||
temp = createTemplate();
|
||||
this.writeLocation = filename;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* add an analysis module to the output source
|
||||
*
|
||||
* @param toMarshall the object to marshall
|
||||
*/
|
||||
public void write(Object toMarshall) {
|
||||
// Create a context to add data to
|
||||
HashMap analysisMap = new HashMap();
|
||||
AnalysisModuleScanner moduleScanner = new AnalysisModuleScanner(toMarshall);
|
||||
|
||||
Pair<String,Object> pair;
|
||||
|
||||
pair = addAnalysis(moduleScanner);
|
||||
analysisMap.put(pair.first,pair.second);
|
||||
|
||||
pair = addParameters(toMarshall, moduleScanner);
|
||||
analysisMap.put(pair.first,pair.second);
|
||||
|
||||
pair = addDataPoints(toMarshall, moduleScanner);
|
||||
analysisMap.put(pair.first,pair.second);
|
||||
|
||||
pair = addTables(toMarshall, moduleScanner);
|
||||
analysisMap.put(pair.first,pair.second);
|
||||
|
||||
// add it to the list of analysis maps we have
|
||||
analysisObjects.add(analysisMap);
|
||||
|
||||
}
|
||||
|
||||
private Pair<String, Object> addAnalysis(AnalysisModuleScanner moduleScanner) {
|
||||
AnalysisChunk chunk = new AnalysisChunk(moduleScanner);
|
||||
return new Pair<String, Object>("analysis",chunk);
|
||||
}
|
||||
|
||||
/**
|
||||
* output the Params objects we find
|
||||
*
|
||||
* @param toMarshall the object to output
|
||||
* @param moduleScanner our scanner, which stores the annotated field information
|
||||
* @return a pair of a string and the list of Chunk objects
|
||||
*/
|
||||
private Pair<String, Object> addParameters(Object toMarshall, AnalysisModuleScanner moduleScanner) {
|
||||
List<ParameterChunk> chunks = new ArrayList<ParameterChunk>();
|
||||
for (Field f : moduleScanner.getParameters().keySet()) {
|
||||
ParameterChunk chunk = new ParameterChunk(f, moduleScanner.getParameters(), toMarshall);
|
||||
if (chunk.isValid()) chunks.add(chunk);
|
||||
}
|
||||
return new Pair<String, Object>("parameters",chunks);
|
||||
}
|
||||
|
||||
/**
|
||||
* output the Table objects we find
|
||||
*
|
||||
* @param toMarshall the object to output
|
||||
* @param moduleScanner our scanner, which stores the annotated field information
|
||||
* @return a pair of a string and the list of Chunk objects
|
||||
*/
|
||||
private Pair<String, Object> addTables(Object toMarshall, AnalysisModuleScanner moduleScanner) {
|
||||
List<TableChunk> chunks = new ArrayList<TableChunk>();
|
||||
for (Field f : moduleScanner.getTables().keySet()) {
|
||||
TableChunk chunk = new TableChunk(f, moduleScanner.getTables(), toMarshall);
|
||||
if (chunk.isValid()) chunks.add(chunk);
|
||||
}
|
||||
return new Pair<String, Object>("tables",chunks);
|
||||
}
|
||||
|
||||
/**
|
||||
* output the DataPoint objects we find
|
||||
*
|
||||
* @param toMarshall the object to output
|
||||
* @param moduleScanner our scanner, which stores the annotated field information
|
||||
* @return a pair of a string and the list of Chunk objects
|
||||
*/
|
||||
private Pair<String, Object> addDataPoints(Object toMarshall, AnalysisModuleScanner moduleScanner) {
|
||||
List<DataPointChunk> chunks = new ArrayList<DataPointChunk>();
|
||||
for (Field f : moduleScanner.getData().keySet()) {
|
||||
DataPointChunk chunk = new DataPointChunk(f, moduleScanner.getData(), toMarshall);
|
||||
if (chunk.isValid()) chunks.add(chunk);
|
||||
}
|
||||
return new Pair<String, Object>("datapoints",chunks);
|
||||
}
|
||||
|
||||
/** call the method to finalize the report */
|
||||
public void close() {
|
||||
map.put("analyses",this.analysisObjects);
|
||||
Writer out = null;
|
||||
try {
|
||||
out = new OutputStreamWriter(new FileOutputStream(this.writeLocation));
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||
}
|
||||
try {
|
||||
temp.process(map, out);
|
||||
out.flush();
|
||||
} catch (TemplateException e) {
|
||||
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
|
||||
private Template createTemplate() {
|
||||
Configuration cfg = new Configuration();
|
||||
try {
|
||||
cfg.setDirectoryForTemplateLoading(new File("templates"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
cfg.setObjectWrapper(new DefaultObjectWrapper());
|
||||
Template temp = null;
|
||||
try {
|
||||
temp = cfg.getTemplate("myTestTemp.ftl");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2010. The Broad Institute
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.broadinstitute.sting.playground.utils.report;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author aaron
|
||||
*
|
||||
* Class TableContainer
|
||||
*
|
||||
* represents a table of data, and formats according to column count. Do not use,
|
||||
* needs improvement. This is a stand-in for something better.
|
||||
*/
|
||||
public class TableContainer {
|
||||
private List<Object> tableEntries;
|
||||
private int columns = 2; // default to two
|
||||
|
||||
public TableContainer(Collection<Object> tbl, int columns) {
|
||||
tableEntries = new ArrayList<Object>();
|
||||
if (tbl instanceof List || tbl instanceof Vector || tbl instanceof Set)
|
||||
tableEntries.addAll(tbl);
|
||||
if (tbl instanceof Map)
|
||||
for (Object key : ((Map)tbl).keySet()) {
|
||||
tableEntries.add(key);
|
||||
tableEntries.add(((Map) tbl).get(key));
|
||||
}
|
||||
this.columns = columns;
|
||||
}
|
||||
|
||||
public List<List<Object>> toRows() {
|
||||
ArrayList<List<Object>> list = new ArrayList<List<Object>>();
|
||||
List<Object> currentRow = new ArrayList<Object>();
|
||||
for (Object obj : tableEntries) {
|
||||
if (currentRow.size() >= columns) {
|
||||
list.add(currentRow);
|
||||
currentRow = new ArrayList<Object>();
|
||||
}
|
||||
currentRow.add(obj);
|
||||
}
|
||||
list.add(currentRow);
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* Copyright (c) 2010. The Broad Institute
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.broadinstitute.sting.playground.utils.report;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author aaron
|
||||
*
|
||||
* Class TableFormatter
|
||||
*
|
||||
* a helper class for formatting a table of data. Given a collection, it formats it into rows and columns.
|
||||
* If it's a Map, values are emited as key, value, key, value, so it may make sense to have colums set to 2.
|
||||
*
|
||||
* TODO: Needs some cleanup
|
||||
*
|
||||
*/
|
||||
public class TableFormatter {
|
||||
public Object tableEntries; // data storage
|
||||
private int columns = 2; // default to two columns of data, overridden in the constructor
|
||||
|
||||
|
||||
public TableFormatter(Collection<Object> tbl, int columns) {
|
||||
tableEntries = tbl;
|
||||
this.columns = columns;
|
||||
}
|
||||
|
||||
public TableFormatter(Object tbl) {
|
||||
tableEntries = tbl;
|
||||
}
|
||||
|
||||
/**
|
||||
* convert the underlying object to a list of lists, for convenient output
|
||||
* @return a list of list of objects (a list for each row, then a list of row members)
|
||||
*/
|
||||
public List<List<Object>> toRows() {
|
||||
if (tableEntries instanceof Collection)
|
||||
return collectionToTable(((Collection)tableEntries));
|
||||
else if (tableEntries instanceof Map)
|
||||
return mapToTable(((Map)tableEntries));
|
||||
else
|
||||
throw new UnsupportedOperationException("underlying collection must be an instance of type Collection or of type Map");
|
||||
}
|
||||
|
||||
private List<List<Object>> mapToTable(Map collection) {
|
||||
ArrayList<List<Object>> list = new ArrayList<List<Object>>();
|
||||
for (Object obj : collection.keySet()) {
|
||||
List<Object> currentRow = new ArrayList<Object>();
|
||||
currentRow.add(obj);
|
||||
Object data = collection.get(obj);
|
||||
currentRow.add(data.toString());
|
||||
|
||||
list.add(currentRow);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<List<Object>> collectionToTable(Collection collection) {
|
||||
ArrayList<List<Object>> list = new ArrayList<List<Object>>();
|
||||
List<Object> currentRow = new ArrayList<Object>();
|
||||
for (Object obj : collection) {
|
||||
if (currentRow.size() >= columns) {
|
||||
list.add(currentRow);
|
||||
currentRow = new ArrayList<Object>();
|
||||
}
|
||||
currentRow.add(obj);
|
||||
}
|
||||
list.add(currentRow);
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2010. The Broad Institute
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.broadinstitute.sting.playground.utils.report.chunks;
|
||||
|
||||
import org.broadinstitute.sting.playground.utils.report.AnalysisModuleScanner;
|
||||
import org.broadinstitute.sting.playground.utils.report.tags.Analysis;
|
||||
|
||||
|
||||
/**
|
||||
* @author aaron
|
||||
* <p/>
|
||||
* Class AnalysisChunk
|
||||
* <p/>
|
||||
* The basic data we've decorated an analysis with
|
||||
*/
|
||||
public class AnalysisChunk implements Chunk {
|
||||
public String name;
|
||||
public String description;
|
||||
public String version;
|
||||
public String className;
|
||||
/**
|
||||
* extract the analysis data from an analysis annotation using the module scanner.
|
||||
* @param moduleScanner the module scanner
|
||||
*/
|
||||
public AnalysisChunk(AnalysisModuleScanner moduleScanner) {
|
||||
Analysis a = moduleScanner.getAnalysis();
|
||||
name = (a.name().equals("") ? moduleScanner.getModuleClass().getSimpleName() : a.name());
|
||||
description = a.description();
|
||||
version = a.version().equals("") ? "unknown" : a.version();
|
||||
className = moduleScanner.getModuleClass().getName();
|
||||
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
/**
|
||||
* is the chunk we've created valid? Invalid chunk would contain null data, or various other
|
||||
* factors that eliminate a chunk from being outputted.
|
||||
*
|
||||
* @return true if it's valid, false if not.
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
if (name == null || name.equals("")) return false;
|
||||
if (description == null || description.equals("")) return false;
|
||||
if (version == null) return false;
|
||||
if (className == null || className.equals("")) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2010. The Broad Institute
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.broadinstitute.sting.playground.utils.report.chunks;
|
||||
|
||||
/**
|
||||
* @author aaron
|
||||
* <p/>
|
||||
* Interface Chunk
|
||||
* <p/>
|
||||
* the basics of what a report data chunk needs to have
|
||||
*/
|
||||
public interface Chunk {
|
||||
/**
|
||||
* is the chunk we've created valid? Invalid chunk would contain null data, or various other
|
||||
* factors that eliminate a chunk from being outputted.
|
||||
*
|
||||
* @return true if it's valid, false if not.
|
||||
*/
|
||||
public boolean isValid();
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright (c) 2010. The Broad Institute
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.broadinstitute.sting.playground.utils.report.chunks;
|
||||
|
||||
import org.broadinstitute.sting.playground.utils.report.tags.DataPoint;
|
||||
import org.broadinstitute.sting.utils.StingException;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author aaron
|
||||
* <p/>
|
||||
* Class DataPointChunk
|
||||
* <p/>
|
||||
* a data point chunk
|
||||
*/
|
||||
public class DataPointChunk implements Chunk {
|
||||
public String name;
|
||||
public String description;
|
||||
public String value;
|
||||
|
||||
/**
|
||||
* create a DataPointChunk from extracted information
|
||||
*
|
||||
* @param dpf the datapoint field
|
||||
* @param mappings the mapping of datapoints to fields in the analysis object
|
||||
* @param toMarshall the object we're marshaling from
|
||||
*/
|
||||
public DataPointChunk(Field dpf, Map<Field, DataPoint> mappings, Object toMarshall) {
|
||||
try {
|
||||
// make sure we can access the field
|
||||
dpf.setAccessible(true);
|
||||
name = mappings.get(dpf).name().equals("") ? dpf.getName() : mappings.get(dpf).name();
|
||||
description = mappings.get(dpf).description();
|
||||
value = dpf.get(toMarshall).toString();
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new StingException("Unable to access variable " + mappings.get(mappings.get(dpf)), e);
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* is the chunk we've created valid? Invalid chunk would contain null data, or various other
|
||||
* factors that eliminate a chunk from being outputted.
|
||||
*
|
||||
* @return true if it's valid, false if not.
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
if (name == null || name.equals("")) return false;
|
||||
if (description == null || description.equals("")) return false;
|
||||
return value != null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright (c) 2010. The Broad Institute
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.broadinstitute.sting.playground.utils.report.chunks;
|
||||
|
||||
import org.broadinstitute.sting.playground.utils.report.tags.Param;
|
||||
import org.broadinstitute.sting.utils.StingException;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author aaron
|
||||
* <p/>
|
||||
* Class ParameterChunk
|
||||
* <p/>
|
||||
* The basics of a parameter
|
||||
*/
|
||||
public class ParameterChunk implements Chunk {
|
||||
public String name;
|
||||
public String description;
|
||||
public String value;
|
||||
|
||||
/**
|
||||
* create a ParameterChunk from extracted information
|
||||
*
|
||||
* @param pf the parameter annotated field
|
||||
* @param mappings the mapping of params to fields in the analysis object
|
||||
* @param toMarshall the object we're marshaling from
|
||||
*/
|
||||
public ParameterChunk(Field pf, Map<Field, Param> mappings, Object toMarshall) {
|
||||
try {
|
||||
// make sure we can access the field
|
||||
pf.setAccessible(true);
|
||||
name = mappings.get(pf).name().equals("") ? pf.getName() : mappings.get(pf).name();
|
||||
description = mappings.get(pf).description();
|
||||
value = pf.get(toMarshall).toString();
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new StingException("Unable to access variable " + pf, e);
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* is the chunk we've created valid? Invalid chunk would contain null data, or various other
|
||||
* factors that eliminate a chunk from being outputted.
|
||||
*
|
||||
* @return true if it's valid, false if not.
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
if (name == null || name.equals("")) return false;
|
||||
if (description == null || description.equals("")) return false;
|
||||
if (value == null) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* Copyright (c) 2010. The Broad Institute
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.broadinstitute.sting.playground.utils.report.chunks;
|
||||
|
||||
import org.broadinstitute.sting.playground.utils.report.TableFormatter;
|
||||
import org.broadinstitute.sting.playground.utils.report.tags.Table;
|
||||
import org.broadinstitute.sting.utils.StingException;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author aaron
|
||||
* <p/>
|
||||
* Class TableChunk
|
||||
* <p/>
|
||||
* all the information we gleam from a Table annotation, including the table entries
|
||||
*/
|
||||
public class TableChunk implements Chunk {
|
||||
public final String name;
|
||||
public final String header;
|
||||
public final String description;
|
||||
public final int columns;
|
||||
public final TableFormatter table;
|
||||
|
||||
/**
|
||||
* create a TableChunk from extracted information
|
||||
*
|
||||
* @param tbf the Table annotated field
|
||||
* @param mappings the mapping of datapoints to fields in the analysis object
|
||||
* @param toMarshall the object we're marshaling from
|
||||
*/
|
||||
public TableChunk(Field tbf, Map<Field, Table> mappings, Object toMarshall) {
|
||||
try {
|
||||
// make sure we can access the field
|
||||
tbf.setAccessible(true);
|
||||
name = mappings.get(tbf).name().equals("") ? tbf.getName() : mappings.get(tbf).name();
|
||||
description = mappings.get(tbf).description();
|
||||
header = mappings.get(tbf).header();
|
||||
columns = mappings.get(tbf).columns();
|
||||
table = new TableFormatter(tbf.get(toMarshall));
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new StingException("Unable to access variable " + tbf, e);
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public int getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public TableFormatter getTable() {
|
||||
return table;
|
||||
}
|
||||
|
||||
public List<List<Object>> getRows() {
|
||||
return table.toRows();
|
||||
}
|
||||
|
||||
/**
|
||||
* is the chunk we've created valid? Invalid chunk would contain null data, or various other
|
||||
* factors that eliminate a chunk from being outputted.
|
||||
*
|
||||
* @return true if it's valid, false if not.
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
if (this.name == null || this.name.equals("")) return false;
|
||||
if (this.header == null || this.header.equals("")) return false;
|
||||
if (this.description == null) return false;
|
||||
if (columns < 1) return false;
|
||||
if (table == null || table.tableEntries == null) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2010. The Broad Institute
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.broadinstitute.sting.playground.utils.report.formats;
|
||||
|
||||
import org.broadinstitute.sting.playground.utils.report.TableContainer;
|
||||
import org.broadinstitute.sting.playground.utils.report.tags.*;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author aaron
|
||||
*
|
||||
* Class OutputFormater
|
||||
*
|
||||
* The formatter defines a perticular output format style. The formatter methods
|
||||
* are required to be called in the following order:
|
||||
*
|
||||
* 1. startReport()
|
||||
* 2. for each analysis module:
|
||||
* addAnalysis()
|
||||
* with many addParam(), addTable(), and addDatum() in no particular order promised
|
||||
* 3. endReport()
|
||||
*/
|
||||
public interface OutputFormater {
|
||||
/**
|
||||
* start the report, given the report tag
|
||||
* @param reportName the report name.
|
||||
*/
|
||||
public void startReport(String reportName);
|
||||
|
||||
/**
|
||||
* add an analysis to the report
|
||||
* @param analysisTag the analysis tag
|
||||
*/
|
||||
public void addAnalysis(Analysis analysisTag);
|
||||
|
||||
/**
|
||||
* add a parameter value to the output location
|
||||
* @param value
|
||||
*/
|
||||
public void addParam(Param paramTag, String value);
|
||||
|
||||
/**
|
||||
* add a parameter value to the output location
|
||||
* @param value
|
||||
*/
|
||||
public void addTable(Table tableTag, TableContainer value);
|
||||
|
||||
/**
|
||||
* add a datum object to the output location
|
||||
* @param value
|
||||
*/
|
||||
public void addDatum(Datum datumTag, String value);
|
||||
|
||||
/**
|
||||
* end the report
|
||||
*/
|
||||
public void endReport();
|
||||
}
|
||||
|
|
@ -1,130 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2010. The Broad Institute
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.broadinstitute.sting.playground.utils.report.formats;
|
||||
|
||||
import org.broadinstitute.sting.playground.utils.report.TableContainer;
|
||||
import org.broadinstitute.sting.playground.utils.report.tags.*;
|
||||
import org.broadinstitute.sting.utils.StingException;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author aaron
|
||||
*
|
||||
* Class SimpleTextOutputer
|
||||
*
|
||||
* a very small demo of text output, just to use for testing and development
|
||||
*/
|
||||
public class SimpleTextOutputer implements OutputFormater {
|
||||
protected PrintWriter out;
|
||||
protected String terminator = "\n";
|
||||
protected String spacer = "\t\t\t";
|
||||
/**
|
||||
* create a simple text output format given the output file
|
||||
* @param outputFile
|
||||
*/
|
||||
public SimpleTextOutputer(File outputFile) {
|
||||
try {
|
||||
FileOutputStream stream = new FileOutputStream(outputFile);
|
||||
out = new PrintWriter(stream);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new StingException("Unable to find file ",e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* start the report, given the report tag
|
||||
*
|
||||
* @param reportTag the report tag, which describes the basics of the report
|
||||
*/
|
||||
@Override
|
||||
public void startReport(String reportTag) {
|
||||
out.write("----------------" + reportTag + "----------------" + terminator);
|
||||
}
|
||||
|
||||
/**
|
||||
* add an analysis to the report
|
||||
*
|
||||
* @param analysisTag the analysis tag
|
||||
*/
|
||||
@Override
|
||||
public void addAnalysis(Analysis analysisTag) {
|
||||
out.write("----------------" + analysisTag.name() + "----------------" + terminator);
|
||||
out.write(String.format("Name%s%s%s",spacer,analysisTag.name(),terminator));
|
||||
out.write(String.format("Description\t\t%s%s",analysisTag.description(),terminator));
|
||||
out.write(String.format("Version%s%s%s",spacer,analysisTag.version(),terminator));
|
||||
}
|
||||
|
||||
/**
|
||||
* add a parameter value to the output location
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
@Override
|
||||
public void addParam(Param paramTag, String value) {
|
||||
out.write(String.format("Param %s%s%s%s",paramTag.name(),spacer,value,terminator));
|
||||
}
|
||||
|
||||
/**
|
||||
* add a parameter value to the output location
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
@Override
|
||||
public void addTable(Table tableTag, TableContainer value) {
|
||||
out.write(tableTag.name());
|
||||
boolean first = false;
|
||||
for (List<Object> row : value.toRows()) {
|
||||
if (!first) first = true;
|
||||
else out.write("\t");
|
||||
out.write("\t\t");
|
||||
for (Object obj: row) out.write(obj+",");
|
||||
out.write(terminator);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* add a datum object to the output location
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
@Override
|
||||
public void addDatum(Datum datumTag, String value) {
|
||||
out.write("Datum "+datumTag.name()+spacer+value+terminator);
|
||||
}
|
||||
|
||||
/**
|
||||
* end the report
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void endReport() {
|
||||
out.write("----------------" + "----------------" + terminator);
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ import java.lang.annotation.RetentionPolicy;
|
|||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Analysis {
|
||||
String name(); // the name of the analysis
|
||||
String name() default ""; // the name of the analysis
|
||||
String description(); // its description, required
|
||||
String version() default "unversioned"; // the version, not always used
|
||||
String version() default ""; // the version, not always used
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,13 +29,13 @@ import java.lang.annotation.RetentionPolicy;
|
|||
/**
|
||||
* @author aaron
|
||||
* <p/>
|
||||
* Annotation Datum
|
||||
* Annotation DataPoint
|
||||
* <p/>
|
||||
* The basic Datum annotation, for fields in an analysis that
|
||||
* The basic DataPoint annotation, for fields in an analysis that
|
||||
* are to be output as data.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Datum {
|
||||
String name(); // the name, required
|
||||
String description(); // a description
|
||||
public @interface DataPoint {
|
||||
String name() default ""; // the name, required
|
||||
String description(); // a description
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package org.broadinstitute.sting.playground.utils.report;
|
|||
|
||||
import org.broadinstitute.sting.BaseTest;
|
||||
import org.broadinstitute.sting.playground.utils.report.tags.Analysis;
|
||||
import org.broadinstitute.sting.playground.utils.report.tags.DataPoint;
|
||||
import org.broadinstitute.sting.playground.utils.report.tags.Param;
|
||||
import org.broadinstitute.sting.playground.utils.report.tags.Table;
|
||||
import org.junit.Assert;
|
||||
|
|
@ -25,12 +26,12 @@ public class AnalysisModuleScannerTest extends BaseTest {
|
|||
AnalysisModuleScanner scanner = new AnalysisModuleScanner(FakeAnalysis.class);
|
||||
|
||||
// check we found one param, and check its description
|
||||
Assert.assertEquals(1, scanner.getParameters().size());
|
||||
Assert.assertTrue("basic description".equals(scanner.getParameters().keySet().iterator().next().description()));
|
||||
Assert.assertEquals(3, scanner.getParameters().size());
|
||||
Assert.assertTrue("basic description".equals(scanner.getParameters().values().iterator().next().description()));
|
||||
|
||||
// check that we've found a table, and check its description
|
||||
Assert.assertEquals(1, scanner.getTables().size());
|
||||
Assert.assertTrue("Generate a table from this data".equals(scanner.getTables().keySet().iterator().next().description()));
|
||||
Assert.assertTrue("Generate a table from this data".equals(scanner.getTables().values().iterator().next().description()));
|
||||
|
||||
// check that the analysis name and description were set
|
||||
Assert.assertTrue("testAnalysis".equals(scanner.getAnalysis().name()));
|
||||
|
|
@ -48,6 +49,21 @@ class FakeAnalysis {
|
|||
@Param(description = "basic description")
|
||||
public String text = "GRRR";
|
||||
|
||||
@Param(description = "basic description")
|
||||
public String text2superlonganme = "GRRR";
|
||||
|
||||
@Param(description = "basic description")
|
||||
public String text3 = "GRRR";
|
||||
|
||||
@DataPoint(description = "basic description")
|
||||
public String text4 = "GRRR";
|
||||
|
||||
@DataPoint(description = "basic description")
|
||||
public String text5 = "GRRR";
|
||||
|
||||
@DataPoint(description = "basic description")
|
||||
public String text6 = "GRRR";
|
||||
|
||||
@Table(name="FakeTable", description = "Generate a table from this data",columns=3)
|
||||
public List<Integer> values = new ArrayList<Integer>();
|
||||
|
||||
|
|
|
|||
|
|
@ -24,35 +24,39 @@
|
|||
package org.broadinstitute.sting.playground.utils.report;
|
||||
|
||||
import org.broadinstitute.sting.BaseTest;
|
||||
import org.broadinstitute.sting.playground.utils.report.formats.SimpleTextOutputer;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author aaron
|
||||
*
|
||||
* Class MarshallerTest
|
||||
*
|
||||
* test out the marshaller
|
||||
* @author aaron
|
||||
* <p/>
|
||||
* Class ReportMarshallerTest
|
||||
* <p/>
|
||||
* test out the marshaller
|
||||
*/
|
||||
public class MarshallerTest extends BaseTest {
|
||||
public class ReportMarshallerTest extends BaseTest {
|
||||
@Test
|
||||
public void testMarshalling() {
|
||||
// output file
|
||||
/*File fl = new File("testfile.txt");
|
||||
fl.deleteOnExit();
|
||||
Marshaller m = new Marshaller();
|
||||
SimpleTextOutputer format = new SimpleTextOutputer(fl);
|
||||
/*Configuration cfg = new Configuration();
|
||||
try {
|
||||
cfg.setDirectoryForTemplateLoading(new File("templates"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
cfg.setObjectWrapper(new DefaultObjectWrapper());
|
||||
Template temp = null;
|
||||
try {
|
||||
temp = cfg.getTemplate("myTestTemp.ftl");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
FakeAnalysis fa = new FakeAnalysis();
|
||||
|
||||
// start the marshall
|
||||
m.createReport("Fake Report",format);
|
||||
m.write(fa);
|
||||
m.write(fa);
|
||||
m.write(fa);
|
||||
m.endReport();*/
|
||||
File fl = new File("testFile.out");
|
||||
fl.deleteOnExit();
|
||||
ReportMarshaller marsh = new ReportMarshaller("report",fl,temp);
|
||||
marsh.write(fa);
|
||||
marsh.write(fa);
|
||||
marsh.write(fa);
|
||||
marsh.close();*/
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue