-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Let users launch NextFlow from file browser
- Loading branch information
1 parent
d106645
commit eaa5d2c
Showing
9 changed files
with
331 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 87 additions & 11 deletions
98
nextflow/src/org/labkey/nextflow/pipeline/NextFlowPipelineJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,120 @@ | ||
package org.labkey.nextflow.pipeline; | ||
|
||
import lombok.Getter; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.labkey.api.data.Container; | ||
import org.labkey.api.files.FileContentService; | ||
import org.labkey.api.pipeline.ParamParser; | ||
import org.labkey.api.pipeline.PipeRoot; | ||
import org.labkey.api.pipeline.PipelineJob; | ||
import org.labkey.api.pipeline.PipelineJobService; | ||
import org.labkey.api.pipeline.TaskId; | ||
import org.labkey.api.pipeline.TaskPipeline; | ||
import org.labkey.api.pipeline.file.AbstractFileAnalysisJob; | ||
import org.labkey.api.util.FileUtil; | ||
import org.labkey.api.util.URLHelper; | ||
import org.labkey.api.util.PageFlowUtil; | ||
import org.labkey.api.view.ViewBackgroundInfo; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
public class NextFlowPipelineJob extends PipelineJob | ||
@Getter | ||
public class NextFlowPipelineJob extends AbstractFileAnalysisJob | ||
{ | ||
private Path config; | ||
|
||
@SuppressWarnings("unused") // For serialization | ||
protected NextFlowPipelineJob() | ||
{} | ||
|
||
public NextFlowPipelineJob(ViewBackgroundInfo info, @NotNull PipeRoot root) | ||
public static NextFlowPipelineJob create(ViewBackgroundInfo info, @NotNull PipeRoot root, Path templateConfig, List<Path> inputFiles) throws IOException | ||
{ | ||
super(null, info, root); | ||
setLogFile(new File(String.valueOf(root.getLogDirectory()), FileUtil.makeFileNameWithTimestamp("NextFlowPipelineJob", "log")).toPath()); | ||
Path parentDir = inputFiles.get(0).getParent(); | ||
|
||
String jobName = FileUtil.makeFileNameWithTimestamp("NextFlow"); | ||
Path jobDir = parentDir.resolve(jobName); | ||
Path log = jobDir.resolve(jobName + ".log"); | ||
FileUtil.createDirectory(jobDir); | ||
|
||
Path config = createConfig(templateConfig, log.getParent(), jobDir, info.getContainer()); | ||
|
||
return new NextFlowPipelineJob(info, root, config, inputFiles, log); | ||
} | ||
|
||
@Override | ||
public URLHelper getStatusHref() | ||
public NextFlowPipelineJob(ViewBackgroundInfo info, @NotNull PipeRoot root, Path config, List<Path> inputFiles, Path log) throws IOException | ||
{ | ||
return null; | ||
super(new NextFlowProtocol(), NextFlowPipelineProvider.NAME, info, root, config.getFileName().toString(), config, inputFiles, false, false); | ||
this.config = config; | ||
setLogFile(log); | ||
} | ||
|
||
@Override | ||
public ParamParser getInputParameters() | ||
{ | ||
return PipelineJobService.get().createParamParser(); | ||
} | ||
|
||
/** Take the template config file and substitute in the values for this job */ | ||
private static Path createConfig(Path configTemplate, Path parentDir, Path jobDir, Container container) throws IOException | ||
{ | ||
String template; | ||
try (InputStream in = Files.newInputStream(configTemplate)) | ||
{ | ||
template = PageFlowUtil.getStreamContentsAsString(in); | ||
} | ||
|
||
String webdavUrl = FileContentService.get().getWebDavUrl(parentDir, container, FileContentService.PathType.full); | ||
webdavUrl = StringUtils.stripEnd(webdavUrl, "/"); | ||
|
||
String substitutedContent = template.replace("${quant_spectra_dir}", "quant_spectra_dir = '" + webdavUrl + "'"); | ||
|
||
Path substitutedFile = jobDir.resolve(configTemplate.getFileName()); | ||
try (BufferedWriter writer = Files.newBufferedWriter(substitutedFile)) | ||
{ | ||
writer.write(substitutedContent); | ||
} | ||
return substitutedFile; | ||
} | ||
|
||
@Override | ||
public String getDescription() | ||
{ | ||
return "NextFlow Job"; | ||
return "NextFlow analysis using " + config.getFileName() + " of " + getInputFilePaths().size() + " files"; | ||
} | ||
|
||
@Override | ||
public TaskPipeline<?> getTaskPipeline() | ||
{ | ||
return PipelineJobService.get().getTaskPipeline(new TaskId(NextFlowPipelineJob.class)); | ||
return PipelineJobService.get().getTaskPipeline(getTaskPipelineId()); | ||
} | ||
|
||
@Override | ||
public TaskId getTaskPipelineId() | ||
{ | ||
return new TaskId(NextFlowPipelineJob.class); | ||
} | ||
|
||
@Override | ||
public AbstractFileAnalysisJob createSingleFileJob(File file) | ||
{ | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public File findInputFile(String name) | ||
{ | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public File findOutputFile(String name) | ||
{ | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.