Search in sources :

Example 1 with RichSequence

use of org.biojavax.bio.seq.RichSequence in project ice by JBEI.

the class FastaParser method parse.

@Override
public FeaturedDNASequence parse(String textSequence) throws InvalidFormatParserException {
    try {
        textSequence = cleanSequence(textSequence);
        try (BufferedReader br = new BufferedReader(new StringReader(textSequence))) {
            FeaturedDNASequence sequence;
            RichSequenceIterator richSequences = IOTools.readFastaDNA(br, null);
            if (richSequences.hasNext()) {
                RichSequence richSequence = richSequences.nextRichSequence();
                sequence = new FeaturedDNASequence(richSequence.seqString(), new LinkedList<>());
            } else {
                throw new InvalidFormatParserException("No sequence found in sequence file!");
            }
            return sequence;
        }
    } catch (BioException | IOException e) {
        throw new InvalidFormatParserException("Couldn't parse FASTA sequence!", e);
    }
}
Also used : BioException(org.biojava.bio.BioException) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) RichSequenceIterator(org.biojavax.bio.seq.RichSequenceIterator) InvalidFormatParserException(org.jbei.ice.lib.parsers.InvalidFormatParserException) IOException(java.io.IOException) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) LinkedList(java.util.LinkedList) RichSequence(org.biojavax.bio.seq.RichSequence)

Aggregations

BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 LinkedList (java.util.LinkedList)1 BioException (org.biojava.bio.BioException)1 RichSequence (org.biojavax.bio.seq.RichSequence)1 RichSequenceIterator (org.biojavax.bio.seq.RichSequenceIterator)1 FeaturedDNASequence (org.jbei.ice.lib.dto.FeaturedDNASequence)1 InvalidFormatParserException (org.jbei.ice.lib.parsers.InvalidFormatParserException)1