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);
}
}
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;
}
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;
}
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;
}
}
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);
}
Aggregations