Search in sources :

Example 1 with SequenceFeatureDAO

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

the class AnnotationsTest method testCurate.

@Test
public void testCurate() throws Exception {
    Account account = AccountCreator.createTestAccount("AnnotationsTest.testCurate", true);
    Plasmid plasmid = TestEntryCreator.createTestPlasmid(account);
    Assert.assertNotNull(plasmid);
    SequenceDAO sequenceDAO = new SequenceDAO();
    Assert.assertFalse(sequenceDAO.hasSequence(plasmid.getId()));
    FeaturedDNASequence dnaSequence = GeneralParser.parse(sequenceString);
    PartSequence partSequence = new PartSequence(account.getEmail(), plasmid.getRecordId());
    partSequence.save(dnaSequence);
    SequenceFeatureDAO sequenceFeatureDAO = new SequenceFeatureDAO();
    List<SequenceFeature> sequenceFeatures = sequenceFeatureDAO.getEntrySequenceFeatures(plasmid);
    Assert.assertEquals(1, sequenceFeatures.size());
    Feature feature = sequenceFeatures.get(0).getFeature();
    DNAFeature dnaFeature = feature.toDataTransferObject();
    Curation curation = new Curation();
    curation.setExclude(true);
    dnaFeature.setCuration(curation);
    List<DNAFeature> features = new ArrayList<>();
    features.add(dnaFeature);
    Annotations annotations = new Annotations(account.getEmail());
    annotations.curate(features);
    sequenceFeatures = sequenceFeatureDAO.getEntrySequenceFeatures(plasmid);
    feature = sequenceFeatures.get(0).getFeature();
    Assert.assertTrue(feature.getCuration().isExclude());
}
Also used : Account(org.jbei.ice.storage.model.Account) Curation(org.jbei.ice.lib.dto.Curation) ArrayList(java.util.ArrayList) SequenceFeature(org.jbei.ice.storage.model.SequenceFeature) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) Feature(org.jbei.ice.storage.model.Feature) SequenceFeature(org.jbei.ice.storage.model.SequenceFeature) DNAFeature(org.jbei.ice.lib.dto.DNAFeature) Plasmid(org.jbei.ice.storage.model.Plasmid) SequenceFeatureDAO(org.jbei.ice.storage.hibernate.dao.SequenceFeatureDAO) PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence) SequenceDAO(org.jbei.ice.storage.hibernate.dao.SequenceDAO) DNAFeature(org.jbei.ice.lib.dto.DNAFeature) Test(org.junit.Test)

Example 2 with SequenceFeatureDAO

use of org.jbei.ice.storage.hibernate.dao.SequenceFeatureDAO 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

DNAFeature (org.jbei.ice.lib.dto.DNAFeature)2 SequenceFeatureDAO (org.jbei.ice.storage.hibernate.dao.SequenceFeatureDAO)2 Feature (org.jbei.ice.storage.model.Feature)2 SequenceFeature (org.jbei.ice.storage.model.SequenceFeature)2 ArrayList (java.util.ArrayList)1 IllegalAlphabetException (org.biojava.bio.symbol.IllegalAlphabetException)1 IllegalSymbolException (org.biojava.bio.symbol.IllegalSymbolException)1 SymbolList (org.biojava.bio.symbol.SymbolList)1 Curation (org.jbei.ice.lib.dto.Curation)1 FeaturedDNASequence (org.jbei.ice.lib.dto.FeaturedDNASequence)1 PartSequence (org.jbei.ice.lib.entry.sequence.PartSequence)1 FeatureDAO (org.jbei.ice.storage.hibernate.dao.FeatureDAO)1 SequenceDAO (org.jbei.ice.storage.hibernate.dao.SequenceDAO)1 Account (org.jbei.ice.storage.model.Account)1 Plasmid (org.jbei.ice.storage.model.Plasmid)1 Test (org.junit.Test)1