aboutsummaryrefslogtreecommitdiff
path: root/default.nix
blob: 27afcb585a3f513a2d7df800560a50dc349a3f90 (plain)
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
{nixpkgs ? import <nixpkgs> {}}:

let
  inherit (nixpkgs) fetchurl callPackage;

  bionix = nixpkgs.lib.makeExtensible (self:
  let callBionix = file: attrs: import file ({ bionix = self; nixpkgs = nixpkgs; } // attrs);
  in with self; {
    callBionix = callBionix;
    id = x: x;
    exec = f: x: y: f x y;
    callBionixE = p: exec (callBionix p);

    types = callBionix ./lib/types.nix {};

    bwa = callBionix ./tools/bwa.nix {};
    bowtie = callBionix ./tools/bowtie.nix {};
    compression = callBionix ./tools/compression.nix {};
    crumble = callBionix ./tools/crumble.nix {};
    fastqc = callBionix ./tools/fastqc.nix {};
    gridss = callBionix ./tools/gridss.nix {};
    infercnv = callBionix ./tools/infercnv.nix {};
    kallisto = callBionix ./tools/kallisto.nix {};
    mosdepth = callBionix ./tools/mosdepth.nix {};
    mutect = callBionix ./tools/mutect.nix {};
    platypus = callBionix ./tools/platypus.nix {};
    samtools = callBionix ./tools/samtools.nix {};
    strelka = callBionix ./tools/strelka.nix {};

    ref = callBionix ./lib/references.nix {};

    qsub = attrs: bionix.extend (self: super: with self; rec {
      qsubDefs = { ppn = 1; mem = 1; walltime = "24:00:00"; tmpDir = "/tmp"; sleepTime = 60; } // attrs;
      qsub = attrs: (callPackage ./lib/qsub.nix {}) (qsubDefs // attrs);
      exec = f: x: y: qsub (builtins.intersectAttrs qsubDefs x) (f (builtins.removeAttrs x (builtins.attrNames qsubDefs)) y);
    });
    def = f: defs: attrs: f (defs // attrs);
    pipe = let g = fs: with builtins; let h = head fs; t = tail fs; in if t != [] then x: (g t (h x)) else h; in g;

    link = {src, dst}: ''
      d=$(dirname ${dst})
      if [ ! -e $out/$d ] ; then
        mkdir -p $out/$d
      fi
      ln -s ${src} $out/${dst}
    '';
    mkLinks = nixpkgs.lib.concatMapStringsSep "\n" link;
    linkDrv = x: nixpkgs.stdenvNoCC.mkDerivation {
      name = "link";
      buildCommand = mkLinks x;
    };
    ln = x: y: { src = x; dst = y; };

    # Fetching files of specific type
    fetchFastQ = attrs: with types; tagFiletype (filetype.fq {}) (fetchurl attrs);
    fetchFastA = attrs: with types; tagFiletype (filetype.fa {}) (fetchurl attrs);
    fetchFastQGZ = attrs: with types; tagFiletype (filetype.gz (filetype.fq {})) (fetchurl attrs);
    fetchFastAGZ = attrs: with types; tagFiletype (filetype.gz (filetype.fa {})) (fetchurl attrs);

    # Export nixpkgs' lib
    lib = nixpkgs.lib;
  });
in bionix