Search in sources :

Example 1 with LibraryContent

use of com.github.jmchilton.blend4j.galaxy.beans.LibraryContent in project irida by phac-nml.

the class GalaxyHistoriesServiceIT method setupLibraries.

/**
 * Sets up library for test.
 * @param testLibrary  The library to upload a file to.
 * @param galaxyInstanceAdmin  The Galaxy Instance to connect to Galaxy.
 * @return Returns the id of the file in a library.
 * @throws CreateLibraryException
 * @throws ExecutionManagerObjectNotFoundException
 */
private String setupLibraries(Library testLibrary, GalaxyInstance galaxyInstanceAdmin) throws CreateLibraryException, ExecutionManagerObjectNotFoundException {
    LibrariesClient librariesClient = galaxyInstanceAdmin.getLibrariesClient();
    LibraryContent rootFolder = librariesClient.getRootFolder(testLibrary.getId());
    assertNotNull(rootFolder);
    FilesystemPathsLibraryUpload upload = new FilesystemPathsLibraryUpload();
    upload.setFolderId(rootFolder.getId());
    upload.setContent(dataFile.toFile().getAbsolutePath());
    upload.setName(dataFile.toFile().getName());
    upload.setLinkData(true);
    upload.setFileType(FILE_TYPE.toString());
    assertEquals(ClientResponse.Status.OK, librariesClient.uploadFilesystemPathsRequest(testLibrary.getId(), upload).getClientResponseStatus());
    List<LibraryContent> libraryContents = librariesClient.getLibraryContents(testLibrary.getId());
    Map<String, List<LibraryContent>> libraryContent = libraryContents.stream().collect(Collectors.groupingBy(LibraryContent::getName));
    LibraryContent fileContent = libraryContent.get("/" + dataFile.toFile().getName()).get(0);
    assertNotNull(fileContent);
    return fileContent.getId();
}
Also used : LibraryContent(com.github.jmchilton.blend4j.galaxy.beans.LibraryContent) List(java.util.List) LibrariesClient(com.github.jmchilton.blend4j.galaxy.LibrariesClient) FilesystemPathsLibraryUpload(com.github.jmchilton.blend4j.galaxy.beans.FilesystemPathsLibraryUpload)

Example 2 with LibraryContent

use of com.github.jmchilton.blend4j.galaxy.beans.LibraryContent in project irida by phac-nml.

the class GalaxyLibrariesService method fileToLibrary.

/**
 * Uploads the given file to a library with the given information.
 *
 * @param path
 *            The path of the file to upload.
 * @param fileType
 *            The type of the file to upload.
 * @param library
 *            The library to upload the file into.
 * @param dataStorage
 *            The {@link DataStorage} method to apply to this dataset.
 * @return A dataset id for the dataset in this library.
 * @throws UploadException
 *             If there was an issue uploading the file to the library.
 */
public String fileToLibrary(Path path, InputFileType fileType, Library library, DataStorage dataStorage) throws UploadException {
    checkNotNull(path, "path is null");
    checkNotNull(fileType, "fileType is null");
    checkNotNull(library, "library is null");
    checkNotNull(library.getId(), "library id is null");
    checkState(path.toFile().exists(), "path " + path + " does not exist");
    File file = path.toFile();
    try {
        LibraryContent rootContent = librariesClient.getRootFolder(library.getId());
        FilesystemPathsLibraryUpload upload = new FilesystemPathsLibraryUpload();
        upload.setFolderId(rootContent.getId());
        upload.setContent(file.getAbsolutePath());
        upload.setName(file.getName());
        upload.setLinkData(DataStorage.LOCAL.equals(dataStorage));
        upload.setFileType(fileType.toString());
        GalaxyObject uploadObject = librariesClient.uploadFilesystemPaths(library.getId(), upload);
        return uploadObject.getId();
    } catch (RuntimeException e) {
        throw new UploadException(e);
    }
}
Also used : GalaxyObject(com.github.jmchilton.blend4j.galaxy.beans.GalaxyObject) LibraryContent(com.github.jmchilton.blend4j.galaxy.beans.LibraryContent) UploadException(ca.corefacility.bioinformatics.irida.exceptions.UploadException) File(java.io.File) FilesystemPathsLibraryUpload(com.github.jmchilton.blend4j.galaxy.beans.FilesystemPathsLibraryUpload)

