Search in sources :

Example 1 with BioException

use of org.biojava.bio.BioException 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)

Example 2 with BioException

use of org.biojava.bio.BioException in project ice by JBEI.

the class PlainParser method parse.

@Override
public DNASequence parse(String textSequence) throws InvalidFormatParserException {
    SymbolList sl;
    try {
        textSequence = cleanSequence(textSequence);
        sl = new SimpleSymbolList(DNATools.getDNA().getTokenization("token"), textSequence.replaceAll("\\s+", "").replaceAll("[\\.|~]", "-").replaceAll("[0-9]", ""));
    } catch (BioException e) {
        throw new InvalidFormatParserException("Couldn't parse Plain sequence!", e);
    }
    return new DNASequence(sl.seqString());
}
Also used : DNASequence(org.jbei.ice.lib.dto.DNASequence) BioException(org.biojava.bio.BioException) SimpleSymbolList(org.biojava.bio.symbol.SimpleSymbolList) SymbolList(org.biojava.bio.symbol.SymbolList) SimpleSymbolList(org.biojava.bio.symbol.SimpleSymbolList)

Aggregations

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