Search in sources :

Example 46 with SingleEndSequenceFile

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile in project irida by phac-nml.

the class RESTAnalysisSubmissionController method getAnalysisInputUnpairedFiles.

/**
 * get the {@link SequenceFile}s not in {@link SequenceFilePair}s used for
 * the {@link AnalysisSubmission}
 *
 * @param identifier
 *            the {@link AnalysisSubmission} id
 * @return list of {@link SequenceFile}s
 */
@RequestMapping("/{identifier}/sequenceFiles/unpaired")
public ModelMap getAnalysisInputUnpairedFiles(@PathVariable Long identifier) {
    ModelMap map = new ModelMap();
    AnalysisSubmission analysisSubmission = analysisSubmissionService.read(identifier);
    Set<SingleEndSequenceFile> inputFilesSingleEnd = sequencingObjectService.getSequencingObjectsOfTypeForAnalysisSubmission(analysisSubmission, SingleEndSequenceFile.class);
    ResourceCollection<SequencingObject> resources = new ResourceCollection<>(inputFilesSingleEnd.size());
    for (SingleEndSequenceFile file : inputFilesSingleEnd) {
        SampleSequencingObjectJoin join = sampleService.getSampleForSequencingObject(file);
        if (join != null) {
            SequencingObject sequencingObject = join.getObject();
            RESTSampleSequenceFilesController.addSequencingObjectLinks(sequencingObject, join.getSubject().getId());
            resources.add(sequencingObject);
        }
    }
    resources.add(linkTo(methodOn(RESTAnalysisSubmissionController.class).getAnalysisInputUnpairedFiles(identifier)).withSelfRel());
    map.addAttribute(RESTGenericController.RESOURCE_NAME, resources);
    return map;
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) ModelMap(org.springframework.ui.ModelMap) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 47 with SingleEndSequenceFile

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile in project irida by phac-nml.

the class SingleEndSequenceFileConcatenator method concatenateFiles.

/**
 * {@inheritDoc}
 */
@Override
public SingleEndSequenceFile concatenateFiles(List<? extends SequencingObject> toConcatenate, String filename) throws ConcatenateException {
    Path tempFile;
    // create the filename with extension
    filename = filename + ".fastq";
    try {
        // create a temp directory and temp file
        Path tempDirectory = Files.createTempDirectory(null);
        tempFile = tempDirectory.resolve(filename);
        tempFile = Files.createFile(tempFile);
    } catch (IOException e) {
        throw new ConcatenateException("Could not create temporary files", e);
    }
    // for each file concatenate the file
    for (SequencingObject f : toConcatenate) {
        SingleEndSequenceFile single = (SingleEndSequenceFile) f;
        SequenceFile forwardSequenceFile = single.getSequenceFile();
        appendToFile(tempFile, forwardSequenceFile);
    }
    // create the new sequencefile and object
    SequenceFile forward = new SequenceFile(tempFile);
    SingleEndSequenceFile seqObject = new SingleEndSequenceFile(forward);
    return seqObject;
}
Also used : Path(java.nio.file.Path) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) IOException(java.io.IOException) ConcatenateException(ca.corefacility.bioinformatics.irida.exceptions.ConcatenateException) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)

Example 48 with SingleEndSequenceFile

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile in project irida by phac-nml.

the class SingleEndSequenceFileRemoteRepositoryImpl method setRemoteStatus.

@Override
protected <T extends IridaResourceSupport> T setRemoteStatus(T entity, RemoteAPI api) {
    entity = super.setRemoteStatus(entity, api);
    SingleEndSequenceFile singleFile = (SingleEndSequenceFile) entity;
    super.setRemoteStatus(singleFile.getSequenceFile(), api);
    return entity;
}
Also used : SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)

Example 49 with SingleEndSequenceFile

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile in project irida by phac-nml.

the class RESTSampleSequenceFilesController method addNewSequenceFileToSample.

/**
 * Add a new {@link SequenceFile} to a {@link Sample}.
 *
 * @param sampleId
 *            the identifier for the {@link Sample}.
 * @param file
 *            the content of the {@link SequenceFile}.
 * @param fileResource
 *            the parameters for the file
 * @param response
 *            the servlet response.
 * @return a response indicating the success of the submission.
 * @throws IOException
 *             if we can't write the file to disk.
 */
