Search in sources :

Example 41 with SingleEndSequenceFile

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

the class ReadSequencingObjectPermissionTest method testPermitAdmin.

@Test
public void testPermitAdmin() {
    Collection<GrantedAuthority> roles = new ArrayList<>();
    roles.add(Role.ROLE_ADMIN);
    Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1", roles);
    when(sequencingObjectRepository.findOne(1L)).thenReturn(new SingleEndSequenceFile(null));
    assertTrue("permission was not granted to admin.", permission.isAllowed(auth, 1L));
    // we should fast pass through to permission granted for administrators.
    verifyZeroInteractions(userRepository);
    verifyZeroInteractions(psjRepository);
    verifyZeroInteractions(userRepository);
    verifyZeroInteractions(ssoRepository);
}
Also used : Authentication(org.springframework.security.core.Authentication) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ArrayList(java.util.ArrayList) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Test(org.junit.Test)

Example 42 with SingleEndSequenceFile

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

the class DatabaseSetupGalaxyITService method setupSequencingObjectInDatabase.

/**
 * Attaches the given sequence file paths to a particular sample id.
 *
 * @param sampleId
 *            The id of the sample to attach a sequence file to.
 * @param sequenceFilePaths
 *            A path of the sequence file to attach.
 * @return A List of {@link SequencingObject}s the given sequence file path
 *         attached and saved in the database.
 */
public List<SingleEndSequenceFile> setupSequencingObjectInDatabase(Long sampleId, Path... sequenceFilePaths) {
    Sample sample = sampleService.read(sampleId);
    List<SingleEndSequenceFile> returnedSequenceFiles = new ArrayList<>();
    for (Path sequenceFilePath : sequenceFilePaths) {
        SingleEndSequenceFile singleEndSequenceFile = new SingleEndSequenceFile(new SequenceFile(sequenceFilePath));
        sequencingObjectService.createSequencingObjectInSample(singleEndSequenceFile, sample);
        waitForFilesToSettle(singleEndSequenceFile);
        returnedSequenceFiles.add((SingleEndSequenceFile) sequencingObjectService.read(singleEndSequenceFile.getId()));
    }
    return returnedSequenceFiles;
}
Also used : Path(java.nio.file.Path) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ArrayList(java.util.ArrayList) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)

Example 43 with SingleEndSequenceFile

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

the class SequencingRunSequenceFilesControllerTest method addSequenceFileToMiseqRunTest.

@Test
public void addSequenceFileToMiseqRunTest() throws IOException {
    Long seqId = 1L;
    Long sequencingrunId = 2L;
    MockHttpServletResponse response = new MockHttpServletResponse();
    SingleEndSequenceFile singleEndSequenceFile = TestDataFactory.constructSingleEndSequenceFile();
    MiseqRun run = new MiseqRun(LayoutType.SINGLE_END, "workflow");
    Map<String, String> representation = new HashMap<String, String>();
    representation.put(RESTSequencingRunSequenceFilesController.SEQUENCEFILE_ID_KEY, "" + seqId);
    when(objectService.read(seqId)).thenReturn(singleEndSequenceFile);
    when(miseqRunService.read(sequencingrunId)).thenReturn(run);
    ModelMap modelMap = controller.addSequenceFileToMiseqRun(sequencingrunId, representation, response);
    verify(objectService).read(seqId);
    verify(miseqRunService).read(sequencingrunId);
    Object o = modelMap.get(RESTGenericController.RESOURCE_NAME);
    assertNotNull("Object should not be null", o);
    assertTrue("Object should be an instance of MiseqRunResource", o instanceof MiseqRun);
    MiseqRun res = (MiseqRun) o;
    String seqFileLocation = linkTo(RESTSequencingRunController.class).slash(sequencingrunId).slash("sequenceFiles").slash(seqId).withSelfRel().getHref();
    assertEquals("Sequence file location should be correct", seqFileLocation, res.getLink(Link.REL_SELF).getHref());
    assertEquals("Sequence file location should be correct", seqFileLocation, response.getHeader(HttpHeaders.LOCATION));
    assertEquals("HTTP status must be CREATED", HttpStatus.CREATED.value(), response.getStatus());
}
Also used : MiseqRun(ca.corefacility.bioinformatics.irida.model.run.MiseqRun) RESTSequencingRunController(ca.corefacility.bioinformatics.irida.web.controller.api.sequencingrun.RESTSequencingRunController) HashMap(java.util.HashMap) ModelMap(org.springframework.ui.ModelMap) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Test(org.junit.Test)

