X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FBLCFile.java;h=0edcb63556fc402b41d1a9fdb3f0d9dcbc0b2657;hb=ef3333028b291ce92bdae34bd2f8487d35d0a0d3;hp=687eef9cacef4f0a7e36bc5215695d9862a8e3e2;hpb=588042b69abf8e60bcc950b24c283933c7dd422f;p=jalview.git diff --git a/src/jalview/io/BLCFile.java b/src/jalview/io/BLCFile.java index 687eef9..0edcb63 100755 --- a/src/jalview/io/BLCFile.java +++ b/src/jalview/io/BLCFile.java @@ -25,26 +25,60 @@ import java.io.*; import java.util.*; -public class BLCFile extends AlignFile { +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ +public class BLCFile extends AlignFile +{ Vector titles; - public BLCFile() { + /** + * Creates a new BLCFile object. + */ + public BLCFile() + { } - public BLCFile(String inStr) { + /** + * Creates a new BLCFile object. + * + * @param inStr DOCUMENT ME! + */ + public BLCFile(String inStr) + { super(inStr); } - public BLCFile(String inFile, String type) throws IOException { + /** + * Creates a new BLCFile object. + * + * @param inFile DOCUMENT ME! + * @param type DOCUMENT ME! + * + * @throws IOException DOCUMENT ME! + */ + public BLCFile(String inFile, String type) throws IOException + { super(inFile, type); } - public void initData() { + /** + * DOCUMENT ME! + */ + public void initData() + { super.initData(); titles = new Vector(); } - public void parse() { + /** + * DOCUMENT ME! + */ + public void parse() + { boolean idsFound = false; Vector ids = new Vector(); StringBuffer[] seqstrings; @@ -53,12 +87,15 @@ public class BLCFile extends AlignFile { String line = null; - try { - do { + try + { + do + { line = nextLine(); // seek end of ids - if (line.indexOf("*") > -1) { + if (line.indexOf("*") > -1) + { idsFound = true; break; @@ -66,14 +103,16 @@ public class BLCFile extends AlignFile { int abracket = line.indexOf(">"); - if (abracket > -1) { + if (abracket > -1) + { if (line.indexOf(" ") > -1) // - { + { ///Colur it be this format? //>54402046 0 1 137 137: // or this?? // 1 >L1H14 30539 343 - try { + try + { ids.addElement(line.substring(abracket + 1, line.indexOf(" ", abracket + 1))); @@ -92,66 +131,106 @@ public class BLCFile extends AlignFile { value = Integer.parseInt(line.substring(0, line.indexOf(" "))); ends.addElement(value + ""); - } catch (Exception ex) { + } + catch (Exception ex) + { System.err.println("Error during blockfile read."); ex.printStackTrace(); - starts.addElement("0"); - ends.addElement("0"); + 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"); } - } else { - 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)); } } - } while (!idsFound); + } + while (!idsFound); int starCol = line.indexOf("*"); seqstrings = new StringBuffer[ids.size()]; - for (int i = 0; i < ids.size(); i++) { - if (seqstrings[i] == null) { + for (int i = 0; i < ids.size(); i++) + { + if (seqstrings[i] == null) + { seqstrings[i] = new StringBuffer(); } } - while ((line = nextLine()).indexOf("*") == -1) { - for (int i = 0; i < ids.size(); i++) { - if (line.length() > (i + starCol)) { + while ((line = nextLine()).indexOf("*") == -1) + { + for (int i = 0; i < ids.size(); i++) + { + if (line.length() > (i + starCol)) + { seqstrings[i].append(line.charAt(i + starCol)); } } } - for (int i = 0; i < ids.size(); i++) { + for (int i = 0; i < ids.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); } - } catch (Exception ex) { + } + catch (Exception ex) + { ex.printStackTrace(); } } - public String print() { + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public String print() + { return print(getSeqsAsArray()); } - public static String print(SequenceI[] s) { + /** + * DOCUMENT ME! + * + * @param s DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public static String print(SequenceI[] s) + { StringBuffer out = new StringBuffer(); int i = 0; int max = -1; - while ((i < s.length) && (s[i] != null)) { + while ((i < s.length) && (s[i] != null)) + { out.append(">" + s[i].getName() + "/" + s[i].getStart() + "-" + s[i].getEnd() + "\n"); - if (s[i].getSequence().length() > max) { + if (s[i].getSequence().length() > max) + { max = s[i].getSequence().length(); } @@ -160,13 +239,18 @@ public class BLCFile extends AlignFile { out.append("* iteration 1\n"); - for (int j = 0; j < max; j++) { + for (int j = 0; j < max; j++) + { i = 0; - while ((i < s.length) && (s[i] != null)) { - if (s[i].getSequence().length() > j) { + while ((i < s.length) && (s[i] != null)) + { + if (s[i].getSequence().length() > j) + { out.append(s[i].getSequence().substring(j, j + 1)); - } else { + } + else + { out.append("-"); }