Skip to content

Commit

Permalink
Add task dag format (#12)
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Sherman <[email protected]>
  • Loading branch information
bentsherman authored Oct 10, 2023
1 parent 99c43ef commit a0f0dd4
Show file tree
Hide file tree
Showing 6 changed files with 420 additions and 66 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,31 @@ The following options are available:

`prov.enabled`

Create the provenance manifest (default: `true` if plugin is loaded).
Create the provenance report (default: `true` if plugin is loaded).

`prov.file`

The path of the provenance manifest (default: `manifest.json`).
The path of the provenance report (default: `manifest.json`).

`prov.format`

The manifest format. Can be `legacy` or `bco` (default: `legacy`).
The report format. The following formats are available:

*Note: The BCO format is experimental and may change in future releases. Visit the [BCO User Guide](https://docs.biocomputeobject.org/user_guide/) to learn more about this format and how to extend it with information that isn't available to Nextflow.*
- `bco`: Render a [BioCompute Object](https://biocomputeobject.org/).

Visit the [BCO User Guide](https://docs.biocomputeobject.org/user_guide/) to learn more about this format and how to extend it with information that isn't available to Nextflow.

- `dag`: Render the task graph as a Mermaid diagram embedded in an HTML document.

- `legacy`: Render the legacy format originally defined in this plugin (default).

`prov.overwrite`

Overwrite any existing provenance report with the same name (default: `false`).

`prov.patterns`

List of file patterns to include in the provenance manifest, from the set of published files. By default, all published files are included.
List of file patterns to include in the provenance report, from the set of published files. By default, all published files are included.

## Development

Expand Down
62 changes: 8 additions & 54 deletions plugins/nf-prov/src/main/nextflow/prov/BcoRenderer.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import java.time.format.DateTimeFormatter
import groovy.json.JsonOutput
import groovy.transform.CompileStatic
import nextflow.Session
import nextflow.exception.AbortOperationException
import nextflow.processor.TaskRun
import nextflow.script.WorkflowMetadata
import nextflow.util.CacheHelper
Expand All @@ -36,53 +35,8 @@ import nextflow.util.CacheHelper
@CompileStatic
class BcoRenderer implements Renderer {

private URL repository

private String commitId

private String launchDir

private String projectDir

private String workDir

/**
* Normalize local paths to remove environment-specific directories.
*
* @param path
*/
private String normalizePath(Path path) {
normalizePath(path.toUriString())
}

private String normalizePath(String path) {
// replace work directory with relative path
if( path.startsWith(workDir) )
return path.replace(workDir, 'work')

// replace project directory with source URL (if applicable)
if( repository && path.startsWith(projectDir) )
return getProjectSourceUrl(path)

// replace launch directory with relative path
if( path.startsWith(launchDir) )
return path.replace(launchDir + '/', '')

return path
}

/**
* Get the source URL for a project asset.
*
* @param path
*/
private String getProjectSourceUrl(String path) {
// TODO: add other git providers
if( repository.host == 'github.com' )
return path.replace(projectDir, "${repository}/tree/${commitId}")
else
return path
}
@Delegate
private PathNormalizer normalizer

@Override
void render(Session session, Set<TaskRun> tasks, Map<Path,Path> workflowOutputs, Path path) {
Expand All @@ -92,13 +46,10 @@ class BcoRenderer implements Renderer {

// get workflow metadata
final metadata = session.workflowMetadata
this.normalizer = new PathNormalizer(metadata)

final manifest = metadata.manifest
final nextflowMeta = metadata.nextflow
this.repository = metadata.repository ? new URL(metadata.repository) : null
this.commitId = metadata.commitId
this.projectDir = metadata.projectDir.toUriString()
this.launchDir = metadata.launchDir.toUriString()
this.workDir = metadata.workDir.toUriString()

final dateCreated = DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(metadata.start)
final authors = (manifest.author ?: '').tokenize(',')*.trim()
Expand Down Expand Up @@ -181,13 +132,16 @@ class BcoRenderer implements Renderer {
// append git repository info
if( metadata.repository ) {
final extension_domain = bco.extension_domain as List
final scriptFile = metadata.scriptFile.toUriString()
final projectDir = metadata.projectDir.toUriString()

extension_domain << [
"extension_schema": "https://w3id.org/biocompute/extension_domain/1.1.0/scm/scm_extension.json",
"scm_extension": [
"scm_repository": metadata.repository,
"scm_type": "git",
"scm_commit": metadata.commitId,
"scm_path": metadata.scriptFile.toUriString().replace(projectDir + '/', ''),
"scm_path": scriptFile.replace(projectDir + '/', ''),
"scm_preview": normalizePath(metadata.scriptFile)
]
]
Expand Down
Loading

0 comments on commit a0f0dd4

Please sign in to comment.