Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions nextflow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ the name it was published under. The dataset's path in this tree (`folderA/folde
also recorded *inside* each checkpoint as its own name, so the two fixed filenames stay
unambiguous — reopening either one shows the dataset it holds, not the word "results".

Only the checkpoints that the dataset's `results.log` records as saved (`[ok] saved …`)
are published and listed in `index.json`. AWS Batch can run a task's job a second time
in the same work directory, for instance when a spot instance is reclaimed during the
upload, and the earlier attempt's files stay there. A checkpoint's hash differs from one
attempt to the next, so without this check the dataset would be published with two
checkpoints of each kind.

Serving the `results/` directory over HTTP — any static host — renders every dataset in
the browser with no backend (DESIGN §14.3). The same `.zarr.zip` files also open in the
full app (New Session → Load) when you need to compute on them.
Expand Down
24 changes: 22 additions & 2 deletions nextflow/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,34 @@ def asciiPath(String prefix) {
.replaceAll('[^\\x20-\\x7E]+', '-')
}

/** Whether ANALYSE's last attempt wrote `checkpoint`, by its `[ok] saved` line in the
* results.log beside it. Any other file is not a checkpoint and is kept.
*
* AWS Batch can run a task's job a second time in the same S3 work directory (a spot
* instance reclaimed mid-upload). Each attempt stages out what it wrote without
* removing what an earlier attempt left there, and a checkpoint is named by a hash of
* its content, which differs between attempts, so the output glob would pick up both.
* results.log has a fixed name and is rewritten from empty by every attempt.
*/
def savedByLastAttempt(Path checkpoint) {
if( !checkpoint.name.endsWith('.zarr.zip') ) return true
def results_log = checkpoint.resolveSibling('results.log')
return results_log.exists() && results_log.readLines().any { line ->
line.startsWith('[ok] saved ') && line.contains("/${checkpoint.name} (")
}
}

process ANALYSE {
tag "${prefix} (${spec.label})"
container params.analysis_container

// Everything this candidate produces is already laid out under out/ exactly as it
// should be published, so publishing is a straight copy with the wrapper stripped.
publishDir "${params.outdir}/results", mode: 'copy', pattern: 'out/**',
saveAs: { f -> f.toString().tokenize('/').drop(1).join('/') }
saveAs: { f ->
savedByLastAttempt(task.workDir.resolve(f))
? f.toString().tokenize('/').drop(1).join('/') : null
}

input:
tuple val(prefix), val(spec), path(data_dir)
Expand Down Expand Up @@ -423,8 +443,8 @@ workflow {
// The full checkpoint and its low-res copy are separate entries in the listing.
ANALYSE.out.published
.flatten()
.filter { f -> f.name.endsWith('.zarr.zip') && savedByLastAttempt(f) }
.map { f -> f.toString() }
.filter { f -> f.endsWith('.zarr.zip') }
.map { f ->
def rel = f.substring(f.indexOf('/out/') + '/out/'.length())
// Both checkpoints of a dataset sit in its own folder, so the folder
Expand Down
Loading