-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.nf
106 lines (88 loc) · 3.36 KB
/
main.nf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env nextflow
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nds-lucid/graphdbloader
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Github : https://github.com/nds-lucid/graphdbloader
----------------------------------------------------------------------------------------
*/
nextflow.enable.dsl = 2
include { graphdb_import_file; graphdb_auth } from './modules/graphdb'
include { clean_backups } from './modules/io'
include { copy_file as copy_to_graphdb } from './modules/io'
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RUN ALL WORKFLOWS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
//
// WORKFLOW: Execute a single named workflow for the pipeline
// See: https://github.com/nf-core/rnaseq/issues/619
//
workflow {
// Copy input files from source to GraphDB
if (params.watch)
ch_input_files = Channel.watchPath("${params.input_dir}/*.nt.gz")
else
ch_input_files = Channel.fromPath("${params.input_dir}/*.nt.gz")
ch_server_files = copy_to_graphdb(ch_input_files, params.graphdb_dir)
// Get GraphDB auth token using nextflow secrets
token = graphdb_auth()
// Extract graph uri from filename, assuming format {timstamp}_{graph}.{ext}
// NOTE: uses baseName+replace instead of simpleName to prevent truncation of
// iso8601-compliant timestamps with milliseconds
ch_graph_uri = ch_input_files
.map {
it
.baseName
.tokenize('_')
.last()
.replaceAll(/\..*$/, '')
}
// Load into GraphDB using server file import and copy to backup dir.
ch_graphdb = graphdb_import_file(
ch_server_files,
ch_graph_uri,
token
)
// Log successful and failed imports (HTTP codes in 2xx range).
ch_log = ch_graphdb.map {
file, graph, resp, code -> [
file: file,
graph: graph,
resp: resp.text
.replaceAll('[\n\r]', '')
.replaceAll('"', '\\\\"'),
status: code.text ==~ /2[0-9]{2}/ ? "SUCCESS" : "FAILURE"
]
}
// Send event to log_dir/timestamp.json
def log_event = { event ->
new File( params.log_dir + "/${new Date().toInstant().now()}.json" ) << event + "\n"
}
// Write all import events to disk as json (successes and failures).
ch_log
.map {
it -> "{\"status\": \"${it.status}\", \"file\": \"${it.file}\", \"graph\": \"${it.graph}\", \"resp\": \"${it.resp}\"}"
}
.subscribe { log_event(it) }
// List all successfully imported files.
ch_imported_files = ch_log
.filter { it.status == "SUCCESS" }
.map { it.file }
// Only retain N last backups for each graph, if set
if ( params.max_backups >= 1 ) {
// Only retain N last backups for each graph, if set
// passing channel to trigger process per file in watchPath
clean_backups(params.backup_dir, params.max_backups, ch_imported_files)
}
}
workflow.onError {
println "Error: ${workflow.errorMessage}"
println "Error: ${workflow.errorReport}"
}
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
THE END
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/