@RequestMapping(value = "/api/samples/{sampleId}/sequenceFiles", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ModelMap addNewSequenceFileToSample(@PathVariable Long sampleId, @RequestPart("file") MultipartFile file, @RequestPart(value = "parameters", required = false) SequenceFileResource fileResource, HttpServletResponse response) throws IOException {
    ModelMap modelMap = new ModelMap();
    logger.debug("Adding sequence file to sample " + sampleId);
    logger.trace("Uploaded file size: " + file.getSize() + " bytes");
    // load the sample from the database
    Sample sample = sampleService.read(sampleId);
    logger.trace("Read sample " + sampleId);
    // prepare a new sequence file using the multipart file supplied by the
    // caller
    Path temp = Files.createTempDirectory(null);
    Path target = temp.resolve(file.getOriginalFilename());
    // Changed to MultipartFile.transerTo(File) because it was truncating
    // large files to 1039956336 bytes
    // target = Files.write(target, file.getBytes());
    file.transferTo(target.toFile());
    logger.trace("Wrote temp file to " + target);
    SequenceFile sf;
    SequencingRun miseqRun = null;
    if (fileResource != null) {
        sf = fileResource.getResource();
        Long miseqRunId = fileResource.getMiseqRunId();
        if (miseqRunId != null) {
            miseqRun = miseqRunService.read(miseqRunId);
            logger.trace("Read miseq run " + miseqRunId);
        }
    } else {
        sf = new SequenceFile();
    }
    sf.setFile(target);
    SingleEndSequenceFile singleEndSequenceFile = new SingleEndSequenceFile(sf);
    if (miseqRun != null) {
        singleEndSequenceFile.setSequencingRun(miseqRun);
        logger.trace("Added seqfile to miseqrun");
    }
    // save the seqobject and sample
    SampleSequencingObjectJoin createSequencingObjectInSample = sequencingObjectService.createSequencingObjectInSample(singleEndSequenceFile, sample);
    singleEndSequenceFile = (SingleEndSequenceFile) createSequencingObjectInSample.getObject();
    logger.trace("Created seqfile in sample " + createSequencingObjectInSample.getObject().getId());
    // clean up the temporary files.
    Files.deleteIfExists(target);
    Files.deleteIfExists(temp);
    logger.trace("Deleted temp file");
    // prepare a link to the sequence file itself (on the sequence file
    // controller)
    String objectType = objectLabels.get(SingleEndSequenceFile.class);
    Long sequenceFileId = singleEndSequenceFile.getSequenceFile().getId();
    Link selfRel = linkTo(methodOn(RESTSampleSequenceFilesController.class).readSequenceFileForSequencingObject(sampleId, objectType, singleEndSequenceFile.getId(), sequenceFileId)).withSelfRel();
    // Changed, because sfr.setResource(sf)
    // and sfr.setResource(sampleSequenceFileRelationship.getObject())
    // both will not pass a GET-POST comparison integration test.
    singleEndSequenceFile = (SingleEndSequenceFile) sequencingObjectService.read(singleEndSequenceFile.getId());
    SequenceFile sequenceFile = singleEndSequenceFile.getFileWithId(sequenceFileId);
    // add links to the resource
    sequenceFile.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).getSampleSequenceFiles(sampleId)).withRel(REL_SAMPLE_SEQUENCE_FILES));
    sequenceFile.add(selfRel);
    sequenceFile.add(linkTo(methodOn(RESTProjectSamplesController.class).getSample(sampleId)).withRel(REL_SAMPLE));
    sequenceFile.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).readSequencingObject(sampleId, objectType, singleEndSequenceFile.getId())).withRel(REL_SEQ_OBJECT));
    modelMap.addAttribute(RESTGenericController.RESOURCE_NAME, sequenceFile);
    // add a location header.
    response.addHeader(HttpHeaders.LOCATION, selfRel.getHref());
    // set the response status.
    response.setStatus(HttpStatus.CREATED.value());
    // respond to the client
    return modelMap;
}
Also used : Path(java.nio.file.Path) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SequencingRun(ca.corefacility.bioinformatics.irida.model.run.SequencingRun) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) Link(org.springframework.hateoas.Link) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 50 with SingleEndSequenceFile

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile in project irida by phac-nml.

the class ProjectEventHandlerTest method testHandleSequenceFileAddedEventMultipleProjects.

@SuppressWarnings("unchecked")
@Test
public void testHandleSequenceFileAddedEventMultipleProjects() {
    Class<? extends ProjectEvent> clazz = DataAddedToSampleProjectEvent.class;
    Project project = new Project("p1");
    Project project2 = new Project("p2");
    Sample sample = new Sample();
    SequenceFile file = new SequenceFile();
    SingleEndSequenceFile seqObj = new SingleEndSequenceFile(file);
    SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(sample, seqObj);
    when(psjRepository.getProjectForSample(sample)).thenReturn(Lists.newArrayList(new ProjectSampleJoin(project, sample, true), new ProjectSampleJoin(project2, sample, true)));
    when(eventRepository.save(any(ProjectEvent.class))).thenReturn(new DataAddedToSampleProjectEvent(project, sample));
    Object[] args = {};
    MethodEvent methodEvent = new MethodEvent(clazz, join, args);
    handler.delegate(methodEvent);
    ArgumentCaptor<ProjectEvent> captor = ArgumentCaptor.forClass(ProjectEvent.class);
    verify(eventRepository, times(2)).save(captor.capture());
    List<ProjectEvent> allValues = captor.getAllValues();
    Set<Project> projects = Sets.newHashSet(project, project2);
    for (ProjectEvent event : allValues) {
        assertTrue(event instanceof DataAddedToSampleProjectEvent);
        Project eventProject = event.getProject();
        assertTrue(projects.contains(eventProject));
        projects.remove(eventProject);
    }
    verify(projectRepository, times(2)).save(project);
}
Also used : Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) DataAddedToSampleProjectEvent(ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) UserRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent) DataAddedToSampleProjectEvent(ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) SampleAddedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent) Test(org.junit.Test)

Aggregations

SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)99 Test (org.junit.Test)72 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)61 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)44 Path (java.nio.file.Path)33 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)24 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)22 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)20 WithMockUser (org.springframework.security.test.context.support.WithMockUser)18 Project (ca.corefacility.bioinformatics.irida.model.project.Project)17 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)17 AnalysisFastQC (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)12 Analysis (ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis)11 IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)10 ArrayList (java.util.ArrayList)10 SequencingRun (ca.corefacility.bioinformatics.irida.model.run.SequencingRun)8 HistoriesClient (com.github.jmchilton.blend4j.galaxy.HistoriesClient)8 History (com.github.jmchilton.blend4j.galaxy.beans.History)8 GZIPOutputStream (java.util.zip.GZIPOutputStream)8 ModelMap (org.springframework.ui.ModelMap)8