Search in sources :

Example 1 with SymbolList

use of org.biojava.bio.symbol.SymbolList in project ice by JBEI.

the class ABIParser method parse.

public DNASequence parse(byte[] bytes) throws InvalidFormatParserException {
    DNASequence DNASequence = null;
    try {
        ABITrace abiTrace = new ABITrace(bytes);
        SymbolList symbolList = abiTrace.getSequence();
        if (symbolList != null) {
            DNASequence = new DNASequence(symbolList.seqString().toLowerCase());
        }
    } catch (Exception e) {
        throw new InvalidFormatParserException(e);
    }
    return DNASequence;
}
Also used : DNASequence(org.jbei.ice.lib.dto.DNASequence) ABITrace(org.jbei.ice.lib.parsers.abi.ABITrace) SymbolList(org.biojava.bio.symbol.SymbolList)

Example 2 with SymbolList

use of org.biojava.bio.symbol.SymbolList in project ice by JBEI.

the class SequenceUtils method reverseComplement.

/**
     * Calculate the reverse complement of the given DNA sequence.
     *
     * @param sequence DNA sequence to reverse complement.
     * @return Reversed, complemented sequence.
     * @throws UtilityException
     */
public static String reverseComplement(String sequence) throws UtilityException {
    SymbolList symL;
    try {
        symL = DNATools.createDNA(sequence);
        symL = DNATools.reverseComplement(symL);
    } catch (IllegalSymbolException | IllegalAlphabetException e) {
        throw new UtilityException(e);
    }
    return symL.seqString();
}
Also used : IllegalAlphabetException(org.biojava.bio.symbol.IllegalAlphabetException) IllegalSymbolException(org.biojava.bio.symbol.IllegalSymbolException) SymbolList(org.biojava.bio.symbol.SymbolList)

Example 3 with SymbolList

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

Example 4 with SymbolList

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

Example 5 with SymbolList

use of org.biojava.bio.symbol.SymbolList in project ice by JBEI.

the class BlastPlus method writeBigFastaFileForFeatures.

/**
     * Writes the fasta file (part of the blast database) that contains all the features that exists on this system.
     * This routine is expected to be called as part of the blast sequence feature database rebuild
     *
     * @param writer writer for fasta file
     * @throws BlastException
     */
private static void writeBigFastaFileForFeatures(BufferedWriter writer) throws BlastException {
    FeatureDAO featureDAO = DAOFactory.getFeatureDAO();
    SequenceFeatureDAO sequenceFeatureDAO = DAOFactory.getSequenceFeatureDAO();
    long count = featureDAO.getFeatureCount(null);
    if (count <= 0)
        return;
    int offset = 0;
    while (offset < count) {
        List<Feature> features = featureDAO.getFeatures(offset++, 1, null);
        Feature feature = features.get(0);
        String featureName = feature.getName();
        if (featureName == null || featureName.trim().isEmpty())
            continue;
        if (feature.getCuration() != null && feature.getCuration().isExclude())
            continue;
        boolean hasNegativeStrand = false;
        boolean hasPositiveStrand = false;
        List<SequenceFeature> sequenceFeatures = sequenceFeatureDAO.getByFeature(feature);
        if (sequenceFeatures == null || sequenceFeatures.isEmpty()) {
            hasPositiveStrand = true;
        } else {
            for (SequenceFeature sequenceFeature : sequenceFeatures) {
                if (sequenceFeature.getStrand() == 1) {
                    hasPositiveStrand = true;
                } else if (sequenceFeature.getStrand() == -1) {
                    hasNegativeStrand = true;
                }
            }
        }
        try {
            String sequenceString = feature.getSequence().trim();
            if (StringUtils.isEmpty(sequenceString))
                continue;
            if (hasNegativeStrand) {
                try {
                    SymbolList symbolList = DNATools.createDNA(sequenceString);
                    symbolList = DNATools.reverseComplement(symbolList);
                    writeSequenceString(feature, writer, symbolList.seqString(), -1);
                } catch (IllegalSymbolException | IllegalAlphabetException e) {
                    Logger.warn(e.getMessage());
                    continue;
                }
            }
            if (hasPositiveStrand) {
                writeSequenceString(feature, writer, sequenceString, 1);
            }
        } catch (IOException e) {
            throw new BlastException(e);
        }
    }
}
Also used : IllegalAlphabetException(org.biojava.bio.symbol.IllegalAlphabetException) SequenceFeatureDAO(org.jbei.ice.storage.hibernate.dao.SequenceFeatureDAO) FeatureDAO(org.jbei.ice.storage.hibernate.dao.FeatureDAO) SequenceFeature(org.jbei.ice.storage.model.SequenceFeature) IllegalSymbolException(org.biojava.bio.symbol.IllegalSymbolException) SequenceFeature(org.jbei.ice.storage.model.SequenceFeature) DNAFeature(org.jbei.ice.lib.dto.DNAFeature) Feature(org.jbei.ice.storage.model.Feature) SequenceFeatureDAO(org.jbei.ice.storage.hibernate.dao.SequenceFeatureDAO) SymbolList(org.biojava.bio.symbol.SymbolList)

Aggregations

SymbolList (org.biojava.bio.symbol.SymbolList)6 IllegalSymbolException (org.biojava.bio.symbol.IllegalSymbolException)4 IllegalAlphabetException (org.biojava.bio.symbol.IllegalAlphabetException)3 DNASequence (org.jbei.ice.lib.dto.DNASequence)2 BioException (org.biojava.bio.BioException)1 SimpleSymbolList (org.biojava.bio.symbol.SimpleSymbolList)1 DNAFeature (org.jbei.ice.lib.dto.DNAFeature)1 ABITrace (org.jbei.ice.lib.parsers.abi.ABITrace)1 FeatureDAO (org.jbei.ice.storage.hibernate.dao.FeatureDAO)1 SequenceDAO (org.jbei.ice.storage.hibernate.dao.SequenceDAO)1 SequenceFeatureDAO (org.jbei.ice.storage.hibernate.dao.SequenceFeatureDAO)1 Feature (org.jbei.ice.storage.model.Feature)1 Sequence (org.jbei.ice.storage.model.Sequence)1 SequenceFeature (org.jbei.ice.storage.model.SequenceFeature)1