Example 3 with LibraryContent

use of com.github.jmchilton.blend4j.galaxy.beans.LibraryContent in project irida by phac-nml.

the class AnalysisWorkspaceServiceGalaxyIT method testPrepareAnalysisFilesPairSuccess.

/**
 * Tests out successfully preparing paired workflow input files for
 * execution.
 *
 * @throws InterruptedException
 * @throws ExecutionManagerException
 * @throws IOException
 * @throws IridaWorkflowException
 */
@Test
@WithMockUser(username = "aaron", roles = "ADMIN")
public void testPrepareAnalysisFilesPairSuccess() throws InterruptedException, ExecutionManagerException, IOException, IridaWorkflowException {
    History history = new History();
    history.setName("testPrepareAnalysisFilesPairSuccess");
    HistoriesClient historiesClient = localGalaxy.getGalaxyInstanceAdmin().getHistoriesClient();
    WorkflowsClient workflowsClient = localGalaxy.getGalaxyInstanceAdmin().getWorkflowsClient();
    LibrariesClient librariesClient = localGalaxy.getGalaxyInstanceAdmin().getLibrariesClient();
    History createdHistory = historiesClient.create(history);
    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);
    AnalysisSubmission analysisSubmission = analysisExecutionGalaxyITService.setupPairSubmissionInDatabase(1L, pairSequenceFiles1A, pairSequenceFiles2A, referenceFilePath, validWorkflowIdPaired, false);
    analysisSubmission.setRemoteAnalysisId(createdHistory.getId());
    analysisSubmission.setRemoteWorkflowId(galaxyWorkflow.getId());
    PreparedWorkflowGalaxy preparedWorkflow = analysisWorkspaceService.prepareAnalysisFiles(analysisSubmission);
    assertEquals("the response history id should match the input history id", createdHistory.getId(), preparedWorkflow.getRemoteAnalysisId());
    WorkflowInputsGalaxy workflowInputsGalaxy = preparedWorkflow.getWorkflowInputs();
    assertNotNull("the returned workflow inputs should not be null", workflowInputsGalaxy);
    assertNotNull("the returned library id should not be null", preparedWorkflow.getRemoteDataId());
    // verify correct library is created
    List<LibraryContent> libraryContents = librariesClient.getLibraryContents(preparedWorkflow.getRemoteDataId());
    Map<String, List<LibraryContent>> libraryContentsMap = libraryContents.stream().collect(Collectors.groupingBy(LibraryContent::getName));
    assertFalse("the returned library should exist in Galaxy", libraryContentsMap.isEmpty());
    String sequenceFile1ALibraryName = "/" + sequenceFilePathA.getFileName().toString();
    String sequenceFile2ALibraryName = "/" + sequenceFilePath2A.getFileName().toString();
    assertEquals("the returned library does not contain the correct number of elements", 3, libraryContentsMap.size());
    assertTrue("the returned library does not contain a root folder", libraryContentsMap.containsKey("/"));
    assertTrue("the returned library does not contain the correct sequence file", libraryContentsMap.containsKey(sequenceFile1ALibraryName));
    assertEquals("the returned library does not contain the correct sequence file", 1, libraryContentsMap.get(sequenceFile1ALibraryName).size());
    assertTrue("the returned library does not contain the correct sequence file", libraryContentsMap.containsKey(sequenceFile2ALibraryName));
    assertEquals("the returned library does not contain the correct sequence file", 1, libraryContentsMap.get(sequenceFile2ALibraryName).size());
    // verify correct files have been uploaded
    List<HistoryContents> historyContents = historiesClient.showHistoryContents(createdHistory.getId());
    assertEquals("the created history has an invalid number of elements", 4, historyContents.size());
    Map<String, HistoryContents> contentsMap = historyContentsAsMap(historyContents);
    assertTrue("the created history should contain the file " + sequenceFilePathA.toFile().getName(), contentsMap.containsKey(sequenceFilePathA.toFile().getName()));
    assertTrue("the created history should contain the file " + sequenceFilePath2A.toFile().getName(), contentsMap.containsKey(sequenceFilePath2A.toFile().getName()));
    assertTrue("the created history should contain the file " + referenceFilePath.toFile().getName(), contentsMap.containsKey(referenceFilePath.toFile().getName()));
    assertTrue("the created history should contain the collection with name " + INPUTS_PAIRED_NAME, contentsMap.containsKey(INPUTS_PAIRED_NAME));
    // make sure workflow inputs contains correct information
    Map<String, WorkflowInput> workflowInputsMap = preparedWorkflow.getWorkflowInputs().getInputsObject().getInputs();
    assertEquals("the created workflow inputs has an invalid number of elements", 2, workflowInputsMap.size());
}
Also used : Path(java.nio.file.Path) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) HistoryContents(com.github.jmchilton.blend4j.galaxy.beans.HistoryContents) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) LibraryContent(com.github.jmchilton.blend4j.galaxy.beans.LibraryContent) Workflow(com.github.jmchilton.blend4j.galaxy.beans.Workflow) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) History(com.github.jmchilton.blend4j.galaxy.beans.History) LibrariesClient(com.github.jmchilton.blend4j.galaxy.LibrariesClient) WorkflowInputsGalaxy(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy) HistoriesClient(com.github.jmchilton.blend4j.galaxy.HistoriesClient) WorkflowsClient(com.github.jmchilton.blend4j.galaxy.WorkflowsClient) PreparedWorkflowGalaxy(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.PreparedWorkflowGalaxy) List(java.util.List) ArrayList(java.util.ArrayList) WorkflowInput(com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs.WorkflowInput) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 4 with LibraryContent

