aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test-tnpair.nix2
-rw-r--r--tools/bwa-index2.nix23
-rw-r--r--tools/bwa-mem2-app.nix15
-rw-r--r--tools/bwa-mem2.nix40
-rw-r--r--tools/bwa.nix8
5 files changed, 86 insertions, 2 deletions
diff --git a/test-tnpair.nix b/test-tnpair.nix
index 0e13338..76fcfab 100644
--- a/test-tnpair.nix
+++ b/test-tnpair.nix
@@ -62,6 +62,8 @@ let
(ln tnpairResult.variants.snvs "strelka.snvs.vcf")
(ln tnpairResult.glvariants.variants "strelka.gl.vcf")
(ln (bowtie.align {inherit ref;} tnpair.normal.files) "alignments/bowtie-normal.bam")
+ (ln (bwa.mem {inherit ref;} tnpair.normal.files) "alignments/bwa-mem.bam")
+ (ln (bwa.mem2 {inherit ref;} tnpair.normal.files) "alignments/bwa-mem2.bam")
(ln (minimap2.align {inherit ref; preset = "sr"; } tnpair.normal.files) "alignments/minimap2-normal.bam")
(ln (snap.align {inherit ref; } tnpair.normal.files) "alignments/snap-normal.bam")
(ln (gridss.callVariants {} (with tnpairResult.alignments; [normal tumour])) "gridss")
diff --git a/tools/bwa-index2.nix b/tools/bwa-index2.nix
new file mode 100644
index 0000000..f5cc69b
--- /dev/null
+++ b/tools/bwa-index2.nix
@@ -0,0 +1,23 @@
+{ bionix
+, flags ? null
+}:
+
+ref:
+
+with bionix;
+with lib;
+with types;
+
+assert (matchFiletype "bwa-index" { fa = _: true; } ref);
+
+stage {
+ name = "bwa-index2";
+ buildInputs = with pkgs; [ bionix.bwa.app2 ];
+ buildCommand = ''
+ ln -s ${ref} ref.fa
+ bwa-mem2 index ${optionalString (flags != null) flags} ref.fa
+ mkdir $out
+ mv ref.fa.* $out
+ grep '^>[^ \t]*_alt$' ref.fa | tr -d '^>' > $out/idxbase.alt || true
+ '';
+}
diff --git a/tools/bwa-mem2-app.nix b/tools/bwa-mem2-app.nix
new file mode 100644
index 0000000..8cca5a5
--- /dev/null
+++ b/tools/bwa-mem2-app.nix
@@ -0,0 +1,15 @@
+{ bwa, fetchFromGitHub }:
+ bwa.overrideAttrs (_:
+ {
+ name = "bwa-mem2";
+ src = fetchFromGitHub {
+ owner = "bwa-mem2";
+ repo = "bwa-mem2";
+ rev = "f882015f7f46845f72c10094a621264f78d206d8";
+ sha256 = "1wfx8j9mwbb29jw4zxp28lajmj774jy1l5x229nf065cqr2dgyqg";
+ };
+ installPhase = ''
+ mkdir -p $out/bin
+ cp bwa-mem2 $out/bin
+ '';
+ })
diff --git a/tools/bwa-mem2.nix b/tools/bwa-mem2.nix
new file mode 100644
index 0000000..3de1944
--- /dev/null
+++ b/tools/bwa-mem2.nix
@@ -0,0 +1,40 @@
+{ bionix
+, ref
+, bamOutput ? true
+, flags ? null
+, indexAttrs ? {}
+}:
+
+{ input1
+, input2 ? null
+}:
+
+with bionix;
+with lib;
+with types;
+with compression;
+
+let
+ fa = f: matchFiletype "bwa-ref" { fa = _: f; } f;
+ fq = f: matchFiletype "bwa-input" { fq = _: f; gz = matchFiletype' "bwa-input" { fq = _: f; }; } f;
+
+in stage {
+ name = "bwa-mem2";
+ buildInputs = with pkgs; [ bionix.bwa.app2 bc ] ++ optional bamOutput samtools;
+ buildCommand = ''
+ ln -s ${fa ref} ref.fa
+ for f in ${bionix.bwa.index2 indexAttrs ref}/* ; do
+ ln -s $f
+ done
+ cores=$(echo $NIX_BUILD_CORES ${optionalString bamOutput "- 1"} | bc)
+ if [[ $cores -lt 1 ]] ; then
+ cores=1
+ fi
+ bwa-mem2 mem ${optionalString (flags != null) flags} -t $cores ref.fa ${fq input1} \
+ ${optionalString (input2 != null) (fq input2)} \
+ ${optionalString bamOutput "| samtools view -b"} \
+ > $out
+ '';
+ passthru.filetype = if bamOutput then filetype.bam {ref = ref; sorting = sort.name {};} else filetype.sam {ref = ref; sorting = sort.name {};};
+ passthru.multicore = true;
+}
diff --git a/tools/bwa.nix b/tools/bwa.nix
index 58f9651..90a8bd3 100644
--- a/tools/bwa.nix
+++ b/tools/bwa.nix
@@ -3,15 +3,19 @@
with bionix;
rec {
+ app2 = pkgs.callPackage ./bwa-mem2-app.nix {};
+
/* Align read against a reference: defaults to bwa-mem */
- align = bwa-mem;
+ align = bionix.bwa.mem;
/* Align reads against a reference using bwa-mem
Type: bwa-mem :: {ref :: fasta, bamOutput :: bool, ...} -> {input1, input2} -> bam/sam
*/
- bwa-mem = callBionixE ./bwa-mem.nix;
+ mem = callBionixE ./bwa-mem.nix;
+ mem2 = callBionixE ./bwa-mem2.nix;
/* Creates an reference index for BWA
Type: index :: {...} -> fasta -> BWA index
*/
index = callBionixE ./bwa-index.nix;
+ index2 = callBionixE ./bwa-index2.nix;
}