FileFormatI further tweaks, clean compile
[jalview.git] / src / jalview / io / AMSAFile.java
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.AlignmentAnnotation;
24 import jalview.datamodel.AlignmentI;
25 import jalview.datamodel.SequenceI;
26
27 import java.io.IOException;
28
29 public class AMSAFile extends jalview.io.FastaFile
30 {
31
32   AlignmentI al;
33
34   /**
35    * Creates a new AMSAFile object for output.
36    */
37   public AMSAFile(AlignmentI al)
38   {
39     this.al = al;
40   }
41
42   public AMSAFile(String inFile, DataSourceType sourceType)
43           throws IOException
44   {
45     super(inFile, sourceType);
46   }
47
48   public AMSAFile(FileParse source) throws IOException
49   {
50     super(source);
51   }
52
53   /**
54    * DOCUMENT ME!
55    * 
56    * @return DOCUMENT ME!
57    */
58   @Override
59   public String print(SequenceI[] sqs, boolean jvsuffix)
60   {
61     super.print(sqs, jvsuffix);
62
63     AlignmentAnnotation aa;
64     if (al.getAlignmentAnnotation() != null)
65     {
66
67       for (int i = 0; i < al.getAlignmentAnnotation().length; i++)
68       {
69         aa = al.getAlignmentAnnotation()[i];
70
71         if (aa.autoCalculated || !aa.visible)
72         {
73           continue;
74         }
75
76         out.append(">#_" + aa.label);
77         if (aa.description != null)
78         {
79           out.append(" " + aa.description);
80         }
81
82         out.append(newline);
83
84         int nochunks = Math.min(aa.annotations.length, al.getWidth()) / len
85                 + 1;
86
87         for (int j = 0; j < nochunks; j++)
88         {
89           int start = j * len;
90           int end = start + len;
91           if (end > aa.annotations.length)
92           {
93             end = aa.annotations.length;
94           }
95
96           String ch;
97           for (int k = start; k < end; k++)
98           {
99             if (aa.annotations[k] == null)
100             {
101               ch = " ";
102             }
103             else
104             {
105               ch = aa.annotations[k].displayCharacter;
106             }
107             if (ch.length() > 1)
108             {
109               this.warningMessage = "Truncated column annotation to first letter.";
110               ch = ch.substring(0, 1);
111             }
112             out.append(ch);
113
114           }
115           out.append(newline);
116         }
117       }
118     }
119     return out.toString();
120   }
121 }