use of com.github.jmchilton.blend4j.galaxy.beans.LibraryContent in project irida by phac-nml.

the class AnalysisWorkspaceServiceGalaxyIT method testPrepareAnalysisFilesSingleSuccess.

/**
 * Tests out successfully preparing single workflow input files for
 * execution.
 *
 * @throws InterruptedException
 * @throws ExecutionManagerException
 * @throws IOException
 * @throws IridaWorkflowException
 */
@Test
@WithMockUser(username = "aaron", roles = "ADMIN")
public void testPrepareAnalysisFilesSingleSuccess() throws InterruptedException, ExecutionManagerException, IOException, IridaWorkflowException {
    History history = new History();
    history.setName("testPrepareAnalysisFilesSingleSuccess");
    HistoriesClient historiesClient = localGalaxy.getGalaxyInstanceAdmin().getHistoriesClient();
    WorkflowsClient workflowsClient = localGalaxy.getGalaxyInstanceAdmin().getWorkflowsClient();
    LibrariesClient librariesClient = localGalaxy.getGalaxyInstanceAdmin().getLibrariesClient();
    History createdHistory = historiesClient.create(history);
    IridaWorkflow iridaWorkflow = iridaWorkflowsService.getIridaWorkflow(validWorkflowIdSingle);
    Path workflowPath = iridaWorkflow.getWorkflowStructure().getWorkflowFile();
    String workflowString = new String(Files.readAllBytes(workflowPath), StandardCharsets.UTF_8);
    Workflow galaxyWorkflow = workflowsClient.importWorkflow(workflowString);
    AnalysisSubmission analysisSubmission = analysisExecutionGalaxyITService.setupSubmissionInDatabase(1L, sequenceFilePathA, referenceFilePath, validWorkflowIdSingle, false);
    analysisSubmission.setRemoteAnalysisId(createdHistory.getId());
    analysisSubmission.setRemoteWorkflowId(galaxyWorkflow.getId());
    PreparedWorkflowGalaxy preparedWorkflow = analysisWorkspaceService.prepareAnalysisFiles(analysisSubmission);
    assertEquals("the response history id should match the input history id", createdHistory.getId(), preparedWorkflow.getRemoteAnalysisId());
    assertNotNull("the returned workflow inputs should not be null", preparedWorkflow.getWorkflowInputs());
    assertNotNull("the returned library id should not be null", preparedWorkflow.getRemoteDataId());
    // verify correct library is created
    List<LibraryContent> libraryContents = librariesClient.getLibraryContents(preparedWorkflow.getRemoteDataId());
    Map<String, List<LibraryContent>> libraryContentsMap = libraryContents.stream().collect(Collectors.groupingBy(LibraryContent::getName));
    assertFalse("the returned library should exist in Galaxy", libraryContentsMap.isEmpty());
    String sequenceFileALibraryName = "/" + sequenceFilePathA.getFileName().toString();
    assertEquals("the returned library does not contain the correct number of elements", 2, libraryContentsMap.size());
    assertTrue("the returned library does not contain a root folder", libraryContentsMap.containsKey("/"));
    assertTrue("the returned library does not contain the correct sequence file", libraryContentsMap.containsKey(sequenceFileALibraryName));
    assertEquals("the returned library does not contain the correct sequence file", 1, libraryContentsMap.get(sequenceFileALibraryName).size());
    // verify correct files have been uploaded
    List<HistoryContents> historyContents = historiesClient.showHistoryContents(createdHistory.getId());
    assertEquals("the created history should contain 3 entries", 3, historyContents.size());
    Map<String, HistoryContents> contentsMap = historyContentsAsMap(historyContents);
    assertTrue("the created history should contain the file " + sequenceFilePathA.toFile().getName(), contentsMap.containsKey(sequenceFilePathA.toFile().getName()));
    assertTrue("the created history should contain the file " + referenceFilePath.toFile().getName(), contentsMap.containsKey(referenceFilePath.toFile().getName()));
    assertTrue("the created history should contain the collection with name " + INPUTS_SINGLE_NAME, contentsMap.containsKey(INPUTS_SINGLE_NAME));
    // make sure workflow inputs contains correct information
    Map<String, WorkflowInput> workflowInputsMap = preparedWorkflow.getWorkflowInputs().getInputsObject().getInputs();
    assertEquals("the created workflow inputs has an invalid number of elements", 2, workflowInputsMap.size());
}
Also used : Path(java.nio.file.Path) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) HistoryContents(com.github.jmchilton.blend4j.galaxy.beans.HistoryContents) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) LibraryContent(com.github.jmchilton.blend4j.galaxy.beans.LibraryContent) Workflow(com.github.jmchilton.blend4j.galaxy.beans.Workflow) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) History(com.github.jmchilton.blend4j.galaxy.beans.History) LibrariesClient(com.github.jmchilton.blend4j.galaxy.LibrariesClient) HistoriesClient(com.github.jmchilton.blend4j.galaxy.HistoriesClient) WorkflowsClient(com.github.jmchilton.blend4j.galaxy.WorkflowsClient) PreparedWorkflowGalaxy(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.PreparedWorkflowGalaxy) List(java.util.List) ArrayList(java.util.ArrayList) WorkflowInput(com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs.WorkflowInput) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Aggregations

