Search in sources :

Example 56 with SequenceFile

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

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

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

the class SampleServiceImpl method getTotalBasesForSample.

/**
 * {@inheritDoc}
 */
@Override
@Transactional(readOnly = true)
@PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(#sample, 'canReadSample')")
public Long getTotalBasesForSample(Sample sample) throws SequenceFileAnalysisException {
    checkNotNull(sample, "sample is null");
    long totalBases = 0;
    List<SampleSequencingObjectJoin> sequencesForSample = ssoRepository.getSequencesForSample(sample);
    for (SampleSequencingObjectJoin join : sequencesForSample) {
        for (SequenceFile sequenceFile : join.getObject().getFiles()) {
            final AnalysisFastQC sequenceFileFastQC = analysisRepository.findFastqcAnalysisForSequenceFile(sequenceFile);
            if (sequenceFileFastQC == null || sequenceFileFastQC.getTotalBases() == null) {
                throw new SequenceFileAnalysisException("Missing FastQC analysis for SequenceFile [" + sequenceFile.getId() + "]");
            }
            totalBases += sequenceFileFastQC.getTotalBases();
        }
    }
    return totalBases;
}
Also used : SequenceFileAnalysisException(ca.corefacility.bioinformatics.irida.exceptions.SequenceFileAnalysisException) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 59 with SequenceFile

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

the class SequencingObjectRemoteServiceImpl method mirrorSequencingObject.

@Override
public Type mirrorSequencingObject(Type seqObject) {
    Set<SequenceFile> files = seqObject.getFiles();
    for (SequenceFile file : files) {
        String fileHref = file.getSelfHref();
        RemoteAPI api = getRemoteApiForURI(fileHref);
        Path downloadRemoteSequenceFile = sequenceFileRemoteRepository.downloadRemoteSequenceFile(fileHref, api);
        file.setFile(downloadRemoteSequenceFile);
    }
    return seqObject;
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) Path(java.nio.file.Path) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)

Example 60 with SequenceFile

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

the class DefaultFileProcessingChain method getSettledSequencingObject.

/**
 * Checks the {@link SequenceFile}s for the given {@link SequencingObject}
 * to see if it's files are in the place they should be. Since there's lots
 * of saves going on during the {@link FileProcessingChain} the transaction
 * might not be complete in the time the file is first read.
 *
 * @param sequencingObjectId
 *            the id of the {@link SequencingObject} to check
 * @return the settled {@link SequencingObject}
 * @throws FileProcessorTimeoutException
 *             if the files don't settle in the configured timeout
 */
private SequencingObject getSettledSequencingObject(Long sequencingObjectId) throws FileProcessorTimeoutException {
    boolean filesNotSettled = true;
    Integer waiting = 0;
    SequencingObject sequencingObject;
    do {
        if (waiting > timeout) {
            throw new FileProcessorTimeoutException("Waiting for longer than " + sleepDuration * timeout + "ms, bailing out.  File id " + sequencingObjectId);
        }
        waiting++;
        try {
            Thread.sleep(sleepDuration);
        } catch (InterruptedException e) {
        }
        sequencingObject = sequencingObjectRepository.findOne(sequencingObjectId);
        Set<SequenceFile> files = sequencingObject.getFiles();
        filesNotSettled = files.stream().anyMatch(f -> {
            return !Files.exists(f.getFile());
        });
    } while (filesNotSettled);
    return sequencingObject;
}
Also used : Arrays(java.util.Arrays) Logger(org.slf4j.Logger) Files(java.nio.file.Files) FileProcessorException(ca.corefacility.bioinformatics.irida.processing.FileProcessorException) SequencingObjectRepository(ca.corefacility.bioinformatics.irida.repositories.sequencefile.SequencingObjectRepository) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) QCEntryRepository(ca.corefacility.bioinformatics.irida.repositories.sample.QCEntryRepository) ArrayList(java.util.ArrayList) FileProcessor(ca.corefacility.bioinformatics.irida.processing.FileProcessor) FileProcessorErrorQCEntry(ca.corefacility.bioinformatics.irida.model.sample.FileProcessorErrorQCEntry) List(java.util.List) FileProcessorTimeoutException(ca.corefacility.bioinformatics.irida.exceptions.FileProcessorTimeoutException) FileProcessingChain(ca.corefacility.bioinformatics.irida.processing.FileProcessingChain) FileProcessorTimeoutException(ca.corefacility.bioinformatics.irida.exceptions.FileProcessorTimeoutException) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)

Aggregations

SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)111 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)84 Test (org.junit.Test)61 Path (java.nio.file.Path)50 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)39 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)31 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)25 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)20 Project (ca.corefacility.bioinformatics.irida.model.project.Project)15 AnalysisFastQC (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)15 WithMockUser (org.springframework.security.test.context.support.WithMockUser)13 IOException (java.io.IOException)11 SequencingRun (ca.corefacility.bioinformatics.irida.model.run.SequencingRun)9 ArrayList (java.util.ArrayList)9 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)8 GZIPOutputStream (java.util.zip.GZIPOutputStream)8 Link (org.springframework.hateoas.Link)8 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)7 OutputStream (java.io.OutputStream)7 Before (org.junit.Before)7