use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile in project irida by phac-nml.
the class AnalysisWorkspaceServiceGalaxyIT method testGetAnalysisResultsTestAnalysisPairedSuccess.
/**
* Tests out successfully getting results for an analysis (TestAnalysis)
* consisting only of paired sequence reads.
*
* @throws InterruptedException
* @throws ExecutionManagerException
* @throws IridaWorkflowNotFoundException
* @throws IOException
* @throws IridaWorkflowAnalysisTypeException
* @throws TimeoutException
*/
@Test
@WithMockUser(username = "aaron", roles = "ADMIN")
public void testGetAnalysisResultsTestAnalysisPairedSuccess() throws InterruptedException, ExecutionManagerException, IridaWorkflowNotFoundException, IOException, IridaWorkflowAnalysisTypeException, TimeoutException {
History history = new History();
history.setName("testGetAnalysisResultsTestAnalysisPairedSuccess");
HistoriesClient historiesClient = localGalaxy.getGalaxyInstanceAdmin().getHistoriesClient();
WorkflowsClient workflowsClient = localGalaxy.getGalaxyInstanceAdmin().getWorkflowsClient();
ToolsClient toolsClient = localGalaxy.getGalaxyInstanceAdmin().getToolsClient();
History createdHistory = historiesClient.create(history);
// upload test outputs
uploadFileToHistory(sequenceFilePathA, OUTPUT1_NAME, createdHistory.getId(), toolsClient);
uploadFileToHistory(sequenceFilePathA, OUTPUT2_NAME, createdHistory.getId(), toolsClient);
// wait for history
Util.waitUntilHistoryComplete(createdHistory.getId(), galaxyHistoriesService, 60);
IridaWorkflow iridaWorkflow = iridaWorkflowsService.getIridaWorkflow(validWorkflowIdPaired);
Path workflowPath = iridaWorkflow.getWorkflowStructure().getWorkflowFile();
String workflowString = new String(Files.readAllBytes(workflowPath), StandardCharsets.UTF_8);
Workflow galaxyWorkflow = workflowsClient.importWorkflow(workflowString);
List<Path> paths1 = new ArrayList<>();
paths1.add(sequenceFilePathA);
List<Path> paths2 = new ArrayList<>();
paths2.add(sequenceFilePath2A);
AnalysisSubmission analysisSubmission = analysisExecutionGalaxyITService.setupPairSubmissionInDatabase(1L, paths1, paths2, referenceFilePath, validWorkflowIdPaired, false);
Set<SingleEndSequenceFile> submittedSingleFiles = sequencingObjectService.getSequencingObjectsOfTypeForAnalysisSubmission(analysisSubmission, SingleEndSequenceFile.class);
Set<SequenceFilePair> pairedFiles = sequencingObjectService.getSequencingObjectsOfTypeForAnalysisSubmission(analysisSubmission, SequenceFilePair.class);
assertEquals("the created submission should have no single input files", 0, submittedSingleFiles.size());
assertEquals("the created submission has an invalid number of paired input files", 1, pairedFiles.size());
SequenceFilePair submittedSp = pairedFiles.iterator().next();
Set<SequenceFile> submittedSf = submittedSp.getFiles();
assertEquals("the paired input should have 2 files", 2, submittedSf.size());
analysisSubmission.setRemoteAnalysisId(createdHistory.getId());
analysisSubmission.setRemoteWorkflowId(galaxyWorkflow.getId());
analysisSubmission.setAnalysisState(AnalysisState.COMPLETING);
analysisSubmissionRepository.save(analysisSubmission);
Analysis analysis = analysisWorkspaceService.getAnalysisResults(analysisSubmission);
assertNotNull("the analysis results were not properly created", analysis);
assertEquals("the Analysis results class is invalid", Analysis.class, analysis.getClass());
assertEquals("the analysis results has an invalid number of output files", 2, analysis.getAnalysisOutputFiles().size());
assertEquals("the analysis results output file has an invalid name", Paths.get(OUTPUT1_NAME), analysis.getAnalysisOutputFile(OUTPUT1_KEY).getFile().getFileName());
assertEquals("the analysis results output file has an invalid label", OUTPUT1_NAME, analysis.getAnalysisOutputFile(OUTPUT1_KEY).getLabel());
assertEquals("the analysis results output file has an invalid name", Paths.get(OUTPUT2_NAME), analysis.getAnalysisOutputFile(OUTPUT2_KEY).getFile().getFileName());
assertEquals("the analysis results output file has an invalid label", OUTPUT2_NAME, analysis.getAnalysisOutputFile(OUTPUT2_KEY).getLabel());
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile in project irida by phac-nml.
the class AnalysisWorkspaceServiceGalaxyTest method setup.
/**
* Sets up variables for testing.
*
* @throws IOException
* @throws GalaxyDatasetException
* @throws UploadException
*/
@Before
public void setup() throws IOException, UploadException, GalaxyDatasetException {
MockitoAnnotations.initMocks(this);
sFileA = new SequenceFile(createTempFile("fileA", "fastq"));
sFileB = new SequenceFile(createTempFile("fileB", "fastq"));
sFileC = new SequenceFile(createTempFile("fileC", "fastq"));
sObjA = new SingleEndSequenceFile(sFileA);
sObjB = new SingleEndSequenceFile(sFileB);
sObjC = new SingleEndSequenceFile(sFileC);
sequenceFilePair = new SequenceFilePair(sFileB, sFileC);
singleEndSequenceFile = sObjA;
Sample sampleA = new Sample();
sampleA.setSampleName("SampleA");
Sample sampleB = new Sample();
sampleB.setSampleName("SampleB");
Sample sampleC = new Sample();
sampleC.setSampleName("SampleC");
sampleSingleSequenceFileMap = ImmutableMap.of(sampleA, singleEndSequenceFile);
sampleSequenceFilePairMap = ImmutableMap.of(sampleB, sequenceFilePair);
sampleSequenceFilePairMapSampleA = ImmutableMap.of(sampleA, sequenceFilePair);
refFile = createTempFile("reference", "fasta");
referenceFile = new ReferenceFile(refFile);
inputFiles = new HashSet<>();
inputFiles.addAll(Arrays.asList(sObjA, sObjB, sObjC));
submission = AnalysisSubmission.builder(workflowId).name("my analysis").inputFiles(inputFiles).referenceFile(referenceFile).build();
workflowHistory = new History();
workflowHistory.setId(HISTORY_ID);
workflowLibrary = new Library();
workflowLibrary.setId(LIBRARY_ID);
workflowDetails = new WorkflowDetails();
workflowDetails.setId(WORKFLOW_ID);
workflowPreparation = new AnalysisWorkspaceServiceGalaxy(galaxyHistoriesService, galaxyWorkflowService, galaxyLibrariesService, iridaWorkflowsService, analysisCollectionServiceGalaxy, analysisProvenanceServiceGalaxy, analysisParameterServiceGalaxy, sequencingObjectService);
output1Dataset = new Dataset();
output1Dataset.setId("1");
output1Dataset.setName("output1.txt");
output2Dataset = new Dataset();
output2Dataset.setId("2");
output2Dataset.setName("output2.txt");
collectionResponseSingle = new CollectionResponse();
collectionResponseSingle.setId(COLLECTION_SINGLE_ID);
collectionResponsePaired = new CollectionResponse();
collectionResponsePaired.setId(COLLECTION_PAIRED_ID);
singleInputFiles = Sets.newHashSet(singleEndSequenceFile);
pairedInputFiles = Sets.newHashSet(sequenceFilePair);
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile in project irida by phac-nml.
the class SequencingObjectServiceImplIT method testCreateNotCompressedSequenceFile.
@Test
@WithMockUser(username = "fbristow", roles = "SEQUENCER")
public void testCreateNotCompressedSequenceFile() throws IOException, InterruptedException {
final Long expectedRevisionNumber = 1L;
SequenceFile sf = createSequenceFile("file1");
Path sequenceFile = sf.getFile();
SingleEndSequenceFile singleEndSequenceFile = new SingleEndSequenceFile(sf);
logger.trace("About to save the file.");
SequencingObject sequencingObject = asRole(Role.ROLE_SEQUENCER, "fbristow").objectService.create(singleEndSequenceFile);
logger.trace("Finished saving the file.");
assertNotNull("ID wasn't assigned.", sequencingObject.getId());
// Sleeping for a bit to let file processing run
Thread.sleep(10000);
// figure out what the version number of the sequence file is (should be
// 1; the file wasn't gzipped, but fastqc will have modified it.)
SequencingObject readObject = null;
do {
readObject = asRole(Role.ROLE_ADMIN, "admin").objectService.read(sequencingObject.getId());
sf = readObject.getFiles().iterator().next();
if (sf.getFileRevisionNumber() < expectedRevisionNumber) {
logger.info("Still waiting on thread to finish, having a bit of a sleep.");
Thread.sleep(1000);
}
} while (sf.getFileRevisionNumber() < expectedRevisionNumber);
assertEquals("Wrong version number after processing.", expectedRevisionNumber, sf.getFileRevisionNumber());
// verify the file checksum was taken properly
assertEquals("checksum should be equal", CHECKSUM, sf.getUploadSha256());
AnalysisFastQC analysis = asRole(Role.ROLE_ADMIN, "admin").analysisService.getFastQCAnalysisForSequenceFile(readObject, sf.getId());
assertNotNull("FastQCAnalysis should have been created for the file.", analysis);
Set<OverrepresentedSequence> overrepresentedSequences = analysis.getOverrepresentedSequences();
assertNotNull("No overrepresented sequences were found.", overrepresentedSequences);
assertEquals("Wrong number of overrepresented sequences were found.", 1, overrepresentedSequences.size());
OverrepresentedSequence overrepresentedSequence = overrepresentedSequences.iterator().next();
assertEquals("Sequence was not the correct sequence.", SEQUENCE, overrepresentedSequence.getSequence());
assertEquals("The count was not correct.", 2, overrepresentedSequence.getOverrepresentedSequenceCount());
assertEquals("The percent was not correct.", new BigDecimal("100.00"), overrepresentedSequence.getPercentage());
// confirm that the file structure is correct
Path idDirectory = baseDirectory.resolve(Paths.get(sf.getId().toString()));
assertTrue("Revision directory doesn't exist.", Files.exists(idDirectory.resolve(Paths.get(sf.getFileRevisionNumber().toString(), sequenceFile.getFileName().toString()))));
// no other files or directories should be beneath the ID directory
int fileCount = 0;
Iterator<Path> dir = Files.newDirectoryStream(idDirectory).iterator();
while (dir.hasNext()) {
dir.next();
fileCount++;
}
assertEquals("Wrong number of directories beneath the id directory", 1, fileCount);
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile in project irida by phac-nml.
the class SequencingObjectServiceImplIT method testCoverage.
@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void testCoverage() throws IOException, InterruptedException {
Project project = projectService.read(1L);
project.setGenomeSize(3L);
project.setMinimumCoverage(2);
project = projectService.update(project);
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);
// Wait 10 seconds. file processing should have run by then.
Thread.sleep(10000);
Sample readSample = sampleService.read(s.getId());
List<QCEntry> qcEntries = sampleService.getQCEntriesForSample(readSample);
assertEquals("should be one qc entry", 1, qcEntries.size());
QCEntry qcEntry = qcEntries.iterator().next();
qcEntry.addProjectSettings(project);
assertTrue("should be coverage entry", qcEntry instanceof CoverageQCEntry);
assertEquals("qc should have passed", QCEntryStatus.POSITIVE, qcEntry.getStatus());
assertEquals("should be 6x coverage", "6x", qcEntry.getMessage());
project.setMinimumCoverage(10);
project = projectService.update(project);
// Wait 10 seconds. file processing should have run by then.
Thread.sleep(10000);
qcEntries = sampleService.getQCEntriesForSample(readSample);
assertEquals("should be one qc entry", 1, qcEntries.size());
qcEntry = qcEntries.iterator().next();
qcEntry.addProjectSettings(project);
assertTrue("should be coverage entry", qcEntry instanceof CoverageQCEntry);
assertEquals("qc should have failed", QCEntryStatus.NEGATIVE, qcEntry.getStatus());
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile in project irida by phac-nml.
the class SequencingRunServiceImplIT method testAddDetachedRunToSequenceFile.
/**
* This test simulates a bug that happens from the REST API when uploading
* sequence files to samples, where a new sequence file is created, then
* detached from a transaction.
*
* @throws IOException
* @throws InterruptedException
*/
@Test
@WithMockUser(username = "fbristow", password = "password1", roles = "ADMIN")
public void testAddDetachedRunToSequenceFile() throws IOException, InterruptedException {
final String SEQUENCE = "ACGTACGTN";
final byte[] FASTQ_FILE_CONTENTS = ("@testread\n" + SEQUENCE + "\n+\n?????????\n@testread2\n" + SEQUENCE + "\n+\n?????????").getBytes();
Path p = Files.createTempFile(null, null);
Files.write(p, FASTQ_FILE_CONTENTS);
SequenceFile sf = new SequenceFile();
sf.setFile(p);
SingleEndSequenceFile so = new SingleEndSequenceFile(sf);
Sample sample = sampleService.read(1L);
SequencingRun run = miseqRunService.read(2L);
objectService.createSequencingObjectInSample(so, sample);
miseqRunService.addSequencingObjectToSequencingRun(run, so);
AnalysisFastQC analysis = null;
do {
try {
analysis = analysisService.getFastQCAnalysisForSequenceFile(so, sf.getId());
} catch (final EntityNotFoundException e) {
logger.info("Fastqc still isn't finished, sleeping a bit.");
Thread.sleep(1000);
}
} while (analysis == null);
assertNotNull("FastQC analysis should have been created for sequence file.", analysis);
}
Aggregations