Search in sources :

Example 31 with SequencingObject

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

the class DefaultFileProcessingChain method launchChain.

/**
 * {@inheritDoc}
 */
@Override
public List<Exception> launchChain(Long sequencingObjectId) throws FileProcessorTimeoutException {
    List<Exception> ignoredExceptions = new ArrayList<>();
    Integer waiting = 0;
    // file has been persisted in the database.
    while (!sequencingObjectRepository.exists(sequencingObjectId)) {
        if (waiting > timeout) {
            throw new FileProcessorTimeoutException("Waiting for longer than " + sleepDuration * timeout + "ms, bailing out.");
        }
        waiting++;
        try {
            Thread.sleep(sleepDuration);
        } catch (InterruptedException e) {
        }
    }
    for (FileProcessor fileProcessor : fileProcessors) {
        try {
            if (fileProcessor.shouldProcessFile(sequencingObjectId)) {
                SequencingObject settledSequencingObject = getSettledSequencingObject(sequencingObjectId);
                fileProcessor.process(settledSequencingObject);
            }
        } catch (FileProcessorException e) {
            SequencingObject sequencingObject = sequencingObjectRepository.findOne(sequencingObjectId);
            qcRepository.save(new FileProcessorErrorQCEntry(sequencingObject));
            // execution (show the error, but proceed).
            if (fileProcessor.modifiesFile() || fastFail) {
                throw e;
            } else {
                ignoredExceptions.add(e);
                logger.error("File processor [" + fileProcessor.getClass() + "] failed to process [" + sequencingObjectId + "], but proceeding with the remaining processors because the " + "file would not be modified by the processor. Stack trace follows.", e);
            }
        }
    }
    return ignoredExceptions;
}
Also used : FileProcessorTimeoutException(ca.corefacility.bioinformatics.irida.exceptions.FileProcessorTimeoutException) FileProcessor(ca.corefacility.bioinformatics.irida.processing.FileProcessor) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) FileProcessorException(ca.corefacility.bioinformatics.irida.processing.FileProcessorException) FileProcessorErrorQCEntry(ca.corefacility.bioinformatics.irida.model.sample.FileProcessorErrorQCEntry) ArrayList(java.util.ArrayList) FileProcessorException(ca.corefacility.bioinformatics.irida.processing.FileProcessorException) FileProcessorTimeoutException(ca.corefacility.bioinformatics.irida.exceptions.FileProcessorTimeoutException)

Example 32 with SequencingObject

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

the class RESTSampleSequenceFilesController method addNewSequenceFilePairToSample.

/**
 * Add a pair of {@link SequenceFile}s to a {@link Sample}
 *
 * @param sampleId
 *            The {@link Sample} id to add to
 * @param file1
 *            The first multipart file
 * @param fileResource1
 *            The metadata for the first file
 * @param file2
 *            The second multipart file
 * @param fileResource2
 *            the metadata for the second file
 * @param response
 *            a reference to the servlet response.
 * @return Response containing the locations for the created files
 * @throws IOException
 *             if we can't write the files to disk
 */
@RequestMapping(value = "/api/samples/{sampleId}/pairs", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ModelMap addNewSequenceFilePairToSample(@PathVariable Long sampleId, @RequestPart("file1") MultipartFile file1, @RequestPart(value = "parameters1") SequenceFileResource fileResource1, @RequestPart("file2") MultipartFile file2, @RequestPart(value = "parameters2") SequenceFileResource fileResource2, HttpServletResponse response) throws IOException {
    logger.debug("Adding pair of sequence files to sample " + sampleId);
    logger.trace("First uploaded file size: " + file1.getSize() + " bytes");
    logger.trace("Second uploaded file size: " + file2.getSize() + " bytes");
    ModelMap modelMap = new ModelMap();
    // confirm that a relationship exists between the project and the sample
    Sample sample = sampleService.read(sampleId);
    logger.trace("Read sample " + sampleId);
    // create temp files
    Path temp1 = Files.createTempDirectory(null);
    Path target1 = temp1.resolve(file1.getOriginalFilename());
    Path temp2 = Files.createTempDirectory(null);
    Path target2 = temp2.resolve(file2.getOriginalFilename());
    // transfer the files to temp directories
    file1.transferTo(target1.toFile());
    file2.transferTo(target2.toFile());
    // create the model objects
    SequenceFile sf1 = fileResource1.getResource();
    SequenceFile sf2 = fileResource2.getResource();
    sf1.setFile(target1);
    sf2.setFile(target2);
    // get the sequencing run
    SequencingRun sequencingRun = null;
    if (!Objects.equal(fileResource1.getMiseqRunId(), fileResource2.getMiseqRunId())) {
        throw new IllegalArgumentException("Cannot upload a pair of files from different sequencing runs");
    }
    Long runId = fileResource1.getMiseqRunId();
    SequenceFilePair sequenceFilePair = new SequenceFilePair(sf1, sf2);
    if (runId != null) {
        sequencingRun = miseqRunService.read(runId);
        sequenceFilePair.setSequencingRun(sequencingRun);
        logger.trace("Added sequencing run to files" + runId);
    }
    // add the files and join
    SampleSequencingObjectJoin createSequencingObjectInSample = sequencingObjectService.createSequencingObjectInSample(sequenceFilePair, sample);
    // clean up the temporary files.
    Files.deleteIfExists(target1);
    Files.deleteIfExists(temp1);
    Files.deleteIfExists(target2);
    Files.deleteIfExists(temp2);
    logger.trace("Deleted temp files");
    SequencingObject sequencingObject = createSequencingObjectInSample.getObject();
    sequencingObject = addSequencingObjectLinks(sequencingObject, sampleId);
    sequencingObject.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).getSampleSequenceFiles(sampleId)).withRel(REL_SAMPLE_SEQUENCE_FILES));
    // add location header
    response.addHeader(HttpHeaders.LOCATION, sequencingObject.getLink("self").getHref());
    // set the response status.
    response.setStatus(HttpStatus.CREATED.value());
    modelMap.addAttribute(RESTGenericController.RESOURCE_NAME, sequencingObject);
    // respond to the client
    return modelMap;
}
Also used : Path(java.nio.file.Path) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) 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) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 33 with SequencingObject

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

