X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fio%2FFastaFile.java;h=684f867f0fe28e123bb766a2dfb762629b256820;hb=558597672640984d936ea22409a674293192a09c;hp=37c96f600a5c9b1f34282255b7ad085088b10fd7;hpb=55e2e9b22b133db8b9ff0979b0338a33081fc8fd;p=jalview.git diff --git a/src/jalview/io/FastaFile.java b/src/jalview/io/FastaFile.java index 37c96f6..684f867 100755 --- a/src/jalview/io/FastaFile.java +++ b/src/jalview/io/FastaFile.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 @@ -22,6 +22,8 @@ import jalview.datamodel.*; import java.io.*; +import java.util.*; + /** * DOCUMENT ME! @@ -31,21 +33,18 @@ import java.io.*; */ public class FastaFile extends AlignFile { - /** - * Creates a new FastaFile object. - */ - public FastaFile() - { - } + /** + * Length of a sequence line + */ + int len = 72; + + StringBuffer out; /** * Creates a new FastaFile object. - * - * @param inStr DOCUMENT ME! */ - public FastaFile(String inStr) + public FastaFile() { - super(inStr); } /** @@ -69,27 +68,57 @@ public class FastaFile extends AlignFile public void parse() throws IOException { StringBuffer sb = new StringBuffer(); - int count = 0; + boolean firstLine = true; String line; Sequence seq = null; + boolean annotation = false; + while ((line = nextLine()) != null) { + line = line.trim(); if (line.length() > 0) { - if (line.charAt(0)=='>') + if (line.charAt(0)=='>') { - if (count != 0) + if (line.startsWith(">#_")) + { + if (annotation) + { + Annotation[] anots = new Annotation[sb.length()]; + String anotString = sb.toString(); + for (int i = 0; i < sb.length(); i++) + { + anots[i] = new Annotation(anotString.substring(i, i+1), + null, + ' ', 0); + } + AlignmentAnnotation aa = new AlignmentAnnotation( + seq.getName().substring(2), seq.getDescription(), + anots); + + annotations.addElement(aa); + } + } + else + annotation = false; + + if (!firstLine) { seq.setSequence(sb.toString()); - seqs.addElement(seq); + + if (!annotation) + seqs.addElement(seq); } seq = parseId(line.substring(1)); + firstLine = false; - count++; sb = new StringBuffer(); + + if (line.startsWith(">#_")) + annotation = true; } else { @@ -98,19 +127,30 @@ public class FastaFile extends AlignFile } } - if (count > 0) + if (annotation) { - if (!isValidProteinSequence(sb.toString().toUpperCase())) - { - throw new IOException("Invalid protein sequence"); - } + Annotation[] anots = new Annotation[sb.length()]; + String anotString = sb.toString(); + for (int i = 0; i < sb.length(); i++) + { + anots[i] = new Annotation(anotString.substring(i, i + 1), + null, + ' ', 0); + } + AlignmentAnnotation aa = new AlignmentAnnotation( + seq.getName().substring(2), seq.getDescription(), + anots); + + annotations.addElement(aa); + } + else if (!firstLine) + { seq.setSequence(sb.toString()); seqs.addElement(seq); } } - /** * DOCUMENT ME! * @@ -123,8 +163,7 @@ public class FastaFile extends AlignFile */ public String print(SequenceI[] s) { - int len = 72; - StringBuffer out = new StringBuffer(); + out = new StringBuffer(); int i = 0; while ((i < s.length) && (s[i] != null)) @@ -144,11 +183,11 @@ public class FastaFile extends AlignFile if (end < s[i].getLength()) { - out.append(s[i].getSequence(start, end) + "\n"); + out.append(s[i].getSequenceAsString(start, end) + "\n"); } else if (start < s[i].getLength()) { - out.append(s[i].getSequence(start, s[i].getLength()) + "\n"); + out.append(s[i].getSequenceAsString(start, s[i].getLength()) + "\n"); } }