X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FBLCFile.java;h=04867a2a8b2ab786889c0a21c13c93b30441f433;hb=6af1258218f8fdbb2d9d6794e72db4c41ec8bf48;hp=0edcb63556fc402b41d1a9fdb3f0d9dcbc0b2657;hpb=378126d607a06854e8752d156120462459364586;p=jalview.git diff --git a/src/jalview/io/BLCFile.java b/src/jalview/io/BLCFile.java index 0edcb63..04867a2 100755 --- a/src/jalview/io/BLCFile.java +++ b/src/jalview/io/BLCFile.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 @@ -42,15 +42,6 @@ public class BLCFile extends AlignFile { } - /** - * Creates a new BLCFile object. - * - * @param inStr DOCUMENT ME! - */ - public BLCFile(String inStr) - { - super(inStr); - } /** * Creates a new BLCFile object. @@ -77,18 +68,13 @@ public class BLCFile extends AlignFile /** * DOCUMENT ME! */ - public void parse() + public void parse() throws IOException { boolean idsFound = false; - Vector ids = new Vector(); StringBuffer[] seqstrings; - Vector starts = new Vector(); - Vector ends = new Vector(); String line = null; - try - { do { line = nextLine(); @@ -105,68 +91,18 @@ public class BLCFile extends AlignFile if (abracket > -1) { - if (line.indexOf(" ") > -1) // - { - ///Colur it be this format? - //>54402046 0 1 137 137: - // or this?? - // 1 >L1H14 30539 343 - try - { - ids.addElement(line.substring(abracket + 1, - line.indexOf(" ", abracket + 1))); - - // remove p Value - line = line.substring(abracket + 1); - line = line.substring(line.indexOf(" ") + 1); - line = line.trim(); - line = line.substring(line.indexOf(" ") + 1); - line = line.trim(); - - int value = Integer.parseInt(line.substring(0, - line.indexOf(" "))); - starts.addElement(value + ""); - line = line.substring(line.indexOf(" ") + 1); - line = line.trim(); - value = Integer.parseInt(line.substring(0, - line.indexOf(" "))); - ends.addElement(value + ""); - } - catch (Exception ex) - { - System.err.println("Error during blockfile read."); - ex.printStackTrace(); - starts.addElement("1"); - ends.addElement("-1"); - } - } - else - { - if (line.indexOf("/") > -1) - { - ids.addElement(line.substring(abracket + 1, - line.indexOf("/"))); - line = line.substring(line.indexOf("/") + 1); - starts.addElement(line.substring(0, - line.indexOf("-"))); - ends.addElement(line.substring(line.indexOf("-") + - 1)); - } - else - { - ids.addElement(line.substring(abracket + 1)); - starts.addElement("1"); - ends.addElement("-1"); - } - } + line = line.substring(abracket+1); + + Sequence seq = parseId(line); + seqs.addElement(seq); } } while (!idsFound); int starCol = line.indexOf("*"); - seqstrings = new StringBuffer[ids.size()]; + seqstrings = new StringBuffer[seqs.size()]; - for (int i = 0; i < ids.size(); i++) + for (int i = 0; i < seqs.size(); i++) { if (seqstrings[i] == null) { @@ -176,7 +112,7 @@ public class BLCFile extends AlignFile while ((line = nextLine()).indexOf("*") == -1) { - for (int i = 0; i < ids.size(); i++) + for (int i = 0; i < seqs.size(); i++) { if (line.length() > (i + starCol)) { @@ -185,19 +121,20 @@ public class BLCFile extends AlignFile } } - for (int i = 0; i < ids.size(); i++) + for (int i = 0; i < seqs.size(); i++) { - Sequence newSeq = new Sequence(ids.elementAt(i).toString(), - seqstrings[i].toString(), - Integer.parseInt(starts.elementAt(i).toString()), - Integer.parseInt(ends.elementAt(i).toString())); - seqs.addElement(newSeq); + Sequence newSeq = (Sequence) seqs.elementAt(i); + + if (!isValidProteinSequence(newSeq.getSequence())) + { + throw new IOException(AppletFormatAdapter.INVALID_CHARACTERS + +" : "+ newSeq.getName() + +" : "+invalidCharacter); + } + + newSeq.setSequence(seqstrings[i].toString()); } - } - catch (Exception ex) - { - ex.printStackTrace(); - } + } /** @@ -217,21 +154,30 @@ public class BLCFile extends AlignFile * * @return DOCUMENT ME! */ - public static String print(SequenceI[] s) + public String print(SequenceI[] s) { StringBuffer out = new StringBuffer(); - + /** + * A general parser for ids. Will look for dbrefs in + * Uniprot format source|id + * And also Jalview /start-end + * + * @String id Id to be parsed + */ int i = 0; int max = -1; while ((i < s.length) && (s[i] != null)) { - out.append(">" + s[i].getName() + "/" + s[i].getStart() + "-" + - s[i].getEnd() + "\n"); + out.append(">" + printId(s[i])); + if(s[i].getDescription()!=null) + out.append(" "+s[i].getDescription()); + + out.append("\n"); - if (s[i].getSequence().length() > max) + if (s[i].getSequence().length > max) { - max = s[i].getSequence().length(); + max = s[i].getSequence().length; } i++; @@ -245,9 +191,9 @@ public class BLCFile extends AlignFile while ((i < s.length) && (s[i] != null)) { - if (s[i].getSequence().length() > j) + if (s[i].getSequence().length > j) { - out.append(s[i].getSequence().substring(j, j + 1)); + out.append(s[i].getSequenceAsString(j, j + 1)); } else {