From: jprocter Date: Fri, 1 Jun 2012 11:53:39 +0000 (+0100) Subject: JWS-29 patch fixes bug - wierd workaround since "^\\s*>" caused scanner to advance... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=8ce6db56df6c0a1c2baca2fc2d33bcb10067c6cd;p=jabaws.git JWS-29 patch fixes bug - wierd workaround since "^\\s*>" caused scanner to advance to end of file rather than start of next FASTA header --- diff --git a/datamodel/compbio/data/sequence/FastaReader.java b/datamodel/compbio/data/sequence/FastaReader.java index 1641d34..6c3e943 100644 --- a/datamodel/compbio/data/sequence/FastaReader.java +++ b/datamodel/compbio/data/sequence/FastaReader.java @@ -22,6 +22,9 @@ import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Iterator; import java.util.Scanner; +import java.util.regex.MatchResult; + +import javax.vecmath.MismatchedSizeException; import compbio.util.Util; @@ -67,7 +70,10 @@ import compbio.util.Util; public class FastaReader implements Iterator { private final Scanner input; - + /** + * Delimiter for the scanner + */ + private final String DELIM=">"; /** * Header data can contain non-ASCII symbols and read in UTF8 * @@ -82,7 +88,7 @@ public class FastaReader implements Iterator { */ public FastaReader(final String inputFile) throws FileNotFoundException { input = new Scanner(new File(inputFile), "UTF8"); - input.useDelimiter("\\s*>"); + input.useDelimiter(DELIM); Runtime.getRuntime().addShutdownHook(new Thread() { @Override @@ -104,7 +110,7 @@ public class FastaReader implements Iterator { public FastaReader(final InputStream inputStream) throws FileNotFoundException { input = new Scanner(inputStream); - input.useDelimiter("\\s*>"); + input.useDelimiter(DELIM); } /** * {@inheritDoc} @@ -124,10 +130,17 @@ public class FastaReader implements Iterator { * if the header or the sequence is missing * @throws IllegalStateException * if the close method was called on this instance + * @throws MismatchException - if there were no more FastaSequence's. */ @Override public FastaSequence next() { - return FastaReader.toFastaSequence(input.next()); + String fastaHeader=input.next(); + while (fastaHeader.indexOf("\n")<0 && input.hasNext()) + { + fastaHeader = fastaHeader.concat(">"); + fastaHeader = fastaHeader.concat(input.next()); + } + return FastaReader.toFastaSequence(fastaHeader); } /**