Search in sources :

Example 1 with AbstractParser

use of org.jbei.ice.lib.parsers.AbstractParser in project ice by JBEI.

the class PartSequence method parseSequenceFile.

/**
     * Parses a sequence in a file and associates it with the current entry
     *
     * @param inputStream input stream of bytes representing the file
     * @param fileName    name of file being parsed
     * @return wrapper around the internal model used to represent sequence information
     * @throws IOException on Exception parsing the contents of the file
     */
public SequenceInfo parseSequenceFile(InputStream inputStream, String fileName) throws IOException {
    try {
        AbstractParser parser;
        String sequenceString = Utils.getString(inputStream);
        switch(detectFormat(sequenceString)) {
            case GENBANK:
                parser = new GenBankParser();
                break;
            case SBOL2:
                SBOLParser sbolParser = new SBOLParser(this.userId, Long.toString(this.entry.getId()));
                return sbolParser.parseToEntry(sequenceString, fileName);
            case FASTA:
                parser = new FastaParser();
                break;
            default:
            case PLAIN:
                parser = new PlainParser();
                break;
        }
        // parse actual sequence
        DNASequence sequence = parser.parse(sequenceString);
        return save(sequence, sequenceString, fileName);
    } catch (InvalidFormatParserException e) {
        Logger.error(e);
        throw new IOException(e);
    }
}
Also used : GenBankParser(org.jbei.ice.lib.parsers.genbank.GenBankParser) AbstractParser(org.jbei.ice.lib.parsers.AbstractParser) SBOLParser(org.jbei.ice.lib.parsers.sbol.SBOLParser) PlainParser(org.jbei.ice.lib.parsers.PlainParser) FastaParser(org.jbei.ice.lib.parsers.fasta.FastaParser) InvalidFormatParserException(org.jbei.ice.lib.parsers.InvalidFormatParserException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 AbstractParser (org.jbei.ice.lib.parsers.AbstractParser)1 InvalidFormatParserException (org.jbei.ice.lib.parsers.InvalidFormatParserException)1 PlainParser (org.jbei.ice.lib.parsers.PlainParser)1 FastaParser (org.jbei.ice.lib.parsers.fasta.FastaParser)1 GenBankParser (org.jbei.ice.lib.parsers.genbank.GenBankParser)1 SBOLParser (org.jbei.ice.lib.parsers.sbol.SBOLParser)1