Jalview Imported Sources
[jalview.git] / src / jalview / io / AlignFile.java
1 package jalview.io;\r
2 \r
3 import jalview.datamodel.*;\r
4 \r
5 import java.io.*;\r
6 import java.util.*;\r
7 \r
8 public abstract class AlignFile extends FileParse {\r
9   int noSeqs    = 0;\r
10   int maxLength = 0;\r
11 \r
12   Vector    seqs;\r
13   Vector    headers;\r
14 \r
15   long start;\r
16   long end;\r
17 \r
18   public AlignFile()\r
19   {}\r
20 \r
21   public AlignFile(String inStr) {\r
22     initData();\r
23 System.out.println("is this ever called??");\r
24     try{\r
25       parse();\r
26     }catch(Exception ex){}\r
27   }\r
28 \r
29 /**\r
30  * Constructor which parses the data from a file of some specified type.\r
31  * @param inFile Filename to read from.\r
32  * @param type   What type of file to read from (File, URL)\r
33  */\r
34   public AlignFile(String inFile, String type) throws IOException {\r
35     super(inFile,type);\r
36 \r
37     initData();\r
38 \r
39     parse();\r
40 \r
41   }\r
42 \r
43 /**\r
44  * Return the seqs Vector\r
45  */\r
46   public Vector getSeqs() {\r
47     return seqs;\r
48   }\r
49 \r
50 /**\r
51  * Return the Sequences in the seqs Vector as an array of Sequences\r
52  */\r
53   public SequenceI [] getSeqsAsArray() {\r
54     SequenceI [] s = new SequenceI[seqs.size()];\r
55     for (int i=0;i < seqs.size();i++) {\r
56       s[i] = (SequenceI)seqs.elementAt(i);\r
57     }\r
58     return s;\r
59   }\r
60 \r
61 \r
62 /**\r
63  * Initialise objects to store sequence data in.\r
64  */\r
65   protected void initData() {\r
66     seqs    = new Vector();\r
67     headers = new Vector();\r
68   }\r
69 \r
70   protected void setSeqs(SequenceI [] s) {\r
71     seqs = new Vector();\r
72     for (int i=0; i<s.length; i++) {\r
73       seqs.addElement(s[i]);\r
74     }\r
75   }\r
76 \r
77   // Checks whether sequence is valid aa characters\r
78   protected boolean isValidProteinSequence(String sequence)\r
79   {\r
80     for (int i = 0; i < sequence.length(); i++)\r
81       if (!jalview.schemes.ResidueProperties.aaHash.containsKey(String.valueOf(sequence.charAt(i))))\r
82         return false;\r
83 \r
84     return true;\r
85   }\r
86 \r
87 \r
88 /**\r
89  * This method must be implemented to parse the contents of the file.\r
90  */\r
91   public abstract void parse() throws IOException;\r
92 \r
93 \r
94 /**\r
95  * Print out in alignment file format the Sequences in the seqs Vector.\r
96  */\r
97   public abstract String print();\r
98 }\r