Search in sources :

Example 1 with PartSequence

use of org.jbei.ice.lib.entry.sequence.PartSequence in project ice by JBEI.

the class AnnotationsTest method testCurate.

@Test
public void testCurate() throws Exception {
    Account account = AccountCreator.createTestAccount("AnnotationsTest.testCurate", true);
    Plasmid plasmid = TestEntryCreator.createTestPlasmid(account);
    Assert.assertNotNull(plasmid);
    SequenceDAO sequenceDAO = new SequenceDAO();
    Assert.assertFalse(sequenceDAO.hasSequence(plasmid.getId()));
    FeaturedDNASequence dnaSequence = GeneralParser.parse(sequenceString);
    PartSequence partSequence = new PartSequence(account.getEmail(), plasmid.getRecordId());
    partSequence.save(dnaSequence);
    SequenceFeatureDAO sequenceFeatureDAO = new SequenceFeatureDAO();
    List<SequenceFeature> sequenceFeatures = sequenceFeatureDAO.getEntrySequenceFeatures(plasmid);
    Assert.assertEquals(1, sequenceFeatures.size());
    Feature feature = sequenceFeatures.get(0).getFeature();
    DNAFeature dnaFeature = feature.toDataTransferObject();
    Curation curation = new Curation();
    curation.setExclude(true);
    dnaFeature.setCuration(curation);
    List<DNAFeature> features = new ArrayList<>();
    features.add(dnaFeature);
    Annotations annotations = new Annotations(account.getEmail());
    annotations.curate(features);
    sequenceFeatures = sequenceFeatureDAO.getEntrySequenceFeatures(plasmid);
    feature = sequenceFeatures.get(0).getFeature();
    Assert.assertTrue(feature.getCuration().isExclude());
}
Also used : Account(org.jbei.ice.storage.model.Account) Curation(org.jbei.ice.lib.dto.Curation) ArrayList(java.util.ArrayList) SequenceFeature(org.jbei.ice.storage.model.SequenceFeature) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) Feature(org.jbei.ice.storage.model.Feature) SequenceFeature(org.jbei.ice.storage.model.SequenceFeature) DNAFeature(org.jbei.ice.lib.dto.DNAFeature) Plasmid(org.jbei.ice.storage.model.Plasmid) SequenceFeatureDAO(org.jbei.ice.storage.hibernate.dao.SequenceFeatureDAO) PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence) SequenceDAO(org.jbei.ice.storage.hibernate.dao.SequenceDAO) DNAFeature(org.jbei.ice.lib.dto.DNAFeature) Test(org.junit.Test)

Example 2 with PartSequence

use of org.jbei.ice.lib.entry.sequence.PartSequence in project ice by JBEI.

the class PartResource method deleteSequence.

@DELETE
@Path("/{id}/sequence")
public Response deleteSequence(@PathParam("id") final String partId) {
    final String userId = requireUserId();
    PartSequence partSequence = new PartSequence(userId, partId);
    partSequence.delete();
    return super.respond(true);
}
Also used : PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence)

Example 3 with PartSequence

use of org.jbei.ice.lib.entry.sequence.PartSequence in project ice by JBEI.

the class FileResource method downloadSequence.

@GET
@Path("{partId}/sequence/{type}")
public Response downloadSequence(@PathParam("partId") final String partId, @PathParam("type") final String downloadType, @DefaultValue("-1") @QueryParam("remoteId") long remoteId, @QueryParam("sid") String sid) {
    if (StringUtils.isEmpty(sessionId))
        sessionId = sid;
    final String userId = getUserId(sessionId);
    if (remoteId != -1) {
        RemoteSequence sequence = new RemoteSequence(remoteId, Long.decode(partId));
        final InputStreamWrapper wrapper = sequence.get(downloadType);
        StreamingOutput stream = output -> IOUtils.copy(wrapper.getInputStream(), output);
        return addHeaders(Response.ok(stream), wrapper.getName());
    } else {
        InputStreamWrapper wrapper = new PartSequence(userId, partId).toFile(SequenceFormat.fromString(downloadType), true);
        StreamingOutput stream = output -> IOUtils.copy(wrapper.getInputStream(), output);
        return addHeaders(Response.ok(stream), wrapper.getName());
    }
}
Also used : RemoteSequence(org.jbei.ice.lib.net.RemoteSequence) AttachmentInfo(org.jbei.ice.lib.dto.entry.AttachmentInfo) FormDataContentDisposition(org.glassfish.jersey.media.multipart.FormDataContentDisposition) ConfigurationSettings(org.jbei.ice.lib.config.ConfigurationSettings) Sequences(org.jbei.ice.lib.entry.sequence.Sequences) PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence) Setting(org.jbei.ice.lib.dto.Setting) TraceSequences(org.jbei.ice.lib.entry.sequence.analysis.TraceSequences) ConfigurationKey(org.jbei.ice.lib.dto.ConfigurationKey) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Entries(org.jbei.ice.lib.entry.Entries) MediaType(javax.ws.rs.core.MediaType) DAOFactory(org.jbei.ice.storage.DAOFactory) Logger(org.jbei.ice.lib.common.logging.Logger) ByteArrayInputStream(java.io.ByteArrayInputStream) FileBulkUpload(org.jbei.ice.lib.bulkupload.FileBulkUpload) SequenceInfo(org.jbei.ice.lib.dto.entry.SequenceInfo) SequenceFormat(org.jbei.ice.lib.entry.sequence.SequenceFormat) EntryType(org.jbei.ice.lib.dto.entry.EntryType) Utils(org.jbei.ice.lib.utils.Utils) EntrySelection(org.jbei.ice.lib.entry.EntrySelection) Files(java.nio.file.Files) FileUtils(org.apache.commons.io.FileUtils) StreamingOutput(javax.ws.rs.core.StreamingOutput) IOException(java.io.IOException) InputStreamWrapper(org.jbei.ice.lib.entry.sequence.InputStreamWrapper) Collectors(java.util.stream.Collectors) EntryFieldLabel(org.jbei.ice.lib.dto.entry.EntryFieldLabel) File(java.io.File) IOUtils(org.apache.commons.io.IOUtils) Attachments(org.jbei.ice.lib.entry.attachment.Attachments) RemoteEntries(org.jbei.ice.lib.net.RemoteEntries) FormDataParam(org.glassfish.jersey.media.multipart.FormDataParam) List(java.util.List) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) Paths(java.nio.file.Paths) ShotgunSequenceDAO(org.jbei.ice.storage.hibernate.dao.ShotgunSequenceDAO) TraceSequence(org.jbei.ice.storage.model.TraceSequence) EntriesAsCSV(org.jbei.ice.lib.entry.EntriesAsCSV) InvalidFormatParserException(org.jbei.ice.lib.parsers.InvalidFormatParserException) ShotgunSequence(org.jbei.ice.storage.model.ShotgunSequence) InputStream(java.io.InputStream) InputStreamWrapper(org.jbei.ice.lib.entry.sequence.InputStreamWrapper) PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence) StreamingOutput(javax.ws.rs.core.StreamingOutput) RemoteSequence(org.jbei.ice.lib.net.RemoteSequence)

