use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.
the class ProjectEventHandler method handleSampleRemovedEvent.
/**
* Create {@link SampleRemovedProjectEvent}s for any {@link Sample}s removed
* from a {@link Project}
*
* @param event
* the {@link MethodEvent} containing params from the method call
* @return a collectino of {@link SampleRemovedProjectEvent}s
*/
private Collection<SampleRemovedProjectEvent> handleSampleRemovedEvent(MethodEvent event) {
Collection<SampleRemovedProjectEvent> events = new ArrayList<>();
Optional<Object> projectOpt = Arrays.stream(event.getArgs()).filter(e -> e instanceof Project).findAny();
Optional<Object> sampleOpt = Arrays.stream(event.getArgs()).filter(e -> e instanceof Sample).findAny();
Optional<Object> sampleListOpt = Arrays.stream(event.getArgs()).filter(e -> e instanceof Iterable).findAny();
if (projectOpt.isPresent()) {
Project project = (Project) projectOpt.get();
if (sampleOpt.isPresent()) {
Sample sample = (Sample) sampleOpt.get();
events.add(eventRepository.save(new SampleRemovedProjectEvent(project, sample.getSampleName())));
} else if (sampleListOpt.isPresent()) {
@SuppressWarnings("unchecked") Iterable<Sample> samples = (Iterable<Sample>) sampleListOpt.get();
for (Sample sample : samples) {
events.add(eventRepository.save(new SampleRemovedProjectEvent(project, sample.getSampleName())));
}
}
}
return events;
}
use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.
the class ProjectEventHandler method handleIndividualSequenceFileAddedEvent.
/**
* Create {@link DataAddedToSampleProjectEvent} for all {@link Project}s a
* {@link Sample} belongs to
*
* @param join
* a {@link SampleSequencingObjectJoin} to turn into a
* {@link DataAddedToSampleProjectEvent}
*/
private Collection<DataAddedToSampleProjectEvent> handleIndividualSequenceFileAddedEvent(SampleSequencingObjectJoin join) {
Sample subject = join.getSubject();
Collection<DataAddedToSampleProjectEvent> events = new ArrayList<>();
List<Join<Project, Sample>> projectForSample = psjRepository.getProjectForSample(subject);
for (Join<Project, Sample> psj : projectForSample) {
events.add(eventRepository.save(new DataAddedToSampleProjectEvent(psj.getSubject(), subject)));
}
return events;
}
use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.
the class AssemblySampleUpdaterIT method testUpdateSuccess.
@Test
@WithMockUser(username = "fbristow", roles = "USER")
public void testUpdateSuccess() {
AnalysisSubmission a = analysisSubmissionRepository.findOne(1L);
Sample s = sampleRepository.findOne(2L);
assertEquals("Should be no join between sample and assembly", 0, sampleGenomeAssemblyJoinRepository.count());
assemblySampleUpdater.update(Sets.newHashSet(s), a);
assertEquals("Should exist a join between sample and assembly", 1, sampleGenomeAssemblyJoinRepository.count());
SampleGenomeAssemblyJoin j = sampleGenomeAssemblyJoinRepository.findAll().iterator().next();
assertEquals("Should have joined sample 2L", (Long) 2L, j.getSubject().getId());
assertNotNull("Should have joined an assembly", j.getObject().getId());
}
use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.
the class SISTRSampleUpdaterTest method testUpdaterPassed.
@SuppressWarnings("unchecked")
@Test
public void testUpdaterPassed() throws PostProcessingException, AnalysisAlreadySetException {
ImmutableMap<String, String> expectedResults = ImmutableMap.of("SISTR serovar", "Enteritidis", "SISTR cgMLST Subspecies", "enterica", "SISTR QC Status", "PASS");
Path outputPath = Paths.get("src/test/resources/files/sistr-predictions-pass.json");
AnalysisOutputFile outputFile = new AnalysisOutputFile(outputPath, null, null, null);
Analysis analysis = new Analysis(null, ImmutableMap.of("sistr-predictions", outputFile), null, null);
AnalysisSubmission submission = AnalysisSubmission.builder(UUID.randomUUID()).inputFiles(ImmutableSet.of(new SingleEndSequenceFile(null))).build();
submission.setAnalysis(analysis);
Sample sample = new Sample();
sample.setId(1L);
ImmutableMap<MetadataTemplateField, MetadataEntry> metadataMap = ImmutableMap.of(new MetadataTemplateField("SISTR Field", "text"), new MetadataEntry("Value1", "text"));
when(metadataTemplateService.getMetadataMap(any(Map.class))).thenReturn(metadataMap);
updater.update(Lists.newArrayList(sample), submission);
ArgumentCaptor<Map> mapCaptor = ArgumentCaptor.forClass(Map.class);
// this is the important bit. Ensures the correct values got pulled from the file
verify(metadataTemplateService).getMetadataMap(mapCaptor.capture());
Map<String, MetadataEntry> metadata = mapCaptor.getValue();
int found = 0;
for (Map.Entry<String, MetadataEntry> e : metadata.entrySet()) {
if (expectedResults.containsKey(e.getKey())) {
String expected = expectedResults.get(e.getKey());
MetadataEntry value = e.getValue();
assertEquals("metadata values should match", expected, value.getValue());
found++;
}
}
assertEquals("should have found the same number of results", expectedResults.keySet().size(), found);
// this bit just ensures the merged data got saved
verify(sampleService).updateFields(eq(sample.getId()), mapCaptor.capture());
Map<MetadataTemplateField, MetadataEntry> value = (Map<MetadataTemplateField, MetadataEntry>) mapCaptor.getValue().get("metadata");
assertEquals(metadataMap.keySet().iterator().next(), value.keySet().iterator().next());
}
use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.
the class SISTRSampleUpdaterTest method testUpdaterBadFile.
@Test(expected = PostProcessingException.class)
public void testUpdaterBadFile() throws PostProcessingException, AnalysisAlreadySetException {
ImmutableMap<String, String> expectedResults = ImmutableMap.of("SISTR serovar", "Enteritidis", "SISTR cgMLST Subspecies", "enterica", "SISTR QC Status", "PASS");
Path outputPath = Paths.get("src/test/resources/files/snp_tree.tree");
AnalysisOutputFile outputFile = new AnalysisOutputFile(outputPath, null, null, null);
Analysis analysis = new Analysis(null, ImmutableMap.of("sistr-predictions", outputFile), null, null);
AnalysisSubmission submission = AnalysisSubmission.builder(UUID.randomUUID()).inputFiles(ImmutableSet.of(new SingleEndSequenceFile(null))).build();
submission.setAnalysis(analysis);
Sample sample = new Sample();
sample.setId(1L);
updater.update(Lists.newArrayList(sample), submission);
}
Aggregations