Repository navigation
feat: add reference into channel to allow multiple refs #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,77 +26,89 @@ workflow { | |
| exit(0) | ||
| } | ||
|
|
||
| input_files = Channel.fromPath("${params.input_dir}/${params.input_single_suffix}", checkIfExists: true) | ||
| input_files = channel.fromPath("${params.input_dir}/${params.input_single_suffix}", checkIfExists: true) | ||
| .ifEmpty { error("cannot find any reads matching ${params.input_single_suffix} in ${params.input_dir}") } | ||
| .map { it -> tuple(it.getName().replaceFirst(/(?i)\.(fastq|fq)\.gz$/, ""), it) } | ||
|
|
||
| ref = channel.fromPath("${params.ref_fasta}").first() | ||
|
|
||
| input_files = input_files | ||
| .combine(ref) | ||
| .map { it -> | ||
| tuple(it[0], it[2].baseName, it[1], it[2]) | ||
| } | ||
|
|
||
| input_files.take(3).view() | ||
|
|
||
| ref = Channel.fromPath("${params.ref_fasta}").first() | ||
|
|
||
| clair3_models_dir = params.clair3_models_dir.startsWith("/") | ||
| ? params.clair3_models_dir | ||
| : "${projectDir}/${params.clair3_models_dir}" | ||
|
|
||
| if (params.workflow == "clair3") { | ||
| rundial(input_files, ref, clair3_models_dir, params.basecalling_model) | ||
| rundial(input_files, clair3_models_dir, params.basecalling_model) | ||
| } | ||
| else if (params.workflow == "bcftools") { | ||
| rundial_with_bcftools(input_files, ref) | ||
| rundial_with_bcftools(input_files) | ||
| } | ||
| else { | ||
| error("Please provide a valid workflow: bcftools or clair3") | ||
| } | ||
| } | ||
|
|
||
| // Main workflow uses clair3 variant calling with bcftools to fill in the gaps | ||
| // ref_id is needed for joining channels, as the reference path can change | ||
| workflow rundial { | ||
| take: | ||
| fastq_files | ||
| ref | ||
| input_files // (sample_name, ref_id, fastq, ref) | ||
| clair3_models_dir | ||
| dorado_model | ||
|
|
||
| main: | ||
| clair3_model = get_clair3_model(dorado_model) | ||
|
|
||
| valid_model_ch = fastq_files | ||
| // swap fastq and ref to match the input of the clair3 process | ||
| valid_model_ch = input_files | ||
| .combine(clair3_model) | ||
| .filter { it -> it[2] != "failed" } | ||
| .map { it -> tuple(it[0], it[1]) } | ||
| invalid_model_ch = fastq_files | ||
| .filter { it -> it[4] != "failed" } | ||
| .map { it -> tuple(it[0], it[1], it[3], it[2]) } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, probably me not undertsanding but why swap the order here and not in the process?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is just me avoiding needing to swap over all of the processes in the repo which would be a bit of a pain |
||
| invalid_model_ch = input_files | ||
| .combine(clair3_model) | ||
| .filter { it -> it[2] == "failed" } | ||
| .map { it -> tuple(it[0], it[1]) } | ||
| .filter { it -> it[4] == "failed" } | ||
| .map { it -> tuple(it[0], it[1], it[3], it[2]) } | ||
|
|
||
| valid_model_ch.take(1).view { "Appropriate Clair3 Model Found" } | ||
| invalid_model_ch.take(1).view { "No appropriate Clair3 Model Found" } | ||
|
|
||
| // If no appropriate clair3 model is found, use bcftools | ||
| rundial_with_bcftools(invalid_model_ch, ref) | ||
| rundial_with_bcftools(invalid_model_ch) | ||
|
|
||
| // If appropriate clair3 model is found, run clair3 | ||
| model_path = clair3_model.map { it -> clair3_models_dir + "/${it}.tar.gz" } | ||
| model_path.view { "Using Clair3 Model: ${it}" } | ||
| model_path.view { it -> "Using Clair3 Model: ${it}" } | ||
|
|
||
| minimap2(valid_model_ch, ref) | ||
| clair3(minimap2.out.sorted_alignment, ref, model_path) | ||
| minimap2(valid_model_ch) | ||
| clair3(minimap2.out.sorted_alignment, model_path) | ||
|
|
||
| clair3_filter_params = Channel.fromPath("${moduleDir}/process/clair3_filter_params.yml").first() | ||
| clair3_filter_params = channel.fromPath("${moduleDir}/process/clair3_filter_params.yml").first() | ||
| apply_filters_clair3(clair3.out.vcf, clair3_filter_params, "clair3") | ||
|
|
||
| // Still use normal params with bcftools support vcf | ||
| filter_params = Channel.fromPath("${moduleDir}/process/filter_params.yml").first() | ||
| call_snps(minimap2.out.sorted_alignment, ref) | ||
| filter_params = channel.fromPath("${moduleDir}/process/filter_params.yml").first() | ||
| call_snps(minimap2.out.sorted_alignment) | ||
| apply_filters(call_snps.out.gvcf, filter_params, "bcftools") | ||
|
|
||
|
|
||
| consensus_params = Channel.fromPath("${moduleDir}/process/clair3_consensus_params.yml").first() | ||
| calls = apply_filters.out.filtered_vcf.join(apply_filters_clair3.out.filtered_vcf) | ||
| make_clair3_consensus(calls, ref, consensus_params) | ||
| consensus_params = channel.fromPath("${moduleDir}/process/clair3_consensus_params.yml").first() | ||
|
|
||
| calls = apply_filters.out.filtered_vcf | ||
| .join(apply_filters_clair3.out.filtered_vcf, by: [0, 1]) | ||
| .map { it -> tuple(it[0], it[1], it[2], it[3], it[5]) } | ||
| make_clair3_consensus(calls, consensus_params) | ||
|
|
||
| emit: | ||
| alignment = rundial_with_bcftools.out.alignment.concat(minimap2.out.sorted_alignment) | ||
| gvcf = rundial_with_bcftools.out.gvcf.concat(clair3.out.vcf) | ||
| alignment = rundial_with_bcftools.out.alignment.concat(minimap2.out.sorted_alignment.map { it -> tuple(it[0], it[1], it[3]) }) | ||
| gvcf = rundial_with_bcftools.out.gvcf.concat(clair3.out.vcf.map { it -> tuple(it[0], it[1], it[3]) }) | ||
| final_fasta = rundial_with_bcftools.out.final_fasta.concat(make_clair3_consensus.out.final_fasta) | ||
| variable_length_fasta = rundial_with_bcftools.out.variable_length_fasta.concat(make_clair3_consensus.out.variable_length_fasta) | ||
| variants_vcf = rundial_with_bcftools.out.variants_vcf.concat(make_clair3_consensus.out.variants_vcf) | ||
|
|
@@ -107,23 +119,25 @@ workflow rundial { | |
|
|
||
| workflow rundial_with_bcftools { | ||
| take: | ||
| fastq_files | ||
| ref | ||
| input_files // (sample_name, ref_id, ref, fastq) | ||
|
|
||
| main: | ||
| filter_params = Channel.fromPath("${moduleDir}/process/filter_params.yml").first() | ||
| consensus_params = Channel.fromPath("${moduleDir}/process/consensus_params.yml").first() | ||
| filter_params = channel.fromPath("${moduleDir}/process/filter_params.yml").first() | ||
| consensus_params = channel.fromPath("${moduleDir}/process/consensus_params.yml").first() | ||
|
|
||
| minimap2(fastq_files, ref) | ||
| call_all(minimap2.out.sorted_alignment, ref) | ||
| apply_filters(call_all.out.gvcf, filter_params, "bcftools") | ||
| minimap2(input_files) | ||
| call_all(minimap2.out.sorted_alignment) | ||
| apply_filters( | ||
| call_all.out.gvcf, | ||
| filter_params, | ||
| "bcftools", | ||
| ) | ||
|
|
||
| calls = apply_filters.out.filtered_vcf | ||
| make_consensus(calls, ref, consensus_params) | ||
| make_consensus(apply_filters.out.filtered_vcf, consensus_params) | ||
|
|
||
| emit: | ||
| alignment = minimap2.out.sorted_alignment | ||
| gvcf = apply_filters.out.filtered_vcf | ||
| alignment = minimap2.out.sorted_alignment.map { it -> tuple(it[0], it[1], it[3]) } | ||
| gvcf = apply_filters.out.filtered_vcf.map { it -> tuple(it[0], it[1], it[3]) } | ||
| final_fasta = make_consensus.out.final_fasta | ||
| variable_length_fasta = make_consensus.out.variable_length_fasta | ||
| variants_vcf = make_consensus.out.variants_vcf | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I'm probably missing something obvious, but why
.first()here, please?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's probably not needed anymore, but was definitely required with the previous setup. It ensures that the channel is a value channel: https://carpentries-incubator.github.io/workflows-nextflow/instructor/03-channels.html#channel-types