Search in sources :

Example 26 with FeaturedDNASequence

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

the class PartSequence method update.

/**
 * Updates the sequence information associated with this part with the referenced one.
 * <br>
 * Write privileges on the entry are required
 *
 * @param updatedSequence new sequence to associate with this part
 */
public void update(FeaturedDNASequence updatedSequence, boolean parseSequence) {
    entryAuthorization.expectWrite(userId, entry);
    Sequence existing = sequenceDAO.getByEntry(this.entry);
    // update with raw sequence if no sequence object is passed
    if (parseSequence) {
        // sometimes the whole sequence is sent in the string portion (when there are no features)
        // no features to add
        updatedSequence = GeneralParser.parse(updatedSequence.getSequence());
    } else if (updatedSequence.getSequence().isEmpty() && StringUtils.isNotBlank(existing.getSequence())) {
        updatedSequence.setSequence(existing.getSequence());
    }
    // convert sequence wrapper to sequence storage model
    Sequence sequence = SequenceUtil.dnaSequenceToSequence(updatedSequence);
    if (sequence == null)
        return;
    // todo : commenting out for now
    if (existing != null) {
        SequenceVersionHistory history = new SequenceVersionHistory(userId, existing.getId());
        // get features for existing entry
        existing.setSequenceFeatures(new HashSet<>(sequenceFeatureDAO.getEntrySequenceFeatures(this.entry)));
        // 1. check sequence string to see if it has changed
        checkSequenceString(history, existing, sequence);
        // 2. check features
        checkForNewFeatures(existing, sequence);
        // 3. check for removed features
        checkRemovedFeatures(existing, sequence);
        // 4. check if any existing features are updated
        checkForUpdatedFeatures(existing, sequence);
        // rebuild the trace sequence alignments // todo : this might not be needed for all updates
        new TraceSequences().rebuildAllAlignments(entry);
        // rebuild blast
        scheduleBlastIndexRebuildTask(Action.UPDATE, this.entry.getPartNumber());
    } else {
        save(updatedSequence);
    }
}
Also used : TraceSequences(org.jbei.ice.lib.entry.sequence.analysis.TraceSequences) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence)

Example 27 with FeaturedDNASequence

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

the class Sequences method getFeaturedSequence.

protected FeaturedDNASequence getFeaturedSequence(Entry entry, boolean canEdit) {
    Sequence sequence = dao.getByEntry(entry);
    if (sequence == null) {
        FeaturedDNASequence featuredDNASequence = new FeaturedDNASequence();
        featuredDNASequence.setName(entry.getName());
        return featuredDNASequence;
    }
    List<SequenceFeature> sequenceFeatures = DAOFactory.getSequenceFeatureDAO().getEntrySequenceFeatures(entry);
    FeaturedDNASequence featuredDNASequence = SequenceUtil.sequenceToDNASequence(sequence, sequenceFeatures);
    featuredDNASequence.setCanEdit(canEdit);
    featuredDNASequence.setIdentifier(entry.getPartNumber());
    String uriPrefix = DAOFactory.getConfigurationDAO().get(ConfigurationKey.URI_PREFIX).getValue();
    if (!StringUtils.isEmpty(uriPrefix)) {
        featuredDNASequence.setUri(uriPrefix + "/entry/" + entry.getId());
    }
    return featuredDNASequence;
}
Also used : FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence)

Example 28 with FeaturedDNASequence

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

the class Features method get.

public Results<DNAFeature> get(int start, int count) {
    Entry entry = super.getEntry(this.sequenceIdentifier);
    List<SequenceFeature> list = dao.pageSequenceFeatures(entry, start, count);
    long number = dao.countSequenceFeatures(entry);
    Sequence sequence = new Sequence();
    sequence.setEntry(entry);
    FeaturedDNASequence featuredDNASequence = SequenceUtil.sequenceToDNASequence(sequence, list);
    Results<DNAFeature> results = new Results<>();
    results.setResultCount(number);
    results.setData(featuredDNASequence.getFeatures());
    return results;
}
Also used : HasEntry(org.jbei.ice.lib.entry.HasEntry) Entry(org.jbei.ice.storage.model.Entry) Results(org.jbei.ice.lib.dto.common.Results) SequenceFeature(org.jbei.ice.storage.model.SequenceFeature) Sequence(org.jbei.ice.storage.model.Sequence) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) DNAFeature(org.jbei.ice.lib.dto.DNAFeature) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence)

Example 29 with FeaturedDNASequence

use of org.jbei.ice.lib.dto.FeaturedDNASequence 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 = featuresBlastDatabase.runBlast(query);
        FeaturedDNASequence dnaSequence = new FeaturedDNASequence();
        if (features.isEmpty())
            return dnaSequence;
        // 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 30 with FeaturedDNASequence

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

the class WebResource method getWebEntrySequence.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/entries/{entryId}/sequence")
public Response getWebEntrySequence(@PathParam("id") final long partnerId, @PathParam("entryId") final String entryId) {
    requireUserId();
    final FeaturedDNASequence result = remoteEntries.getPublicEntrySequence(partnerId, entryId);
    Configuration configuration = DAOFactory.getConfigurationDAO().get(ConfigurationKey.URI_PREFIX);
    if (configuration != null && result != null) {
        String uriPrefix = configuration.getValue();
        result.setUri(uriPrefix + "/web/" + partnerId + "/entry/" + entryId);
    }
    return super.respond(Response.Status.OK, result);
}
Also used : Configuration(org.jbei.ice.storage.model.Configuration) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence)

Aggregations

FeaturedDNASequence (org.jbei.ice.lib.dto.FeaturedDNASequence)47 Test (org.junit.Test)23 HibernateRepositoryTest (org.jbei.ice.storage.hibernate.HibernateRepositoryTest)17 Account (org.jbei.ice.storage.model.Account)17 Sequence (org.jbei.ice.storage.model.Sequence)14 DNAFeature (org.jbei.ice.lib.dto.DNAFeature)8 Plasmid (org.jbei.ice.storage.model.Plasmid)8 IOException (java.io.IOException)5 SequenceInfo (org.jbei.ice.lib.dto.entry.SequenceInfo)5 Strain (org.jbei.ice.storage.model.Strain)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InvalidFormatParserException (org.jbei.ice.lib.parsers.InvalidFormatParserException)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ArrayList (java.util.ArrayList)3 BioException (org.biojava.bio.BioException)3 PartData (org.jbei.ice.lib.dto.entry.PartData)3 BufferedReader (java.io.BufferedReader)2 StringReader (java.io.StringReader)2 Date (java.util.Date)2 LinkedList (java.util.LinkedList)2