X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FBLCFile.java;h=a7cc1eadf490f4b5b4ae6bec70c23b5de664d71b;hb=ca05d2959da096c30276df437bc24fcf9dc5adb6;hp=7961810c33c927c360700a62d7953173064d1167;hpb=99c58ee0ae2a848f982552e53feaf6d5cb9925e5;p=jalview.git diff --git a/src/jalview/io/BLCFile.java b/src/jalview/io/BLCFile.java index 7961810..a7cc1ea 100755 --- a/src/jalview/io/BLCFile.java +++ b/src/jalview/io/BLCFile.java @@ -16,160 +16,216 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ - package jalview.io; import jalview.datamodel.*; import java.io.*; -import java.util.*; - -public class BLCFile extends AlignFile { - - Vector titles; - public BLCFile() - {} - - public BLCFile(String inStr) { - super(inStr); - } - - public void initData() { - super.initData(); - titles = new Vector(); - } +import java.util.*; - public BLCFile(String inFile, String type) throws IOException { - super(inFile,type); - } +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ +public class BLCFile extends AlignFile +{ + Vector titles; + + /** + * Creates a new BLCFile object. + */ + public BLCFile() + { + } - public void parse() - { - boolean idsFound=false; - Vector ids = new Vector(); - StringBuffer seqstrings []; - Vector starts = new Vector(); - Vector ends = new Vector(); + /** + * Creates a new BLCFile object. + * + * @param inStr DOCUMENT ME! + */ + public BLCFile(String inStr) + { + super(inStr); + } - String line=null; - try{ - do{ - line = nextLine(); + /** + * 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); + } - // seek end of ids - if (line.indexOf("*") > -1) - { - idsFound=true; - break; - } + /** + * DOCUMENT ME! + */ + public void initData() + { + super.initData(); + titles = new Vector(); + } - int abracket = line.indexOf(">"); + /** + * DOCUMENT ME! + */ + public void parse() + { + boolean idsFound = false; + Vector ids = new Vector(); + StringBuffer[] seqstrings; + Vector starts = new Vector(); + Vector ends = new Vector(); - if (abracket > -1) - { + String line = null; - if(line.indexOf(" ")>-1)// + try { - ///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("0"); - ends.addElement("0"); - } - + do + { + line = nextLine(); + + // seek end of ids + if (line.indexOf("*") > -1) + { + idsFound = true; + + break; + } + + int abracket = line.indexOf(">"); + + if (abracket > -1) + { + if (line.indexOf(" ") > -1) // + { + line = line.substring(abracket + 1, + line.indexOf(" ", abracket + 1)); + } + else + line = line.substring(abracket+1); + + + Sequence seq = parseId(line); + ids.addElement(seq.getName()); + starts.addElement(seq.getStart() + ""); + ends.addElement(seq.getEnd() + ""); + } + } + while (!idsFound); + + int starCol = line.indexOf("*"); + seqstrings = new StringBuffer[ids.size()]; + + 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)) + { + seqstrings[i].append(line.charAt(i + starCol)); + } + } + } + + 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); + } } - else + catch (Exception ex) { - 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)); + ex.printStackTrace(); } - } - }while(!idsFound); - - int starCol = line.indexOf("*"); - seqstrings = new StringBuffer[ids.size()]; - for(int i=0; ii+starCol) - seqstrings[i].append(line.charAt(i + starCol)); - } + return print(getSeqsAsArray()); } - for(int i=0; i" + printId(s[i]) +"\n"); - }catch(Exception ex){ex.printStackTrace();} - } - - public String print() { - return print(getSeqsAsArray()); - } - public static String print(SequenceI[] s) { - StringBuffer out = new StringBuffer(); - - 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"); - if (s[i].getSequence().length() > max) { max = s[i].getSequence().length();} - i++; - } + if (s[i].getSequence().length() > max) + { + max = s[i].getSequence().length(); + } - out.append("* iteration 1\n"); - for (int j = 0; j < max; j++) { - i=0; - while (i < s.length && s[i] != null) { - if(s[i].getSequence().length()>j ) - out.append(s[i].getSequence().substring(j,j+1)); - else - out.append("-"); - i++; + i++; } - out.append("\n"); - } - out.append("*\n"); - return out.toString(); - } + out.append("* iteration 1\n"); + + for (int j = 0; j < max; j++) + { + i = 0; + + while ((i < s.length) && (s[i] != null)) + { + if (s[i].getSequence().length() > j) + { + out.append(s[i].getSequence().substring(j, j + 1)); + } + else + { + out.append("-"); + } + + i++; + } + + out.append("\n"); + } + + out.append("*\n"); + + return out.toString(); + } }