Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 15:05:32 GMT
  2. Package jalview.io

File AlignmentProperties.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
60% of files have more coverage

Code metrics

22
49
5
1
156
102
16
0.33
9.8
5
3.2

Classes

Class Line # Actions
AlignmentProperties 38 49 16
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.io;
22   
23    import jalview.datamodel.Alignment;
24    import jalview.datamodel.AlignmentI;
25   
26    import java.io.PrintWriter;
27    import java.io.StringWriter;
28    import java.util.Enumeration;
29    import java.util.Hashtable;
30   
31    /**
32    * Render associated attributes of an alignment. The heart of this code was
33    * refactored from jalview.gui.AlignFrame and jalview.appletgui.AlignFrame TODO:
34    * consider extending the html renderer to annotate elements with CSS ids
35    * enabling finer output format control.
36    *
37    */
 
38    public class AlignmentProperties
39    {
40    AlignmentI alignment;
41   
 
42  0 toggle public AlignmentProperties(AlignmentI alignment)
43    {
44  0 this.alignment = alignment;
45    }
46   
47    /**
48    * render the alignment's properties report as text or an HTML fragment
49    *
50    * @param pw
51    * @param html
52    */
 
53  0 toggle public void writeProperties(PrintWriter pw, boolean html)
54    {
55  0 final String nl = html ? "<br>" : System.getProperty("line.separator");
56  0 float avg = 0;
57  0 int min = Integer.MAX_VALUE, max = 0;
58  0 for (int i = 0; i < alignment.getHeight(); i++)
59    {
60  0 int size = 1 + alignment.getSequenceAt(i).getEnd()
61    - alignment.getSequenceAt(i).getStart();
62  0 avg += size;
63  0 if (size > max)
64    {
65  0 max = size;
66    }
67  0 if (size < min)
68    {
69  0 min = size;
70    }
71    }
72  0 avg = avg / alignment.getHeight();
73  0 pw.print(nl);
74  0 pw.print("Sequences: " + alignment.getHeight());
75  0 pw.print(nl);
76  0 pw.print("Minimum Sequence Length: " + min);
77  0 pw.print(nl);
78  0 pw.print("Maximum Sequence Length: " + max);
79  0 pw.print(nl);
80  0 pw.print("Average Length: " + (int) avg);
81   
82  0 if (((Alignment) alignment).alignmentProperties != null)
83    {
84  0 pw.print(nl);
85  0 pw.print(nl);
86  0 if (html)
87    {
88  0 pw.print("<table border=\"1\">");
89    }
90  0 Hashtable props = ((Alignment) alignment).alignmentProperties;
91  0 Enumeration en = props.keys();
92  0 while (en.hasMoreElements())
93    {
94  0 String key = en.nextElement().toString();
95  0 String vals = props.get(key).toString();
96  0 if (html)
97    {
98    // wrap the text in the table
99  0 StringBuffer val = new StringBuffer();
100  0 int pos = 0, npos;
101  0 do
102    {
103  0 npos = vals.indexOf("\n", pos);
104  0 if (npos == -1)
105    {
106  0 val.append(vals.substring(pos));
107    }
108    else
109    {
110  0 val.append(vals.substring(pos, npos));
111  0 val.append("<br>");
112    }
113  0 pos = npos + 1;
114  0 } while (npos != -1);
115  0 pw.print("<tr><td>" + key + "</td><td>" + val + "</td></tr>");
116    }
117    else
118    {
119  0 pw.print(nl + key + "\t" + vals);
120    }
121    }
122  0 if (html)
123    {
124  0 pw.print("</table>");
125    }
126    }
127    }
128   
129    /**
130    * generate a report as plain text
131    *
132    * @return
133    */
 
134  0 toggle public StringBuffer formatAsString()
135    {
136  0 return formatReport(false);
137    }
138   
 
139  0 toggle protected StringBuffer formatReport(boolean html)
140    {
141  0 StringWriter content = new StringWriter();
142  0 writeProperties(new PrintWriter(content), html);
143  0 return content.getBuffer();
144    }
145   
146    /**
147    * generate a report as a fragment of html
148    *
149    * @return
150    */
 
151  0 toggle public StringBuffer formatAsHtml()
152    {
153  0 return formatReport(true);
154    }
155   
156    }