-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.nf
More file actions
executable file
·167 lines (118 loc) · 4.56 KB
/
main.nf
File metadata and controls
executable file
·167 lines (118 loc) · 4.56 KB
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
#!/usr/bin/env nextflow
process downloadCelltypes {
publishDir "${params.outdir}/cell_type_assignments", mode: 'copy'
input:
tuple val(study_name), path(study_dir)
output:
tuple val(study_name), path("${study_name}.celltypes.tsv"), emit: celltypes_meta
script:
def cta_protocol = "author-submitted"
//}
"""
if [ ${params.author_submitted} = true ]; then
curl -u "${params.GEMMA_USERNAME}:${params.GEMMA_PASSWORD}" \
-H "Accept: text/tab-separated-values" \
--compressed \
"https://staging-gemma.msl.ubc.ca/rest/v2/datasets/${study_name}/cellTypeAssignment?useBioAssayId=true&protocol=${cta_protocol}" \
-o "${study_name}.celltypes.tsv"
else
curl -u "${params.GEMMA_USERNAME}:${params.GEMMA_PASSWORD}" \
-H "Accept: text/tab-separated-values" \
--compressed \
"https://staging-gemma.msl.ubc.ca/rest/v2/datasets/${study_name}/cellTypeAssignment?useBioAssayId=true" \
-o "${study_name}.celltypes.tsv"
fi
"""
}
process getGemmaMeta {
publishDir "${params.outdir}/metadata/${study_name}", mode: 'copy'
conda "/home/rschwartz/anaconda3/envs/scanpyenv"
input:
tuple val(study_name), path(study_dir)
output:
tuple val(study_name), path("**${study_name}_sample_meta.tsv"), emit: sample_meta
script:
"""
python /space/grp/rschwartz/rschwartz/get_gemma_data.nf/bin/get_gemma_meta.py \\
--study_name ${study_name} \\
"""
}
process write_unique_cells {
publishDir "${params.outdir}/unique_cells/${study_name}", mode: 'copy'
input:
tuple val(study_name), val(celltypes_meta)
output:
path "${study_name}_unique_cells.tsv", emit: unique_cell_path
script:
// metadata_file = ${meta_path}.getName()
"""
awk -F'\t' '
NR == 1 {
for (i = 1; i <= NF; i++) if (\$i == "cell_type") col = i
next
}
{ count[\$col]++ }
END {
print "cell_type\tcount"
for (c in count) print c "\t" count[c]
}
' "$celltypes_meta" > "${study_name}_unique_cells.tsv"
"""
}
process standardizeMetadata {
publishDir "${params.outdir}/metadata_standardized/${study_name}", mode: 'copy'
conda "/home/rschwartz/anaconda3/envs/scanpyenv"
input:
tuple val(study_name), path(sample_meta)
output:
tuple val(study_name), path("${study_name}_sample_meta_std.tsv"), emit: sample_meta
script:
"""
python $projectDir/bin/standardize_metadata.py \\
${sample_meta} \\
-o ${study_name}_sample_meta_std.tsv
"""
}
include { DOWNLOAD_STUDIES_SUBWF } from "$projectDir/modules/subworkflows/download_studies.nf"
include { PROCESS_QUERY_SAMPLE } from "$projectDir/modules/processes/process_query_samples.nf"
include { PROCESS_QUERY_COMBINED } from "$projectDir/modules/processes/process_query_combined.nf"
// Workflow definition
workflow {
DOWNLOAD_STUDIES_SUBWF(params.study_names, params.study_file, params.study_paths)
DOWNLOAD_STUDIES_SUBWF.out.study_channel.set { study_channel }
downloadCelltypes(study_channel)
// Get the metadata
getGemmaMeta(study_channel)
// study_dirs = downloadStudies.out.study_dir
celltypes_meta = downloadCelltypes.out.celltypes_meta
standardizeMetadata(getGemmaMeta.out.sample_meta)
sample_meta = standardizeMetadata.out.sample_meta
write_unique_cells(celltypes_meta)
// If process_samples is true, we will process each query sample separately
// and use a different process
def processed_queries
if (params.process_samples) {
// Split study_channel into individual samples
expanded_channel = study_channel.flatMap { study_name, study_dir ->
def results = []
study_dir.eachDir { dir -> results << [study_name, dir.name, dir.toString()] }
return results
}
expanded_channel.combine(celltypes_meta, by: 0)
.set { expanded_channel }
expanded_channel.combine(sample_meta, by: 0)
.set { expanded_channel }
// Process each query sample separately
PROCESS_QUERY_SAMPLE(expanded_channel)
} else {
// Process each query without subsampling
study_channel.combine(celltypes_meta, by: 0)
.set { study_channel }
study_channel.combine(sample_meta, by: 0)
.set { study_channel }
PROCESS_QUERY_COMBINED(study_channel)
}
}
workflow.onError = {
println "Error: something went wrong, check the pipeline log at '.nextflow.log"
}