From ab809b8c77efdad9fb54d3591a0193a1cbe888d1 Mon Sep 17 00:00:00 2001 From: Justin Bedo Date: Fri, 29 Oct 2021 15:27:22 +1100 Subject: octopus: write region lists to region files --- tools/octopus-call.nix | 29 +++++++++++++++++++++++------ tools/octopus-callSomatic.nix | 31 +++++++++++++++++++++++-------- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/tools/octopus-call.nix b/tools/octopus-call.nix index f33d87c..80092e0 100644 --- a/tools/octopus-call.nix +++ b/tools/octopus-call.nix @@ -3,9 +3,10 @@ , very-fast ? false , max-genotypes ? null , targets ? null -, faidxAttrs ? {} -, indexAttrs ? {} -, flags ? ""}: +, faidxAttrs ? { } +, indexAttrs ? { } +, flags ? "" +}: assert !fast || !very-fast; assert max-genotypes == null || max-genotypes > 0; @@ -17,10 +18,26 @@ with types; inputs: let - getref = f: matchFiletype "octopus-call" { bam = {ref, ...}: ref; cram = {ref, ...}: ref;} f; + getref = f: matchFiletype "octopus-call" { bam = { ref, ... }: ref; cram = { ref, ... }: ref; } f; refs = map getref inputs; ref = head refs; + + handleTarget = x: + let + type = builtins.typeOf x; + handler = handlers."${type}" or (builtins.throw "octopus-callSomatic:unhandled target type:${type}"); + handlers = { + string = "-T '${x}'"; + list = + let file = pkgs.writeText "regions.txt" (concatStringsSep "\n" x); + in "-t ${file}"; + path = "-t ${x}"; + }; + in + handler; + + in assert (length (unique refs) == 1); @@ -43,9 +60,9 @@ stage { ${optionalString fast "--fast"} \ ${optionalString very-fast "--very-fast"} \ ${optionalString (max-genotypes != null) "--max-genotypes ${toString max-genotypes}"} \ - ${optionalString (targets != null) (if builtins.typeOf targets == "list" then "-T ${concatStringsSep "," targets}" else "-t ${targets}")} \ + ${optionalString (targets != null) (handleTarget targets)} \ ${flags} ''; - passthru.filetype = filetype.vcf {ref = ref;}; + passthru.filetype = filetype.vcf { ref = ref; }; passthru.multicore = true; } diff --git a/tools/octopus-callSomatic.nix b/tools/octopus-callSomatic.nix index d3e7f96..401eeb8 100644 --- a/tools/octopus-callSomatic.nix +++ b/tools/octopus-callSomatic.nix @@ -3,9 +3,10 @@ , very-fast ? false , max-genotypes ? null , targets ? null -, faidxAttrs ? {} -, indexAttrs ? {} -, flags ? ""}: +, faidxAttrs ? { } +, indexAttrs ? { } +, flags ? "" +}: assert !fast || !very-fast; assert max-genotypes == null || max-genotypes > 0; @@ -14,7 +15,7 @@ with bionix; with lib; with types; -{normal, tumours}: +{ normal, tumours }: let smScript = pkgs.writeText "smScript.awk" '' @@ -29,11 +30,25 @@ let } ''; - inputs = [normal] ++ tumours; - getref = f: matchFiletype "octopus-callSomatic" { bam = {ref, ...}: ref; cram = {ref, ...}: ref;} f; + inputs = [ normal ] ++ tumours; + getref = f: matchFiletype "octopus-callSomatic" { bam = { ref, ... }: ref; cram = { ref, ... }: ref; } f; refs = map getref inputs; ref = head refs; + handleTarget = x: + let + type = builtins.typeOf x; + handler = handlers."${type}" or (builtins.throw "octopus-callSomatic:unhandled target type:${type}"); + handlers = { + string = "-T '${x}'"; + list = + let file = pkgs.writeText "regions.txt" (concatStringsSep "\n" x); + in "-t ${file}"; + path = "-t ${x}"; + }; + in + handler; + in assert (length (unique refs) == 1); @@ -58,10 +73,10 @@ stage { ${optionalString fast "--fast"} \ ${optionalString very-fast "--very-fast"} \ ${optionalString (max-genotypes != null) "--max-genotypes ${toString max-genotypes}"} \ - ${optionalString (targets != null) (if builtins.typeOf targets == "list" then "-T ${concatStringsSep "," targets}" else "-t ${targets}")} \ + ${optionalString (targets != null) (handleTarget targets)} \ -N $normal \ ${flags} ''; - passthru.filetype = filetype.vcf {ref = ref;}; + passthru.filetype = filetype.vcf { ref = ref; }; passthru.multicore = true; } -- cgit v1.2.3