Example 4 with PartSequence

use of org.jbei.ice.lib.entry.sequence.PartSequence in project ice by JBEI.

the class FileResource method uploadSequence.

/**
 * this creates an entry if an id is not specified in the form data
 */
@POST
@Path("sequence")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public Response uploadSequence(@FormDataParam("file") InputStream fileInputStream, @FormDataParam("entryRecordId") String recordId, @FormDataParam("entryType") String entryType, @FormDataParam("extractHierarchy") @DefaultValue("false") boolean extractHierarchy, @FormDataParam("file") FormDataContentDisposition contentDispositionHeader) {
    try {
        final String fileName = contentDispositionHeader.getFileName();
        String userId = getUserId();
        PartSequence partSequence;
        if (StringUtils.isEmpty(recordId)) {
            if (entryType == null) {
                entryType = "PART";
            }
            EntryType type = EntryType.nameToType(entryType);
            partSequence = new PartSequence(userId, type);
        } else {
            partSequence = new PartSequence(userId, recordId);
        }
        SequenceInfo info = partSequence.parseSequenceFile(fileInputStream, fileName, extractHierarchy);
        if (info == null)
            throw new WebApplicationException(Response.serverError().build());
        return Response.status(Response.Status.OK).entity(info).build();
    } catch (IOException e) {
        Logger.error(e);
        ErrorResponse response = new ErrorResponse();
        response.setMessage(e.getMessage());
        throw new WebApplicationException(Response.serverError().entity(response).build());
    }
}
Also used : EntryType(org.jbei.ice.lib.dto.entry.EntryType) SequenceInfo(org.jbei.ice.lib.dto.entry.SequenceInfo) PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence) IOException(java.io.IOException)

Example 5 with PartSequence

use of org.jbei.ice.lib.entry.sequence.PartSequence in project ice by JBEI.

the class BulkUploads method addSequence.

public SequenceInfo addSequence(String userId, long bulkUploadId, long entryId, String sequenceString, String fileName) {
    BulkUpload upload = dao.get(bulkUploadId);
    if (upload == null)
        return null;
    authorization.expectWrite(userId, upload);
    PartSequence partSequence = new PartSequence(userId, Long.toString(entryId));
    try {
        ByteArrayInputStream inputStream = new ByteArrayInputStream(sequenceString.getBytes(StandardCharsets.UTF_8));
        return partSequence.parseSequenceFile(inputStream, fileName, false);
    } catch (IOException e) {
        Logger.error(e);
        return null;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence) IOException(java.io.IOException)

Aggregations

PartSequence (org.jbei.ice.lib.entry.sequence.PartSequence)16 IOException (java.io.IOException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)3 EntryType (org.jbei.ice.lib.dto.entry.EntryType)3 SequenceInfo (org.jbei.ice.lib.dto.entry.SequenceInfo)3 InputStreamWrapper (org.jbei.ice.lib.entry.sequence.InputStreamWrapper)3 File (java.io.File)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 ZipOutputStream (java.util.zip.ZipOutputStream)2 FeaturedDNASequence (org.jbei.ice.lib.dto.FeaturedDNASequence)2 EntryFieldLabel (org.jbei.ice.lib.dto.entry.EntryFieldLabel)2 Entry (org.jbei.ice.storage.model.Entry)2 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ZipEntry (java.util.zip.ZipEntry)1 javax.ws.rs (javax.ws.rs)1