X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FClustalFile.java;h=b43e3ead651d9237ab44f18627f9647db41ae572;hb=dad6e1eb4bd44e9f70e4bbb5f3a7da6e25a917bd;hp=74cb2d0b32548f81c6cf86396da0075025cdceef;hpb=efc31b4a8d5cee63555586804a2b79c06bdb5a14;p=jalview.git diff --git a/src/jalview/io/ClustalFile.java b/src/jalview/io/ClustalFile.java index 74cb2d0..b43e3ea 100755 --- a/src/jalview/io/ClustalFile.java +++ b/src/jalview/io/ClustalFile.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -27,17 +27,11 @@ import jalview.util.*; public class ClustalFile extends AlignFile { - Vector ids; public ClustalFile() { } - public ClustalFile(String inStr) - { - super(inStr); - } - public ClustalFile(String inFile, String type) throws IOException { @@ -47,18 +41,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 +60,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 +74,6 @@ public class ClustalFile { if (flag) { - StringBuffer tempseq; - if (seqhash.containsKey(id)) { tempseq = (StringBuffer) seqhash.get(id); @@ -105,6 +96,8 @@ public class ClustalFile } } } + else + flag = true; } } } @@ -121,9 +114,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,42 +123,16 @@ public class ClustalFile .length(); } - String head = headers.elementAt(i).toString(); - start = 1; - end = seqhash.get(headers.elementAt(i)).toString().length(); - - 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); } @@ -187,7 +151,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"); @@ -198,12 +162,11 @@ 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) + if (s[i].getSequence().length > max) { - max = s[i].getSequence().length(); + max = s[i].getSequence().length; } if (tmp.length() > maxid) @@ -230,22 +193,21 @@ 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; - if ( (end < s[j].getSequence().length()) && - (start < s[j].getSequence().length())) + if ( (end < s[j].getSequence().length) && + (start < s[j].getSequence().length)) { - out.append(s[j].getSequence().substring(start, end)); + out.append(s[j].getSequenceAsString(start, end)); } else { - if (start < s[j].getSequence().length()) + if (start < s[j].getSequence().length) { - out.append(s[j].getSequence().substring(start)); + out.append(s[j].getSequenceAsString().substring(start)); } }