Search in sources :

Example 6 with SequenceDAO

use of org.jbei.ice.storage.hibernate.dao.SequenceDAO in project ice by JBEI.

the class BlastPlus method writeBigFastaFile.

/**
     * Retrieve all the sequences from the database, and writes it out to a fasta file on disk.
     *
     * @throws BlastException
     */
private static void writeBigFastaFile(BufferedWriter writer) throws BlastException {
    SequenceDAO sequenceDAO = DAOFactory.getSequenceDAO();
    long count = sequenceDAO.getSequenceCount();
    if (count <= 0)
        return;
    int offset = 0;
    while (offset < count) {
        Sequence sequence = sequenceDAO.getSequence(offset++);
        if (sequence == null || sequence.getEntry() == null)
            continue;
        long id = sequence.getEntry().getId();
        String sequenceString = "";
        String temp = sequence.getSequence();
        //            int sequenceLength = 0;
        if (temp != null) {
            SymbolList symL;
            try {
                symL = DNATools.createDNA(sequence.getSequence().trim());
            } catch (IllegalSymbolException e1) {
                // maybe it's rna?
                try {
                    symL = RNATools.createRNA(sequence.getSequence().trim());
                } catch (IllegalSymbolException e2) {
                    // skip this sequence
                    Logger.debug("Invalid characters in sequence for " + sequence.getEntry().getId() + ". Skipped for indexing");
                    Logger.debug(e2.toString());
                    continue;
                }
            }
            //                sequenceLength = symL.seqString().length();
            sequenceString = SequenceUtils.breakUpLines(symL.seqString() + symL.seqString());
        }
        if (sequenceString.length() > 0) {
            try {
                String idString = ">" + id;
                idString += DELIMITER + sequence.getEntry().getRecordType();
                String name = sequence.getEntry().getName() == null ? "None" : sequence.getEntry().getName();
                idString += DELIMITER + name;
                String pNumber = sequence.getEntry().getPartNumber();
                idString += DELIMITER + pNumber;
                idString += "\n";
                writer.write(idString);
                writer.write(sequenceString + "\n");
            } catch (IOException e) {
                throw new BlastException(e);
            }
        }
    }
}
Also used : IllegalSymbolException(org.biojava.bio.symbol.IllegalSymbolException) SequenceDAO(org.jbei.ice.storage.hibernate.dao.SequenceDAO) Sequence(org.jbei.ice.storage.model.Sequence) SymbolList(org.biojava.bio.symbol.SymbolList)

Aggregations

SequenceDAO (org.jbei.ice.storage.hibernate.dao.SequenceDAO)6 ArrayList (java.util.ArrayList)1 ZipEntry (java.util.zip.ZipEntry)1 IllegalSymbolException (org.biojava.bio.symbol.IllegalSymbolException)1 SymbolList (org.biojava.bio.symbol.SymbolList)1 Curation (org.jbei.ice.lib.dto.Curation)1 DNAFeature (org.jbei.ice.lib.dto.DNAFeature)1 DNASequence (org.jbei.ice.lib.dto.DNASequence)1 FeaturedDNASequence (org.jbei.ice.lib.dto.FeaturedDNASequence)1 EntryField (org.jbei.ice.lib.dto.entry.EntryField)1 AttachmentController (org.jbei.ice.lib.entry.attachment.AttachmentController)1 ByteArrayWrapper (org.jbei.ice.lib.entry.sequence.ByteArrayWrapper)1 GenbankFormatter (org.jbei.ice.lib.entry.sequence.composers.formatters.GenbankFormatter)1 SequenceFeatureDAO (org.jbei.ice.storage.hibernate.dao.SequenceFeatureDAO)1 Sequence (org.jbei.ice.storage.model.Sequence)1 Test (org.junit.Test)1