LibraryContent (com.github.jmchilton.blend4j.galaxy.beans.LibraryContent)4 LibrariesClient (com.github.jmchilton.blend4j.galaxy.LibrariesClient)3 List (java.util.List)3 IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)2 PreparedWorkflowGalaxy (ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.PreparedWorkflowGalaxy)2 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)2 HistoriesClient (com.github.jmchilton.blend4j.galaxy.HistoriesClient)2 WorkflowsClient (com.github.jmchilton.blend4j.galaxy.WorkflowsClient)2 FilesystemPathsLibraryUpload (com.github.jmchilton.blend4j.galaxy.beans.FilesystemPathsLibraryUpload)2 History (com.github.jmchilton.blend4j.galaxy.beans.History)2 HistoryContents (com.github.jmchilton.blend4j.galaxy.beans.HistoryContents)2 Workflow (com.github.jmchilton.blend4j.galaxy.beans.Workflow)2 WorkflowInput (com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs.WorkflowInput)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 WithMockUser (org.springframework.security.test.context.support.WithMockUser)2 UploadException (ca.corefacility.bioinformatics.irida.exceptions.UploadException)1 WorkflowInputsGalaxy (ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy)1 GalaxyObject (com.github.jmchilton.blend4j.galaxy.beans.GalaxyObject)1