Formatting
[jalview.git] / src / jalview / io / AMSAFile.java
1 /*\r
2  * Jalview - A Sequence Alignment Editor and Viewer\r
3  * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4  *\r
5  * This program is free software; you can redistribute it and/or\r
6  * modify it under the terms of the GNU General Public License\r
7  * as published by the Free Software Foundation; either version 2\r
8  * of the License, or (at your option) any later version.\r
9  *\r
10  * This program is distributed in the hope that it will be useful,\r
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13  * GNU General Public License for more details.\r
14  *\r
15  * You should have received a copy of the GNU General Public License\r
16  * along with this program; if not, write to the Free Software\r
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
18  */\r
19 package jalview.io;\r
20 \r
21 import jalview.datamodel.*;\r
22 \r
23 public class AMSAFile\r
24     extends jalview.io.FastaFile\r
25 {\r
26 \r
27   AlignmentI al;\r
28   /**\r
29    * Creates a new AMSAFile object for output.\r
30    */\r
31   public AMSAFile(AlignmentI al)\r
32   {\r
33     this.al = al;\r
34   }\r
35 \r
36   /**\r
37    * DOCUMENT ME!\r
38    *\r
39    * @return DOCUMENT ME!\r
40    */\r
41   public String print()\r
42   {\r
43     super.print(getSeqsAsArray());\r
44 \r
45     AlignmentAnnotation aa;\r
46     if (al.getAlignmentAnnotation() != null)\r
47     {\r
48       for (int i = 0; i < al.getAlignmentAnnotation().length; i++)\r
49       {\r
50         aa = al.getAlignmentAnnotation()[i];\r
51         if (aa.autoCalculated || !aa.visible)\r
52         {\r
53           continue;\r
54         }\r
55 \r
56         out.append(">#_" + aa.label);\r
57         if (aa.description != null)\r
58         {\r
59           out.append(" " + aa.description);\r
60         }\r
61 \r
62         out.append("\n");\r
63 \r
64         int nochunks = (aa.annotations.length / len) + 1;\r
65 \r
66         for (int j = 0; j < nochunks; j++)\r
67         {\r
68           int start = j * len;\r
69           int end = start + len;\r
70           if (end > aa.annotations.length)\r
71           {\r
72             end = aa.annotations.length;\r
73           }\r
74 \r
75           String ch;\r
76           for (int k = start; k < end; k++)\r
77           {\r
78             if (aa.annotations[k] == null)\r
79             {\r
80               ch = " ";\r
81             }\r
82             else\r
83             {\r
84               ch = aa.annotations[k].displayCharacter;\r
85             }\r
86 \r
87             out.append(ch);\r
88 \r
89           }\r
90           out.append("\n");\r
91         }\r
92       }\r
93     }\r
94     return out.toString();\r
95   }\r
96 }\r