use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class CoverageFileProcessorTest method testRemoveExistingEntry.
@Test
public void testRemoveExistingEntry() {
Project p = new Project();
p.setGenomeSize(100L);
p.setMinimumCoverage(2);
SequenceFile file = new SequenceFile();
SequencingObject o = new SingleEndSequenceFile(file);
AnalysisFastQC fqc = mock(AnalysisFastQC.class);
Long baseCount = 300L;
QCEntry existingQc = new CoverageQCEntry();
o.setQcEntries(Sets.newHashSet(existingQc));
when(analysisRepository.findFastqcAnalysisForSequenceFile(file)).thenReturn(fqc);
when(fqc.getTotalBases()).thenReturn(baseCount);
processor.process(o);
ArgumentCaptor<CoverageQCEntry> qcCaptor = ArgumentCaptor.forClass(CoverageQCEntry.class);
verify(qcEntryRepository).delete(existingQc);
verify(qcEntryRepository).save(qcCaptor.capture());
CoverageQCEntry qc = qcCaptor.getValue();
qc.addProjectSettings(p);
assertEquals("should show 3 times coverage", 3, qc.getCoverage());
assertEquals("should be positive coverage", QCEntryStatus.POSITIVE, qc.getStatus());
}
use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class CoverageFileProcessorTest method testGoodCoverage.
@Test
public void testGoodCoverage() {
Project p = new Project();
p.setGenomeSize(100L);
p.setMinimumCoverage(2);
SequenceFile file = new SequenceFile();
SequencingObject o = new SingleEndSequenceFile(file);
AnalysisFastQC fqc = mock(AnalysisFastQC.class);
Long baseCount = 300L;
when(analysisRepository.findFastqcAnalysisForSequenceFile(file)).thenReturn(fqc);
when(fqc.getTotalBases()).thenReturn(baseCount);
processor.process(o);
ArgumentCaptor<CoverageQCEntry> qcCaptor = ArgumentCaptor.forClass(CoverageQCEntry.class);
verify(qcEntryRepository, times(0)).delete(any(QCEntry.class));
verify(qcEntryRepository).save(qcCaptor.capture());
CoverageQCEntry qc = qcCaptor.getValue();
qc.addProjectSettings(p);
assertEquals("should show 3 times coverage", 3, qc.getCoverage());
assertEquals("should be positive coverage", QCEntryStatus.POSITIVE, qc.getStatus());
}
use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class RESTUsersController method getUserProjects.
/**
* Get the collection of projects for a specific user.
*
* @param username
* the username for the desired user.
* @return a model containing the collection of projects for that user.
*/
@RequestMapping(value = "/api/{username}/projects", method = RequestMethod.GET)
public ModelMap getUserProjects(@PathVariable String username) {
logger.debug("Loading projects for user [" + username + "]");
ModelMap mav = new ModelMap();
// get the appropriate user from the database
User u = userService.getUserByUsername(username);
// get all of the projects that this user belongs to
ResourceCollection<Project> resources = new ResourceCollection<>();
List<Join<Project, User>> projects = projectService.getProjectsForUser(u);
ControllerLinkBuilder linkBuilder = linkTo(RESTProjectsController.class);
// add the project and a self-rel link to the project representation
for (Join<Project, User> join : projects) {
Project project = join.getSubject();
project.add(linkBuilder.slash(project.getId()).withSelfRel());
resources.add(project);
}
// add the resources to the response
mav.addAttribute("projectResources", resources);
// respond to the user
return mav;
}
use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class RESTProjectSamplesController method copySampleToProject.
/**
* Copy an existing sample to a project.
*
* @param projectId
* the project to copy the sample to.
* @param sampleIds
* the collection of sample IDs to copy.
* @param response
* a reference to the servlet response.
* @return the response indicating that the sample was joined to the
* project.
*/
@RequestMapping(value = "/api/projects/{projectId}/samples", method = RequestMethod.POST, consumes = "application/idcollection+json")
public ModelMap copySampleToProject(@PathVariable final Long projectId, @RequestBody final List<Long> sampleIds, HttpServletResponse response) {
ModelMap modelMap = new ModelMap();
Project p = projectService.read(projectId);
ResourceCollection<LabelledRelationshipResource<Project, Sample>> labeledProjectSampleResources = new ResourceCollection<>(sampleIds.size());
for (final long sampleId : sampleIds) {
Sample sample = sampleService.read(sampleId);
Join<Project, Sample> r = projectService.addSampleToProject(p, sample, false);
LabelledRelationshipResource<Project, Sample> resource = new LabelledRelationshipResource<Project, Sample>(r.getLabel(), r);
// add a labeled relationship resource to the resource collection
// that will fill the body of the response.
resource.add(linkTo(methodOn(RESTProjectSamplesController.class).getSample(sample.getId())).withSelfRel());
resource.add(linkTo(methodOn(RESTProjectSamplesController.class).getProjectSample(projectId, sample.getId())).withRel(REL_PROJECT_SAMPLE));
resource.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).getSampleSequenceFiles(sample.getId())).withRel(RESTSampleSequenceFilesController.REL_SAMPLE_SEQUENCE_FILES));
resource.add(linkTo(RESTProjectsController.class).slash(projectId).withRel(REL_PROJECT));
labeledProjectSampleResources.add(resource);
final String location = linkTo(methodOn(RESTProjectSamplesController.class).getProjectSample(projectId, sampleId)).withSelfRel().getHref();
response.addHeader(HttpHeaders.LOCATION, location);
}
// add a link to the project that was copied to.
labeledProjectSampleResources.add(linkTo(methodOn(RESTProjectSamplesController.class).getProjectSamples(projectId)).withSelfRel());
modelMap.addAttribute(RESTGenericController.RESOURCE_NAME, labeledProjectSampleResources);
response.setStatus(HttpStatus.CREATED.value());
return modelMap;
}
use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class RESTProjectSamplesController method getProjectSampleBySequencerId.
/**
* Get samples by a given string name
*
* @param projectId the Project to get samples from
* @param seqeuncerId the string id of the sample
* @return The found sample
*/
@RequestMapping(value = "/api/projects/{projectId}/samples/bySequencerId/{seqeuncerId}", method = RequestMethod.GET)
public ModelAndView getProjectSampleBySequencerId(@PathVariable Long projectId, @PathVariable String seqeuncerId) {
Project p = projectService.read(projectId);
Sample sampleBySampleId = sampleService.getSampleBySampleName(p, seqeuncerId);
Link withSelfRel = linkTo(methodOn(RESTProjectSamplesController.class).getSample(sampleBySampleId.getId())).withSelfRel();
String href = withSelfRel.getHref();
RedirectView redirectView = new RedirectView(href);
return new ModelAndView(redirectView);
}
Aggregations