X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fjalview%2Fio%2FClustalFile.java;h=2ea1d2f3017c8588b0fe60745fd4cf153ba70520;hb=424a0faf266f649090f17dc65246cdfb4111217e;hp=71e86b354208977ef26825e91032fe0e8e055155;hpb=bacb105d85f7d068c8cd643cd337b832aeb80343;p=jalview.git diff --git a/src/jalview/io/ClustalFile.java b/src/jalview/io/ClustalFile.java index 71e86b3..2ea1d2f 100755 --- a/src/jalview/io/ClustalFile.java +++ b/src/jalview/io/ClustalFile.java @@ -27,7 +27,6 @@ import jalview.util.*; public class ClustalFile extends AlignFile { - Vector ids; public ClustalFile() { @@ -47,18 +46,18 @@ public class ClustalFile public void initData() { super.initData(); - ids = new Vector(); } - public void parse() + public void parse() throws IOException { int i = 0; boolean flag = false; Vector headers = new Vector(); Hashtable seqhash = new Hashtable(); - - String line; + StringBuffer tempseq; + String line, id; + StringTokenizer str; try { @@ -66,14 +65,13 @@ public class ClustalFile { if (line.indexOf(" ") != 0) { - StringTokenizer str = new StringTokenizer(line, " "); - String id = ""; + str = new StringTokenizer(line, " "); if (str.hasMoreTokens()) { id = str.nextToken(); - if (id.equals("CLUSTAL")) + if (id.equalsIgnoreCase("CLUSTAL")) { flag = true; } @@ -81,8 +79,6 @@ public class ClustalFile { if (flag) { - StringBuffer tempseq; - if (seqhash.containsKey(id)) { tempseq = (StringBuffer) seqhash.get(id); @@ -105,6 +101,8 @@ public class ClustalFile } } } + else + flag = true; } } } @@ -121,9 +119,6 @@ public class ClustalFile //Add sequences to the hash for (i = 0; i < headers.size(); i++) { - int start = 1; - int end = -1; - if (seqhash.get(headers.elementAt(i)) != null) { if (maxLength < seqhash.get(headers.elementAt(i)).toString() @@ -133,40 +128,16 @@ public class ClustalFile .length(); } - String head = headers.elementAt(i).toString(); - - if (head.indexOf("/") > 0) - { - StringTokenizer st = new StringTokenizer(head, "/"); - - if (st.countTokens() == 2) - { - ids.addElement(st.nextToken()); - - String tmp = st.nextToken(); - st = new StringTokenizer(tmp, "-"); + Sequence newSeq = parseId(headers.elementAt(i).toString()); + newSeq.setSequence( seqhash.get(headers.elementAt(i).toString()).toString() ); - if (st.countTokens() == 2) - { - start = Integer.valueOf(st.nextToken()) - .intValue(); - end = Integer.valueOf(st.nextToken()).intValue(); - } - } - else - { - ids.addElement(headers.elementAt(i)); - } - } - else + if (!isValidProteinSequence(newSeq.getSequence())) { - ids.addElement(headers.elementAt(i)); + throw new IOException(AppletFormatAdapter.INVALID_CHARACTERS + + " : " + newSeq.getName() + + " : " + invalidCharacter); } - Sequence newSeq = new Sequence(ids.elementAt(i).toString(), - seqhash.get(headers.elementAt(i). - toString()) - .toString(), start, end); seqs.addElement(newSeq); } @@ -185,7 +156,7 @@ public class ClustalFile return print(getSeqsAsArray()); } - public static String print(SequenceI[] s) + public String print(SequenceI[] s) { StringBuffer out = new StringBuffer("CLUSTAL\n\n"); @@ -196,8 +167,7 @@ public class ClustalFile while ( (i < s.length) && (s[i] != null)) { - String tmp = s[i].getName() + "/" + s[i].getStart() + "-" + - s[i].getEnd(); + String tmp = printId(s[i]); if (s[i].getSequence().length() > max) { @@ -228,8 +198,7 @@ public class ClustalFile while ( (j < s.length) && (s[j] != null)) { - out.append(new Format("%-" + maxid + "s").form(s[j].getName() + - "/" + s[j].getStart() + "-" + s[j].getEnd()) + " "); + out.append(new Format("%-" + maxid + "s").form( printId(s[j]) + " ")); int start = i * len; int end = start + len;