aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJustin Bedo <cu@cua0.org>2018-10-05 16:16:20 +1000
committerJustin Bedo <cu@cua0.org>2018-10-05 16:19:06 +1000
commit871ef64f3c43199dfa01216ac86db56650c2c8a2 (patch)
tree7053b4533d7306b3fc0eed8f9bc25e8e2abb6d6e /lib
parentdd3666f6a069105e61f8889665cf55eed9a14e51 (diff)
implement types
Diffstat (limited to 'lib')
-rwxr-xr-xlib/references.nix5
-rw-r--r--lib/types.nix64
2 files changed, 69 insertions, 0 deletions
diff --git a/lib/references.nix b/lib/references.nix
index 61655cd..3614647 100755
--- a/lib/references.nix
+++ b/lib/references.nix
@@ -1,6 +1,7 @@
{ bionix, nixpkgs }:
with nixpkgs;
+with bionix.types;
rec {
grch38 = grch38-p12;
@@ -13,6 +14,7 @@ rec {
sha256 = "0ji2ggpmgnbpwbhq8mirj6h3lyy02nl2rnz7n892iq5cqpsblh4z";
};
buildCommand = "gunzip < $src > $out";
+ passthru.filetype = filetype.fa {};
};
blacklist = stdenvNoCC.mkDerivation {
name = "blacklist-grch38";
@@ -21,6 +23,7 @@ rec {
sha256 = "1lpnqq1mjidbdxj5i6x26rxa8x1rs8q3hlf0z1z49j3jsnkgffky";
};
buildCommand = "gunzip < $src > $out";
+ passthru.filetype = filetype.bed { ref = seq; };
};
};
@@ -34,6 +37,7 @@ rec {
sha256 = "0ryiqab5bldpzawylsk2qpjxr2j701q03ww9jqyxhkimqpn9g3mr";
};
buildCommand = "gunzip < $src > $out";
+ passthru.filetype = filetype.fa {};
};
};
@@ -47,6 +51,7 @@ rec {
sha256 = "1660d6d05f3aa266c6053cfd1efef1747d9e854836917241d6f47cff7a55340c";
};
buildCommand = "gunzip < $src > $out";
+ passthru.filetype = filetype.fa {};
};
};
}
diff --git a/lib/types.nix b/lib/types.nix
new file mode 100644
index 0000000..a347046
--- /dev/null
+++ b/lib/types.nix
@@ -0,0 +1,64 @@
+{bionix, nixpkgs}:
+
+with nixpkgs;
+
+let
+ nix-adt-src = fetchFromGitHub {
+ owner = "shlevy";
+ repo = "nix-adt";
+ rev = "dd04b5d08eed65ecd73aafde56a78078e09f1c74";
+ sha256 = "0vhk1y7gilgn2pgvj4813bh2ljpw4pvrph8k8b0fsg56dbm8mqxa";
+ };
+ nix-adt = import "${nix-adt-src}";
+ inherit (nix-adt.checked) make-type match any std none;
+ inherit (std) option;
+
+ idft = sym: ft: _: abort "unhandled filetype (${ft}) for ${sym}";
+ idst = sym: st: _: abort "unhandled sorting (${st}) for ${sym}";
+
+in
+rec {
+ option-sort = option sorting;
+
+ matchFiletype = sym: y: x: if x ? filetype then match x.filetype ({
+ fa = idft sym "fasta";
+ fq = idft sym "fastq";
+ bam = idft sym "bam";
+ sam = idft sym "sam";
+ cram = idft sym "cram";
+ vcf = idft sym "vcf";
+ bed = idft sym "bed";
+ gz = idft sym "gz";
+ bz2 = idft sym "bz2";
+ } // y) else abort "unknown filetype for ${sym}";
+ filetype = make-type "filetype" {
+ fa = {};
+ fq = {};
+ bam = {ref = any; sorting = option-sort;};
+ sam = {ref = any; sorting = option-sort;};
+ cram = {ref = any; sorting = option-sort;};
+ vcf = {ref = any;};
+ bed = {ref = any;};
+ gz = filetype;
+ bz2 = filetype;
+ };
+
+ toCram = matchFiletype "bam2cram" { bam = filetype.cram; sam = filetype.cram; cram = filetype.cram; };
+ toBam = matchFiletype "bam2cram" { bam = filetype.bam; sam = filetype.bam; cram = filetype.bam; };
+ toSam = matchFiletype "bam2cram" { bam = filetype.sam; sam = filetype.sam; cram = filetype.sam; };
+
+ matchSorting = sym: y: let f = x: match x.sorting { some = z: match z ( { coord = idst sym "coord"; name = idst sym "name"; } // y); none = abort "unknown sort for ${sym}"; }; in matchFiletype sym { bam = f; sam = f; cram = f; };
+ sorting = make-type "sorting" {
+ coord = {};
+ name = {};
+ };
+ coordSort = f: matchFiletype "coordSort" { bam = x: filetype.bam (x // {sorting = option-sort.some (sorting.coord {});}); } {filetype = f;};
+ nameSort = f: matchFiletype "nameSort" { bam = x: filetype.bam (x // {sorting = option-sort.some (sorting.name {});}); } {filetype = f;};
+
+ gunzip = matchFiletype "gunzip" { gz = x: x; };
+ bunzip2 = matchFiletype "bunzip2" { bz2 = x: x; };
+
+ tag = attrs: x: if x ? type && x.type == "derivation" then x // attrs else tagPassthru attrs x;
+ tagPassthru = attrs: x: if x ? passthru then x // { passthru = x.passthru // attrs; } else x // { passthru = attrs; };
+ tagFiletype = ft: tag { filetype = ft; };
+}