aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJustin Bedo <cu@cua0.org>2018-12-05 10:48:05 +1100
committerJustin Bedo <cu@cua0.org>2018-12-10 16:26:37 +1100
commit86b1b192501eecc8a4e566795327772c32b1633d (patch)
treef06d78c11672b66e2655ab5f23cfe91a30fe5504 /tools
parent16951e6f99636a2c9d924d49c549a918e403f276 (diff)
bowtie: init
Diffstat (limited to 'tools')
-rw-r--r--tools/bowtie-align.nix36
-rw-r--r--tools/bowtie-index.nix22
-rw-r--r--tools/bowtie.nix8
3 files changed, 66 insertions, 0 deletions
diff --git a/tools/bowtie-align.nix b/tools/bowtie-align.nix
new file mode 100644
index 0000000..456747a
--- /dev/null
+++ b/tools/bowtie-align.nix
@@ -0,0 +1,36 @@
+{ bionix
+, nixpkgs
+, ref
+, bamOutput ? true
+, flags ? null
+, indexAttrs ? {}
+}:
+
+{ input1
+, input2 ? null
+}:
+
+with nixpkgs;
+with lib;
+with bionix.types;
+with bionix.compression;
+
+let
+ fa = f: matchFiletype "bowtie2-ref" { fa = _: f; } f;
+ fq = f: matchFiletype "bowtie2-input" { fq = _: f; gz = matchFiletype' "bowtie2-input" { fq = _: f; }; } f;
+
+in stdenv.mkDerivation {
+ name = "bowtie2-align";
+ buildInputs = [ bowtie2 bc ] ++ optional bamOutput samtools;
+ buildCommand = ''
+ cores=$(echo $NIX_BUILD_CORES ${optionalString bamOutput "- 1"} | bc)
+ if [[ $cores -lt 1 ]] ; then
+ cores=1
+ fi
+ bowtie2 -x ${bionix.bowtie.index indexAttrs ref}/ref ${optionalString (flags != null) flags} --threads $cores \
+ ${if input2 != null then "-1 " + fq input1 + " -2 " + fq input2 else "-U " + fq input1} \
+ ${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 {};};
+}
diff --git a/tools/bowtie-index.nix b/tools/bowtie-index.nix
new file mode 100644
index 0000000..98e529f
--- /dev/null
+++ b/tools/bowtie-index.nix
@@ -0,0 +1,22 @@
+{ bionix
+, nixpkgs
+, flags ? null
+, seed ? 42
+}:
+
+ref:
+
+with nixpkgs;
+with lib;
+with bionix.types;
+
+assert (matchFiletype "bowtie-index" { fa = _: true; } ref);
+
+stdenv.mkDerivation {
+ name = "bowtie-index";
+ buildInputs = [ bowtie2 ];
+ buildCommand = ''
+ mkdir $out
+ bowtie2-build --seed ${toString seed} --threads $NIX_BUILD_CORES ${optionalString (flags != null) flags} ${ref} $out/ref
+ '';
+}
diff --git a/tools/bowtie.nix b/tools/bowtie.nix
new file mode 100644
index 0000000..a9fa2e8
--- /dev/null
+++ b/tools/bowtie.nix
@@ -0,0 +1,8 @@
+{ bionix, nixpkgs }:
+
+with bionix;
+
+{
+ align = callBionix ./bowtie-align.nix;
+ index = callBionix ./bowtie-index.nix;
+}