-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.nf
168 lines (123 loc) · 4.39 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env nextflow
// Using DSL-2
nextflow.enable.dsl=2
// All of the default parameters are being set in `nextflow.config`
params.input_dir = "${projectDir}/data"
params.output_dir = "${projectDir}/output"
//Static Assests for beautification
params.letterhead = "${projectDir}/images/ClassyFlow_Letterhead.PNG"
// Build Input List of Batches
Channel.fromPath("${params.input_dir}/*/", type: 'dir')
.ifEmpty { error "No subdirectories found in ${params.input_dir}" }
.set { batchDirs }
// Import sub-workflows
include { normalization_wf } from './modules/normalizations'
include { featureselection_wf } from './modules/featureselections'
include { modelling_wf } from './modules/makemodels'
// -------------------------------------- //
// Function which prints help message text
def helpMessage() {
log.info"""
Usage:
nextflow run main.nf <ARGUMENTS>
Required Arguments:
Input Data:
--input_dir Folder containing subfolders of QuPath's Quantification Exported Measurements,
each dir containing Quant files belonging to a common batch of images.
""".stripIndent()
}
// Define a process to merge tab-delimited files and save as pickle
process mergeTabDelimitedFiles {
input:
path subdir
output:
tuple val(batchID), path("merged_dataframe_${batchID}.pkl"), emit: namedBatchtables
path("merged_dataframe_${batchID}.pkl"), emit: batchtables
script:
exMarks = "${params.exclude_markers}"
batchID = subdir.baseName
template 'merge_files.py'
}
// Identify
process checkPanelDesign {
input:
path(tables_pkl_collected)
output:
path 'panel_design.csv', emit: paneldesignfile
script:
template 'compare_panel_designs.py'
}
//Add back empty Markers, low noise (16-bit or 8-bit)
process addEmptyMarkerNoise {
input:
tuple val(batchID), path(pickleTable)
path designTable
output:
tuple val(batchID), path("merged_dataframe_${batchID}_mod.pkl"), emit: modbatchtables
script:
template 'add_empty_marker_noise.py'
}
process generateTrainingNHoldout{
publishDir(
path: "${params.output_dir}/celltype_reports",
pattern: "*.pdf",
mode: "copy"
)
input:
path(norms_pkl_collected)
output:
path("holdout_dataframe.pkl"), emit: holdout
path("training_dataframe.pkl"), emit: training
path("celltypes.csv"), emit: lableFile
path("annotation_report.pdf")
script:
template 'split_annotations_for_training.py'
}
// Run model on everything make results
process predictAllCells_xgb{
publishDir(
path: "${params.output_dir}/celltypes",
pattern: "*_PRED.tsv",
mode: "copy"
)
input:
tuple val(model_name), path(model_path)
tuple val(batchID), path(pickleTable)
output:
path("*.tsv")
script:
template 'predict_celltypes.py'
}
// -------------------------------------- //
// Main workflow
workflow {
// Show help message if the user specifies the --help flag at runtime
// or if any required params are not provided
if ( params.help || params.input_dir == false ){
// Invoke the function above which prints the help message
helpMessage()
// Exit out and do not run anything else
exit 1
} else {
// Pull channel object `batchDirs` from nextflow env - see top of file.
mergeTabDelimitedFiles(batchDirs)
checkPanelDesign(mergeTabDelimitedFiles.output.batchtables.collect())
//modify the pickle files to account for missing features...
addEmptyMarkerNoise(mergeTabDelimitedFiles.output.namedBatchtables, checkPanelDesign.output.paneldesignfile)
/*
* - Subworkflow to handle all Normalization/Standardization Tasks -
*/
normalizedDataFrames = normalization_wf(addEmptyMarkerNoise.output.modbatchtables)
labledDataFrames = generateTrainingNHoldout(normalizedDataFrames.map{ it[1] }.collect())
/*
* - Subworkflow to examine Cell Type Specific interpetability & Feature Selections -
*/
selectFeatures = featureselection_wf(labledDataFrames.training, labledDataFrames.lableFile)
/*
* - Subworkflow to generate models and then check them against the holdout -
*/
bestModel = modelling_wf(labledDataFrames.training, labledDataFrames.holdout, selectFeatures)
// Run the best model on the full input batches/files
predictAllCells_xgb(bestModel, normalizedDataFrames)
}
}