the class RESTSampleSequenceFilesController method removeSequenceFileFromSample.

/**
 * Remove a {@link SequencingObject} from a {@link Sample}.
 *
 * @param sampleId   the source {@link Sample} identifier.
 * @param objectType The type of sequencing object being removed
 * @param objectId   the identifier of the {@link SequencingObject} to move.
 * @return a status indicating the success of the move.
 */
@RequestMapping(value = "/api/samples/{sampleId}/{objectType}/{objectId}", method = RequestMethod.DELETE)
public ModelMap removeSequenceFileFromSample(@PathVariable Long sampleId, @PathVariable String objectType, @PathVariable Long objectId) {
    ModelMap modelMap = new ModelMap();
    // load the project, sample and sequence file from the database
    Sample s = sampleService.read(sampleId);
    SequencingObject seqObject = sequencingObjectService.readSequencingObjectForSample(s, objectId);
    // ask the service to remove the sample from the sequence file
    sampleService.removeSequencingObjectFromSample(s, seqObject);
    // respond with a link to the sample, the new location of the sequence
    // file (as it is associated with the
    // project)
    RootResource resource = new RootResource();
    resource.add(linkTo(methodOn(RESTProjectSamplesController.class).getSample(sampleId)).withRel(REL_SAMPLE));
    resource.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).getSampleSequenceFiles(sampleId)).withRel(REL_SAMPLE_SEQUENCE_FILES));
    modelMap.addAttribute(RESTGenericController.RESOURCE_NAME, resource);
    return modelMap;
}
Also used : RootResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 34 with SequencingObject

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

the class RESTSampleSequenceFilesController method readQCForSequenceFile.

/**
 * Get the fastqc metrics for a {@link SequenceFile}
 *
 * @param sampleId
 *            {@link Sample} id of the file
 * @param objectType
 *            type of {@link SequencingObject}
 * @param objectId
 *            id of the {@link SequencingObject}
 * @param fileId
 *            id of the {@link SequenceFile}
 * @return an {@link AnalysisFastQC} for the file
 */
@RequestMapping(value = "/api/samples/{sampleId}/{objectType}/{objectId}/files/{fileId}/qc", method = RequestMethod.GET)
public ModelMap readQCForSequenceFile(@PathVariable Long sampleId, @PathVariable String objectType, @PathVariable Long objectId, @PathVariable Long fileId) {
    ModelMap modelMap = new ModelMap();
    Sample sample = sampleService.read(sampleId);
    SequencingObject readSequencingObjectForSample = sequencingObjectService.readSequencingObjectForSample(sample, objectId);
    AnalysisFastQC fastQCAnalysisForSequenceFile = analysisService.getFastQCAnalysisForSequenceFile(readSequencingObjectForSample, fileId);
    if (fastQCAnalysisForSequenceFile == null) {
        throw new EntityNotFoundException("No QC data for file");
    }
    fastQCAnalysisForSequenceFile.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).readSequenceFileForSequencingObject(sampleId, objectType, objectId, fileId)).withRel(REL_QC_SEQFILE));
    fastQCAnalysisForSequenceFile.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).readQCForSequenceFile(sampleId, objectType, objectId, fileId)).withSelfRel());
    modelMap.addAttribute(RESTGenericController.RESOURCE_NAME, fastQCAnalysisForSequenceFile);
    return modelMap;
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 35 with SequencingObject

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

the class RESTSampleSequenceFilesController method readSequencingObject.

/**
 * Read a single {@link SequencingObject} of the given type from a
 * {@link Sample}
 *
 * @param sampleId
 *            {@link Sample} identifier
 * @param objectType
 *            type of {@link SequencingObject}
 * @param objectId
 *            ID of the {@link SequencingObject}
 * @return A single {@link SequencingObject}
 */
@RequestMapping(value = "/api/samples/{sampleId}/{objectType}/{objectId}", method = RequestMethod.GET)
public ModelMap readSequencingObject(@PathVariable Long sampleId, @PathVariable String objectType, @PathVariable Long objectId) {
    ModelMap modelMap = new ModelMap();
    Sample sample = sampleService.read(sampleId);
    SequencingObject sequencingObject = sequencingObjectService.readSequencingObjectForSample(sample, objectId);
    sequencingObject = addSequencingObjectLinks(sequencingObject, sampleId);
    modelMap.addAttribute(RESTGenericController.RESOURCE_NAME, sequencingObject);
    return modelMap;
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)61 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)29 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)25 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)24 Test (org.junit.Test)24 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)16 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)14 WithMockUser (org.springframework.security.test.context.support.WithMockUser)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 Project (ca.corefacility.bioinformatics.irida.model.project.Project)11 AnalysisFastQC (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)11 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)10 SequencingRun (ca.corefacility.bioinformatics.irida.model.run.SequencingRun)8 Path (java.nio.file.Path)8 ModelMap (org.springframework.ui.ModelMap)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 Transactional (org.springframework.transaction.annotation.Transactional)6 IOException (java.io.IOException)5 List (java.util.List)5 Logger (org.slf4j.Logger)5