Search in sources :

Example 6 with SequencingRun

use of ca.corefacility.bioinformatics.irida.model.run.SequencingRun in project irida by phac-nml.

the class SequencingRunServiceImplIT method testCreateMiseqRunAsSequencer.

@Test
@WithMockUser(username = "sequencer", password = "password1", roles = "SEQUENCER")
public void testCreateMiseqRunAsSequencer() {
    MiseqRun mr = new MiseqRun(LayoutType.PAIRED_END, "workflow");
    SequencingRun returned = miseqRunService.create(mr);
    assertNotNull("Created run was not assigned an ID.", returned.getId());
}
Also used : MiseqRun(ca.corefacility.bioinformatics.irida.model.run.MiseqRun) SequencingRun(ca.corefacility.bioinformatics.irida.model.run.SequencingRun) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 7 with SequencingRun

use of ca.corefacility.bioinformatics.irida.model.run.SequencingRun in project irida by phac-nml.

the class SequencingRunServiceImplIT method testReadMiseqRunAsTech.

@Test
@WithMockUser(username = "tech", password = "password1", roles = "TECHNICIAN")
public void testReadMiseqRunAsTech() {
    SequencingRun mr = miseqRunService.read(1L);
    assertNotNull("Created run was not assigned an ID.", mr.getId());
}
Also used : SequencingRun(ca.corefacility.bioinformatics.irida.model.run.SequencingRun) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 8 with SequencingRun

use of ca.corefacility.bioinformatics.irida.model.run.SequencingRun in project irida by phac-nml.

the class SequencingRunControllerTest method testGetDetailsPage.

@Test
public void testGetDetailsPage() throws IOException {
    Long runId = 1L;
    SequencingRun sequencingRunEntity = new MiseqRun(SequencingRun.LayoutType.PAIRED_END, "");
    ExtendedModelMap model = new ExtendedModelMap();
    when(sequencingRunService.read(runId)).thenReturn(sequencingRunEntity);
    String detailsPage = controller.getDetailsPage(runId, model);
    verify(sequencingRunService).read(runId);
    assertEquals(SequencingRunController.DETAILS_VIEW, detailsPage);
    assertEquals(sequencingRunEntity, model.get("run"));
}
Also used : MiseqRun(ca.corefacility.bioinformatics.irida.model.run.MiseqRun) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) SequencingRun(ca.corefacility.bioinformatics.irida.model.run.SequencingRun) Test(org.junit.Test)

Example 9 with SequencingRun

use of ca.corefacility.bioinformatics.irida.model.run.SequencingRun in project irida by phac-nml.

the class SequencingObjectServiceImpl method create.

/**
 * {@inheritDoc}
 */
@Override
@Transactional
@PreAuthorize("hasAnyRole('ROLE_SEQUENCER', 'ROLE_USER')")
public SequencingObject create(SequencingObject object) throws ConstraintViolationException, EntityExistsException {
    SequencingRun sequencingRun = object.getSequencingRun();
    if (sequencingRun != null) {
        if (object instanceof SingleEndSequenceFile && sequencingRun.getLayoutType() != LayoutType.SINGLE_END) {
            throw new IllegalArgumentException("Attempting to add a single end file to a non single end run");
        } else if (object instanceof SequenceFilePair && sequencingRun.getLayoutType() != LayoutType.PAIRED_END) {
            throw new IllegalArgumentException("Attempting to add a paired end file to a non paired end run");
        }
    }
    for (SequenceFile file : object.getFiles()) {
        file = sequenceFileRepository.save(file);
    }
    SequencingObject so = super.create(object);
    fileProcessingChainExecutor.execute(new SequenceFileProcessorLauncher(fileProcessingChain, so.getId(), SecurityContextHolder.getContext()));
    return so;
}
Also used : SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequencingRun(ca.corefacility.bioinformatics.irida.model.run.SequencingRun) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SequenceFileProcessorLauncher(ca.corefacility.bioinformatics.irida.service.impl.processor.SequenceFileProcessorLauncher) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with SequencingRun

use of ca.corefacility.bioinformatics.irida.model.run.SequencingRun 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)

Aggregations

SequencingRun (ca.corefacility.bioinformatics.irida.model.run.SequencingRun)25 Test (org.junit.Test)17 WithMockUser (org.springframework.security.test.context.support.WithMockUser)13 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)9 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)8 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)8 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)8 MiseqRun (ca.corefacility.bioinformatics.irida.model.run.MiseqRun)7 Path (java.nio.file.Path)6 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)3 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)3 ModelMap (org.springframework.ui.ModelMap)3 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)2 CoverageQCEntry (ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry)2 FileProcessorErrorQCEntry (ca.corefacility.bioinformatics.irida.model.sample.FileProcessorErrorQCEntry)2 QCEntry (ca.corefacility.bioinformatics.irida.model.sample.QCEntry)2 User (ca.corefacility.bioinformatics.irida.model.user.User)2 AnalysisFastQC (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)2