Search in sources :

Example 31 with FeaturedDNASequence

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;
}
Also used : Entry(org.jbei.ice.storage.model.Entry) RemotePartner(org.jbei.ice.storage.model.RemotePartner) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence)

Example 32 with FeaturedDNASequence

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();
}
Also used : PartTraceSequences(org.jbei.ice.lib.entry.sequence.PartTraceSequences) Sequences(org.jbei.ice.lib.entry.sequence.Sequences) TraceSequences(org.jbei.ice.lib.entry.sequence.analysis.TraceSequences) RegistryPartner(org.jbei.ice.lib.dto.web.RegistryPartner) PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence)

Example 33 with FeaturedDNASequence

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);
    }
}
Also used : FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence)

Example 34 with FeaturedDNASequence

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());
        }
    }
}
Also used : DNAFeatureLocation(org.jbei.ice.lib.dto.DNAFeatureLocation) SequenceAnnotation(org.sbolstandard.core.SequenceAnnotation) DNAFeature(org.jbei.ice.lib.dto.DNAFeature) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) DnaSequence(org.sbolstandard.core.DnaSequence)

Example 35 with FeaturedDNASequence

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);
}
Also used : Account(org.jbei.ice.storage.model.Account) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) Test(org.junit.Test) HibernateRepositoryTest(org.jbei.ice.storage.hibernate.HibernateRepositoryTest)

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