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