Search in sources :

Example 1 with Feature

use of org.jbei.ice.storage.model.Feature in project ice by JBEI.

the class FeatureDAO method getFeaturesGroupBy.

public Map<String, List<Feature>> getFeaturesGroupBy(int offset, int size) {
    Map<String, List<Feature>> results = new HashMap<>();
    try {
        CriteriaQuery<String> query = getBuilder().createQuery(String.class);
        Root<Feature> from = query.from(Feature.class);
        query.select(from.get("name")).distinct(true);
        query.where(getBuilder().isNotNull(from.get("name")), getBuilder().notEqual(from.get("name"), ""));
        query.orderBy(getBuilder().asc(from.get("name")));
        List<String> names = currentSession().createQuery(query).setFirstResult(offset).setMaxResults(size).list();
        for (String name : names) {
            CriteriaQuery<Feature> featureQuery = getBuilder().createQuery(Feature.class);
            Root<Feature> root = featureQuery.from(Feature.class);
            featureQuery.where(getBuilder().equal(getBuilder().lower(root.get("name")), name.toLowerCase()));
            List<Feature> result = currentSession().createQuery(featureQuery).list();
            results.put(name, result);
        }
        return results;
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HashMap(java.util.HashMap) HibernateException(org.hibernate.HibernateException) List(java.util.List) Feature(org.jbei.ice.storage.model.Feature)

Example 2 with Feature

use of org.jbei.ice.storage.model.Feature in project ice by JBEI.

the class FeatureDAO method getFeatureCount.

public long getFeatureCount(String filter) {
    try {
        CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
        Root<Feature> from = query.from(Feature.class);
        query.select(getBuilder().countDistinct(from.get("id")));
        buildFilter(query, from, filter);
        return currentSession().createQuery(query).uniqueResult();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) Feature(org.jbei.ice.storage.model.Feature)

Example 3 with Feature

use of org.jbei.ice.storage.model.Feature in project ice by JBEI.

the class FeatureDAO method getFeatures.

public List<Feature> getFeatures(int offset, int size, String filter) {
    try {
        CriteriaQuery<Feature> query = getBuilder().createQuery(Feature.class);
        Root<Feature> from = query.from(Feature.class);
        buildFilter(query, from, filter);
        return currentSession().createQuery(query).setFirstResult(offset).setMaxResults(size).list();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) Feature(org.jbei.ice.storage.model.Feature)

Example 4 with Feature

use of org.jbei.ice.storage.model.Feature in project ice by JBEI.

the class FeatureDAO method getFeaturesGroupByCount.

public long getFeaturesGroupByCount() {
    try {
        CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
        Root<Feature> from = query.from(Feature.class);
        query.select(getBuilder().countDistinct(from.get("name"))).where(getBuilder().isNotNull(from.get("name")), getBuilder().notEqual(from.get("name"), ""));
        return currentSession().createQuery(query).uniqueResult();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) Feature(org.jbei.ice.storage.model.Feature)

Example 5 with Feature

use of org.jbei.ice.storage.model.Feature 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)

Aggregations

Feature (org.jbei.ice.storage.model.Feature)7 HibernateException (org.hibernate.HibernateException)5 DAOException (org.jbei.ice.storage.DAOException)5 DNAFeature (org.jbei.ice.lib.dto.DNAFeature)2 SequenceFeatureDAO (org.jbei.ice.storage.hibernate.dao.SequenceFeatureDAO)2 SequenceFeature (org.jbei.ice.storage.model.SequenceFeature)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)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