use of org.jbei.ice.lib.dto.FeaturedDNASequence in project ice by JBEI.
the class WebEntries method getSequence.
public FeaturedDNASequence getSequence(String entryId) {
String recordId;
try {
long id = Long.decode(entryId);
Entry entry = this.entryDAO.get(id);
if (entry == null)
recordId = entryId;
else
recordId = entry.getRecordId();
} catch (NumberFormatException ex) {
recordId = entryId;
}
List<RemotePartner> partners = this.remotePartnerDAO.getRegistryPartners();
for (RemotePartner partner : partners) {
if (partner.getPartnerStatus() != RemotePartnerStatus.APPROVED)
continue;
FeaturedDNASequence sequence = this.remoteContact.getPublicEntrySequence(partner.getUrl(), recordId, partner.getApiKey());
if (sequence != null)
return sequence;
}
return null;
}
use of org.jbei.ice.lib.dto.FeaturedDNASequence in project ice by JBEI.
the class PartResource method getSequence.
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/sequence")
public Response getSequence(@PathParam("id") final String partId, @DefaultValue("false") @QueryParam("remote") boolean isRemote, @QueryParam("token") String remoteUserToken, @QueryParam("userId") String remoteUserId, @QueryParam("folderId") long fid, @DefaultValue("true") @QueryParam("annotations") boolean includeAnnotations) {
final FeaturedDNASequence sequence;
final String userId = getUserId();
Sequences sequences = new Sequences(userId);
if (isRemote) {
// entry exists remotely
sequence = remoteEntries.getSequence(userId, fid, partId);
} else {
// what request is being responded to (local or remote)
if (StringUtils.isEmpty(userId)) {
RegistryPartner partner = requireWebPartner();
if (StringUtils.isEmpty(remoteUserToken) || fid == 0) {
sequence = new PartSequence(userId, partId).get(includeAnnotations);
} else {
sequence = sequences.getRequestedSequence(partner, remoteUserId, remoteUserToken, partId, fid);
}
} else {
// user id can be null if partId is public
sequence = new PartSequence(userId, partId).get(includeAnnotations);
}
}
return Response.status(Response.Status.OK).entity(sequence).build();
}
use of org.jbei.ice.lib.dto.FeaturedDNASequence in project ice by JBEI.
the class PartnerResource method getSequence.
/**
* @return sequence from remote ICE
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/{entryId}/sequence")
public Response getSequence(@PathParam("id") final long remoteId, @PathParam("entryId") final long partId) {
requireUserId();
try {
RemoteSequence remoteSequence = new RemoteSequence(remoteId, partId);
final FeaturedDNASequence sequence = remoteSequence.getRemoteSequence();
if (sequence == null) {
return Response.status(Response.Status.NO_CONTENT).build();
}
return Response.status(Response.Status.OK).entity(sequence).build();
} catch (IllegalArgumentException e) {
throw new WebApplicationException(Response.Status.BAD_REQUEST);
}
}
use of org.jbei.ice.lib.dto.FeaturedDNASequence in project ice by JBEI.
the class ICESBOLParserVisitor method visit.
@Override
public void visit(DnaComponent component) {
if (featuredDNASequence == null) {
featuredDNASequence = new FeaturedDNASequence();
if (update != null) {
String name = component.getName();
if (name == null || name.trim().isEmpty())
update.getKeyValue().put(EntryFieldLabel.NAME, name);
else {
update.getKeyValue().put(EntryFieldLabel.NAME, name);
update.getKeyValue().put(EntryFieldLabel.ALIAS, component.getDisplayId());
}
update.getKeyValue().put(EntryFieldLabel.SUMMARY, component.getDescription());
}
featuredDNASequence.setName(component.getName());
featuredDNASequence.setIdentifier(component.getDisplayId());
featuredDNASequence.setDescription(component.getDescription());
featuredDNASequence.setDcUri(component.getURI().toString());
DnaSequence sequence = component.getDnaSequence();
if (sequence != null) {
featuredDNASequence.setSequence(sequence.getNucleotides());
featuredDNASequence.setUri(sequence.getURI().toString());
}
}
List<SequenceAnnotation> annotations = component.getAnnotations();
Logger.debug("Encountered DC " + component.getDisplayId());
if (!annotations.isEmpty()) {
// iterate sorted annotations for top level
for (SequenceAnnotation sequenceAnnotation : annotations) {
int strand;
if (sequenceAnnotation.getStrand() == null) {
strand = 1;
} else {
strand = sequenceAnnotation.getStrand() == StrandType.POSITIVE ? 1 : -1;
}
Pair relative = new Pair(sequenceAnnotation.getBioStart(), sequenceAnnotation.getBioEnd(), strand);
walkTree(sequenceAnnotation, relative);
DNAFeature feature = createDNAFeature(sequenceAnnotation, relative);
DNAFeatureLocation location = feature.getLocations().get(0);
featuredDNASequence.getFeatures().add(feature);
Logger.debug("Adding feature [" + location.getGenbankStart() + ", " + location.getEnd() + "] for " + feature.getIdentifier());
}
}
}
use of org.jbei.ice.lib.dto.FeaturedDNASequence in project ice by JBEI.
the class PartSequenceTest method testSave.
@Test
public void testSave() throws Exception {
Account account = AccountCreator.createTestAccount("PartSequenceTest.testSave", false);
PartSequence partSequence = new PartSequence(account.getEmail(), EntryType.PLASMID);
FeaturedDNASequence sequence = GeneralParser.parse(genbank);
Assert.assertNotNull(sequence);
partSequence.save(sequence);
// compare
PartSequence existingSequence = new PartSequence(account.getEmail(), partSequence.get(true).getIdentifier());
FeaturedDNASequence dnaSequence = existingSequence.get(true);
Assert.assertEquals(1, dnaSequence.getFeatures().size());
Assert.assertEquals(234, dnaSequence.getSequence().length());
// try to save again
boolean caught = false;
try {
existingSequence.save(sequence);
} catch (IllegalArgumentException e) {
caught = true;
}
Assert.assertTrue(caught);
}
Aggregations