Search in sources :

Example 1 with Builder

use of ca.corefacility.bioinformatics.irida.model.export.NcbiBioSampleFiles.Builder in project irida by phac-nml.

the class ProjectExportController method submitToNcbi.

/**
 * Save an NCBI submission to the database
 *
 * @param projectId
 *            the ID of the {@link Project} for the submission
 * @param submission
 *            A {@link SubmissionBody} describing the files to upload
 * @param principal
 *            the user submitting the upload
 * @return ID of the submission if successful
 * @throws InterruptedException
 *             if thread was not successfully put to sleep
 */
@RequestMapping(value = "/projects/{projectId}/export/ncbi", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> submitToNcbi(@PathVariable Long projectId, @RequestBody SubmissionBody submission, Principal principal) throws InterruptedException {
    Project project = projectService.read(projectId);
    User submitter = userService.getUserByUsername(principal.getName());
    List<NcbiBioSampleFiles> bioSampleFiles = new ArrayList<>();
    for (BioSampleBody sample : submission.getSamples()) {
        List<SingleEndSequenceFile> singleFiles = new ArrayList<>();
        sequencingObjectService.readMultiple(sample.getSingle()).forEach(f -> singleFiles.add((SingleEndSequenceFile) f));
        List<SequenceFilePair> paired = new ArrayList<>();
        sequencingObjectService.readMultiple(sample.getPaired()).forEach(f -> paired.add((SequenceFilePair) f));
        Builder sampleBuilder = new NcbiBioSampleFiles.Builder();
        sampleBuilder.bioSample(sample.getBioSample()).files(singleFiles).pairs(paired).instrumentModel(sample.getInstrumentModel()).libraryConstructionProtocol(sample.getLibraryConstructionProtocol()).libraryName(sample.getLibraryName()).librarySelection(sample.getLibrarySelection()).librarySource(sample.getLibrarySource()).libraryStrategy(sample.getLibraryStrategy()).namespace(submission.getNamespace());
        NcbiBioSampleFiles build = sampleBuilder.build();
        bioSampleFiles.add(build);
    }
    NcbiExportSubmission ncbiExportSubmission = new NcbiExportSubmission(project, submitter, submission.getBioProject(), submission.getOrganization(), submission.getNamespace(), submission.getReleaseDate(), bioSampleFiles);
    ncbiExportSubmission = exportSubmissionService.create(ncbiExportSubmission);
    return ImmutableMap.of("submissionId", ncbiExportSubmission.getId());
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) User(ca.corefacility.bioinformatics.irida.model.user.User) NcbiExportSubmission(ca.corefacility.bioinformatics.irida.model.NcbiExportSubmission) Builder(ca.corefacility.bioinformatics.irida.model.export.NcbiBioSampleFiles.Builder) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)

Aggregations

NcbiExportSubmission (ca.corefacility.bioinformatics.irida.model.NcbiExportSubmission)1 Builder (ca.corefacility.bioinformatics.irida.model.export.NcbiBioSampleFiles.Builder)1 Project (ca.corefacility.bioinformatics.irida.model.project.Project)1 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)1 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)1 User (ca.corefacility.bioinformatics.irida.model.user.User)1