/**
*
*/
package jalview.io;
import java.io.IOException;
import java.io.StringWriter;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.Hashtable;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
/**
* Render associated attributes of an alignment. The heart of this code was refactored from jalview.gui.AlignFrame and jalview.appletgui.AlignFrame
* TODO: consider extending the html renderer to annotate elements with CSS ids enabling finer output format control.
*
*/
public class AlignmentProperties
{
AlignmentI alignment;
public AlignmentProperties(AlignmentI alignment)
{
this.alignment = alignment;
}
/**
* render the alignment's properties report as text or an HTML fragment
* @param pw
* @param html
*/
public void writeProperties(PrintWriter pw, boolean html)
{
final String nl = html ? "
" : System.getProperty("line.separator");
float avg = 0;
int min = Integer.MAX_VALUE, max = 0;
for (int i = 0; i < alignment.getHeight(); i++)
{
int size = 1 + alignment.getSequenceAt(i).getEnd()
- alignment.getSequenceAt(i).getStart();
avg += size;
if (size > max)
max = size;
if (size < min)
min = size;
}
avg = avg / (float) alignment.getHeight();
pw.print(nl);
pw.print("Sequences: " + alignment.getHeight());
pw.print(nl);
pw.print("Minimum Sequence Length: " + min);
pw.print(nl);
pw.print("Maximum Sequence Length: " + max);
pw.print(nl);
pw.print("Average Length: " + (int) avg);
if (((Alignment) alignment).alignmentProperties != null)
{
pw.print(nl);
pw.print(nl);
if (html)
{
pw.print("
" + key + " | " + val + " |