Search in sources :

Example 11 with DNAFeature

use of org.jbei.ice.lib.dto.DNAFeature in project ice by JBEI.

the class Annotations method generate.

/**
     * Auto generate annotations for specified entry
     *
     * @param entryId       unique (local) identifier for entry
     * @param ownerFeatures whether to only include the features created by the requesting user
     * @return wrapper around generated annotations, if any are found
     */
public FeaturedDNASequence generate(long entryId, boolean ownerFeatures) {
    Entry entry = entryDAO.get(entryId);
    if (entry == null)
        throw new IllegalArgumentException("Could not retrieve entry with id \"" + entryId + "\"");
    Sequence sequence = sequenceDAO.getByEntry(entry);
    if (sequence == null)
        return null;
    String sequenceString = sequence.getSequence();
    BlastQuery query = new BlastQuery();
    query.setSequence(sequenceString);
    try {
        List<DNAFeature> features = BlastPlus.runCheckFeatures(query);
        FeaturedDNASequence dnaSequence = new FeaturedDNASequence();
        // check permissions
        Account account = accountDAO.getByEmail(userId);
        List<Group> groups = this.groupDAO.retrieveMemberGroups(account);
        for (DNAFeature dnaFeature : features) {
            Feature feature = this.featureDAO.get(dnaFeature.getId());
            if (feature == null)
                continue;
            List<Long> entries = this.sequenceFeatureDAO.getEntryIdsByFeature(feature);
            if (entries.isEmpty())
                continue;
            if (!isAdministrator()) {
                entries = this.permissionDAO.getCanReadEntries(account, groups, entries);
                if (entries.isEmpty())
                    continue;
            }
            if (ownerFeatures) {
                entries = this.entryDAO.filterByUserId(this.userId, entries);
            }
            if (entries != null && !entries.isEmpty()) {
                dnaFeature.getEntries().addAll(entries);
                dnaSequence.getFeatures().add(dnaFeature);
            }
        }
        dnaSequence.setLength(sequenceString.length());
        return dnaSequence;
    } catch (BlastException e) {
        Logger.error(e);
        return null;
    }
}
Also used : FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) DNAFeature(org.jbei.ice.lib.dto.DNAFeature) BlastQuery(org.jbei.ice.lib.dto.search.BlastQuery) DNAFeature(org.jbei.ice.lib.dto.DNAFeature) BlastException(org.jbei.ice.lib.search.blast.BlastException)

Example 12 with DNAFeature

use of org.jbei.ice.lib.dto.DNAFeature in project ice by JBEI.

the class Annotations method get.

/**
     * Retrieves list of annotations that are available
     *
     * @param offset paging start
     * @param limit  maximum number of annotations to return
     * @param sort   paging sort
     * @return available annotations that conform to parameters along with the total number that are available
     * @throws PermissionException if the requesting user's account does not have administrative privileges
     */
public Results<DNAFeatures> get(int offset, int limit, String sort) {
    if (!isAdministrator())
        throw new PermissionException("Administrative privileges required to retrieve features");
    long count = this.featureDAO.getFeaturesGroupByCount();
    Results<DNAFeatures> results = new Results<>();
    results.setResultCount(count);
    Map<String, List<Feature>> map = this.featureDAO.getFeaturesGroupBy(offset, limit);
    for (String key : map.keySet()) {
        DNAFeatures features = new DNAFeatures(key);
        for (Feature feature : map.get(key)) {
            DNAFeature dnaFeature = feature.toDataTransferObject();
            dnaFeature.setSequence(feature.getSequence());
            List<Long> entries = this.sequenceFeatureDAO.getEntryIdsByFeature(feature);
            if (entries != null)
                dnaFeature.getEntries().addAll(entries);
            features.getFeatures().add(dnaFeature);
        }
        results.getData().add(features);
    }
    return results;
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) DNAFeatures(org.jbei.ice.lib.dto.DNAFeatures) Results(org.jbei.ice.lib.dto.common.Results) List(java.util.List) DNAFeature(org.jbei.ice.lib.dto.DNAFeature) DNAFeature(org.jbei.ice.lib.dto.DNAFeature)

Example 13 with DNAFeature

use of org.jbei.ice.lib.dto.DNAFeature in project ice by JBEI.

the class Annotations method filter.

public Results<DNAFeature> filter(int offset, int limit, String filter) {
    Account account = accountDAO.getByEmail(userId);
    List<Group> groups = new GroupController().getAllGroups(account);
    List<SequenceFeature> features = sequenceFeatureDAO.getSequenceFeatures(this.userId, groups, filter, offset, limit);
    int count = sequenceFeatureDAO.getSequenceFeaturesCount(this.userId, groups, filter);
    Results<DNAFeature> results = new Results<>();
    results.setResultCount(count);
    for (SequenceFeature feature : features) {
        DNAFeature dnaFeature = feature.toDataTransferObject();
        Entry entry = feature.getSequence().getEntry();
        dnaFeature.setIdentifier(entry.getPartNumber());
        DNAFeatureLocation location = new DNAFeatureLocation();
        location.setGenbankStart(feature.getUniqueGenbankStart());
        location.setEnd(feature.getUniqueEnd());
        dnaFeature.getLocations().add(location);
        dnaFeature.getEntries().add(entry.getId());
        results.getData().add(dnaFeature);
    }
    return results;
}
Also used : Results(org.jbei.ice.lib.dto.common.Results) GroupController(org.jbei.ice.lib.group.GroupController) DNAFeatureLocation(org.jbei.ice.lib.dto.DNAFeatureLocation) DNAFeature(org.jbei.ice.lib.dto.DNAFeature)

Aggregations

DNAFeature (org.jbei.ice.lib.dto.DNAFeature)13 DNAFeatureLocation (org.jbei.ice.lib.dto.DNAFeatureLocation)5 PermissionException (org.jbei.ice.lib.access.PermissionException)3 ArrayList (java.util.ArrayList)2 FeaturedDNASequence (org.jbei.ice.lib.dto.FeaturedDNASequence)2 Results (org.jbei.ice.lib.dto.common.Results)2 BlastQuery (org.jbei.ice.lib.dto.search.BlastQuery)2 BlastException (org.jbei.ice.lib.search.blast.BlastException)2 SequenceAnnotation (org.sbolstandard.core.SequenceAnnotation)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 CSVReader (com.opencsv.CSVReader)1 Type (java.lang.reflect.Type)1 List (java.util.List)1 MediaType (javax.ws.rs.core.MediaType)1 Curation (org.jbei.ice.lib.dto.Curation)1 DNAFeatures (org.jbei.ice.lib.dto.DNAFeatures)1 DNASequence (org.jbei.ice.lib.dto.DNASequence)1 Annotations (org.jbei.ice.lib.entry.sequence.annotation.Annotations)1 GroupController (org.jbei.ice.lib.group.GroupController)1