Example 44 with SingleEndSequenceFile

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile 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 45 with SingleEndSequenceFile

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

the class AnalysisSubmissionServiceImpl method createSingleSampleSubmission.

/**
 * {@inheritDoc}
 */
@Override
@Transactional
@PreAuthorize("hasRole('ROLE_USER')")
public Collection<AnalysisSubmission> createSingleSampleSubmission(IridaWorkflow workflow, Long ref, List<SingleEndSequenceFile> sequenceFiles, List<SequenceFilePair> sequenceFilePairs, Map<String, String> params, IridaWorkflowNamedParameters namedParameters, String name, String analysisDescription, List<Project> projectsToShare, boolean writeResultsToSamples) {
    final Collection<AnalysisSubmission> createdSubmissions = new HashSet<AnalysisSubmission>();
    // Single end reads
    IridaWorkflowDescription description = workflow.getWorkflowDescription();
    if (description.acceptsSingleSequenceFiles()) {
        final Map<Sample, SingleEndSequenceFile> samplesMap = sequencingObjectService.getUniqueSamplesForSequencingObjects(Sets.newHashSet(sequenceFiles));
        for (final Map.Entry<Sample, SingleEndSequenceFile> entry : samplesMap.entrySet()) {
            Sample s = entry.getKey();
            SingleEndSequenceFile file = entry.getValue();
            // Build the analysis submission
            AnalysisSubmission.Builder builder = AnalysisSubmission.builder(workflow.getWorkflowIdentifier());
            builder.name(name + "_" + s.getSampleName());
            builder.inputFiles(ImmutableSet.of(file));
            builder.updateSamples(writeResultsToSamples);
            builder.priority(AnalysisSubmission.Priority.MEDIUM);
            // Add reference file
            if (ref != null && description.requiresReference()) {
                // Note: This cannot be empty if through the UI if the
                // pipeline required a reference file.
                ReferenceFile referenceFile = referenceFileRepository.findOne(ref);
                builder.referenceFile(referenceFile);
            }
            if (description.acceptsParameters()) {
                if (namedParameters != null) {
                    builder.withNamedParameters(namedParameters);
                } else {
                    if (!params.isEmpty()) {
                        // Note: This cannot be empty if through the UI if
                        // the pipeline required params.
                        builder.inputParameters(params);
                    }
                }
            }
            // Create the submission
            createdSubmissions.add(create(builder.build()));
        }
    }
    // Paired end reads
    if (description.acceptsPairedSequenceFiles()) {
        final Map<Sample, SequenceFilePair> samplesMap = sequencingObjectService.getUniqueSamplesForSequencingObjects(Sets.newHashSet(sequenceFilePairs));
        for (final Map.Entry<Sample, SequenceFilePair> entry : samplesMap.entrySet()) {
            Sample s = entry.getKey();
            SequenceFilePair filePair = entry.getValue();
            // Build the analysis submission
            AnalysisSubmission.Builder builder = AnalysisSubmission.builder(workflow.getWorkflowIdentifier());
            builder.name(name + "_" + s.getSampleName());
            builder.inputFiles(ImmutableSet.of(filePair));
            builder.updateSamples(writeResultsToSamples);
            // Add reference file
            if (ref != null && description.requiresReference()) {
                ReferenceFile referenceFile = referenceFileRepository.findOne(ref);
                builder.referenceFile(referenceFile);
            }
            if (description.acceptsParameters()) {
                if (namedParameters != null) {
                    builder.withNamedParameters(namedParameters);
                } else {
                    if (!params.isEmpty()) {
                        // Note: This cannot be empty if through the UI if
                        // the pipeline required params.
                        builder.inputParameters(params);
                    }
                }
            }
            // Add description to submission, can be null
            builder.analysisDescription(analysisDescription);
            // Create the submission
            createdSubmissions.add(create(builder.build()));
        }
    }
    // Share with the required projects
    for (AnalysisSubmission submission : createdSubmissions) {
        for (Project project : projectsToShare) {
            pasRepository.save(new ProjectAnalysisSubmissionJoin(project, submission));
        }
    }
    return createdSubmissions;
}
Also used : ReferenceFile(ca.corefacility.bioinformatics.irida.model.project.ReferenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) Project(ca.corefacility.bioinformatics.irida.model.project.Project) IridaWorkflowDescription(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription) ProjectAnalysisSubmissionJoin(ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin) ImmutableMap(com.google.common.collect.ImmutableMap) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(javax.transaction.Transactional)

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