04ddff3fe9599a277032650e50a69df81312db6c
[jalview.git] / src / jalview / io / AlignFile.java
1 /*\r
2 * Jalview - A Sequence Alignment Editor and Viewer\r
3 * Copyright (C) 2005 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 import java.io.*;\r
24 \r
25 import java.util.*;\r
26 \r
27 \r
28 public abstract class AlignFile extends FileParse {\r
29     int noSeqs = 0;\r
30     int maxLength = 0;\r
31     Vector seqs;\r
32     Vector headers;\r
33     long start;\r
34     long end;\r
35 \r
36     public AlignFile() {\r
37     }\r
38 \r
39     public AlignFile(String inStr) {\r
40         initData();\r
41         System.out.println("is this ever called??");\r
42 \r
43         try {\r
44             parse();\r
45         } catch (Exception ex) {\r
46         }\r
47     }\r
48 \r
49     /**\r
50      * Constructor which parses the data from a file of some specified type.\r
51      * @param inFile Filename to read from.\r
52      * @param type   What type of file to read from (File, URL)\r
53      */\r
54     public AlignFile(String inFile, String type) throws IOException {\r
55         super(inFile, type);\r
56 \r
57         initData();\r
58 \r
59         parse();\r
60     }\r
61 \r
62     /**\r
63      * Return the seqs Vector\r
64      */\r
65     public Vector getSeqs() {\r
66         return seqs;\r
67     }\r
68 \r
69     /**\r
70      * Return the Sequences in the seqs Vector as an array of Sequences\r
71      */\r
72     public SequenceI[] getSeqsAsArray() {\r
73         SequenceI[] s = new SequenceI[seqs.size()];\r
74 \r
75         for (int i = 0; i < seqs.size(); i++) {\r
76             s[i] = (SequenceI) seqs.elementAt(i);\r
77         }\r
78 \r
79         return s;\r
80     }\r
81 \r
82     /**\r
83      * Initialise objects to store sequence data in.\r
84      */\r
85     protected void initData() {\r
86         seqs = new Vector();\r
87         headers = new Vector();\r
88     }\r
89 \r
90     protected void setSeqs(SequenceI[] s) {\r
91         seqs = new Vector();\r
92 \r
93         for (int i = 0; i < s.length; i++) {\r
94             seqs.addElement(s[i]);\r
95         }\r
96     }\r
97 \r
98     // Checks whether sequence is valid aa characters\r
99     protected boolean isValidProteinSequence(String sequence) {\r
100         for (int i = 0; i < sequence.length(); i++)\r
101             if (!jalview.schemes.ResidueProperties.aaHash.containsKey(\r
102                         String.valueOf(sequence.charAt(i)))) {\r
103                 return false;\r
104             }\r
105 \r
106         return true;\r
107     }\r
108 \r
109     /**\r
110      * This method must be implemented to parse the contents of the file.\r
111      */\r
112     public abstract void parse() throws IOException;\r
113 \r
114     /**\r
115      * Print out in alignment file format the Sequences in the seqs Vector.\r
116      */\r
117     public abstract String print();\r
118 }\r