use of ca.corefacility.bioinformatics.irida.model.run.SequencingRun 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;
}
use of ca.corefacility.bioinformatics.irida.model.run.SequencingRun in project irida by phac-nml.
the class RESTSequencingRunSequenceFilesController method addSequenceFileToMiseqRun.
/**
* Add a relationship between a {@link MiseqRun} and a {@link SequenceFile}.
*
* @param sequencingrunId
* the id of the run to add sequence file to.
* @param representation
* the JSON key-value pair that contains the identifier for the
* sequenceFile
* @param response
* a reference to the response.
* @return a response indicating that the collection was modified.
*/
@RequestMapping(value = "/api/sequencingrun/{sequencingrunId}/sequenceFiles", method = RequestMethod.POST)
public ModelMap addSequenceFileToMiseqRun(@PathVariable Long sequencingrunId, @RequestBody Map<String, String> representation, HttpServletResponse response) {
ModelMap modelMap = new ModelMap();
String stringId = representation.get(SEQUENCEFILE_ID_KEY);
long seqId = Long.parseLong(stringId);
// first, get the SequenceFile
SequencingObject sequencingObject = sequencingObjectService.read(seqId);
// then, get the miseq run
SequencingRun run = miseqRunService.read(sequencingrunId);
// then add the user to the project with the specified role.
miseqRunService.addSequencingObjectToSequencingRun(run, sequencingObject);
MiseqRun miseqRun;
if (run instanceof MiseqRun) {
miseqRun = (MiseqRun) run;
} else {
throw new IllegalArgumentException("The sequencing run ID must correspond to a a valid MiSeq sequence");
}
Link seqFileLocation = linkTo(RESTSequencingRunController.class).slash(sequencingrunId).slash("sequenceFiles").slash(seqId).withSelfRel();
miseqRun.add(seqFileLocation);
modelMap.addAttribute(RESTGenericController.RESOURCE_NAME, miseqRun);
response.addHeader(HttpHeaders.LOCATION, seqFileLocation.getHref());
response.setStatus(HttpStatus.CREATED.value());
return modelMap;
}
use of ca.corefacility.bioinformatics.irida.model.run.SequencingRun in project irida by phac-nml.
the class SequencingRunControllerTest method testGetFilesPage.
@SuppressWarnings("rawtypes")
@Test
public void testGetFilesPage() throws IOException {
Long runId = 1L;
ExtendedModelMap model = new ExtendedModelMap();
SequencingRun sequencingRunEntity = new MiseqRun(SequencingRun.LayoutType.PAIRED_END, "");
ImmutableSet<SequencingObject> files = ImmutableSet.of(new SingleEndSequenceFile(new SequenceFile()));
when(sequencingRunService.read(runId)).thenReturn(sequencingRunEntity);
when(objectService.getSequencingObjectsForSequencingRun(sequencingRunEntity)).thenReturn(files);
String filesPage = controller.getFilesPage(runId, model);
assertEquals(SequencingRunController.FILES_VIEW, filesPage);
assertFalse(((Collection) model.get("sequencingObjects")).isEmpty());
assertEquals(sequencingRunEntity, model.get("run"));
assertTrue(model.containsKey("fileCount"));
verify(sequencingRunService).read(runId);
verify(objectService).getSequencingObjectsForSequencingRun(sequencingRunEntity);
}
use of ca.corefacility.bioinformatics.irida.model.run.SequencingRun in project irida by phac-nml.
the class SequencingObjectServiceImplIT method testCreateSequenceFileInSample.
@Test
@WithMockUser(username = "fbristow", roles = "SEQUENCER")
public void testCreateSequenceFileInSample() throws IOException, InterruptedException {
Sample s = sampleService.read(1L);
SequenceFile sf = new SequenceFile();
Path sequenceFile = Files.createTempFile("TEMPORARY-SEQUENCE-FILE", ".gz");
OutputStream gzOut = new GZIPOutputStream(Files.newOutputStream(sequenceFile));
gzOut.write(FASTQ_FILE_CONTENTS);
gzOut.close();
sf.setFile(sequenceFile);
SingleEndSequenceFile so = new SingleEndSequenceFile(sf);
objectService.createSequencingObjectInSample(so, s);
SequencingRun mr = sequencingRunService.read(1L);
sequencingRunService.addSequencingObjectToSequencingRun(mr, so);
// Sleeping for a bit to let file processing run
Thread.sleep(10000);
Sample readSample = sampleService.read(s.getId());
List<QCEntry> qcEntries = sampleService.getQCEntriesForSample(readSample);
assertEquals("should be one qc entries", 1, qcEntries.size());
QCEntry qcEntry = qcEntries.iterator().next();
assertTrue("should be coverage entry", qcEntry instanceof CoverageQCEntry);
CoverageQCEntry coverage = (CoverageQCEntry) qcEntry;
assertEquals("should be 18 bases", 18, coverage.getTotalBases());
}
use of ca.corefacility.bioinformatics.irida.model.run.SequencingRun in project irida by phac-nml.
the class SequencingRunServiceImplIT method testCreateMiseqRunAsUser.
@Test
@WithMockUser(username = "user", password = "password1", roles = "USER")
public void testCreateMiseqRunAsUser() {
MiseqRun mr = new MiseqRun(LayoutType.PAIRED_END, "workflow");
SequencingRun create = miseqRunService.create(mr);
assertEquals("user", create.getUser().getUsername());
}
Aggregations