aboutsummaryrefslogtreecommitdiff
path: root/tools/gridss-somatic-filter.nix
blob: 2e3f5ea9aa58bf96635ee09cf0ef3e8b5a61e51c (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
{ bionix, normalName, genomeVersion ? "hg38" }:
vcf:

with bionix;
with pkgs;

let
  refMap = with rPackages; {
    hg38 = BSgenome_Hsapiens_UCSC_hg38;
    hg19 = BSgenome_Hsapiens_UCSC_hg19;
  };

  renv = rWrapper.override {
    packages = with rPackages; [
      (refMap."${genomeVersion}" or (abort "unsupported reference"))
      Biobase
      BiocGenerics
      Biostrings
      DelayedArray
      IRanges
      S4Vectors
      StructuralVariantAnnotation
      VariantAnnotation
      XVector
      argparser
      ggplot2
      matrixStats
      readr
      rtracklayer
      stringdist
      stringr
      testthat
      tidyverse
    ];
  };

  script = stdenvNoCC.mkDerivation {
    name = "gridss-somatic-filtering-scripts";
    src = fetchFromGitHub {
      owner = "PapenfussLab";
      repo = "gridss";
      rev = "a6b230a78179869c0210dc878490811be813d2fb";
      sha256 = "sha256-b+b6BEvjZbKYR+pJ/Z8yQpcZpairpSUoMHtRRTuRUls=";

    };

    doBuild = false;
    nativeBuildInputs = [ makeWrapper ];

    installPhase = ''
      mkdir -p $out/libexec/gridss
      cp scripts/{gridss.config.R,libgridss.R,gridss_somatic_filter} $out/libexec/gridss
      mkdir -p $out/bin
      makeWrapper ${renv}/bin/Rscript $out/bin/gridss_somatic_filter \
        --add-flags $out/libexec/gridss/gridss_somatic_filter \
        --add-flags "--ref BSgenome.Hsapiens.UCSC.${genomeVersion}" \
        --add-flags "--scriptdir $out/libexec/gridss"
    '';
  };

  findNormal = writeText "find-normal.awk" ''
    /^#C/{
      for(i = 10; i <= NF && $i != "${normalName}"; i++);
      if(i > NF){
        print "findNormal: could not match name" > /dev/stderr
        exit(1)
      }
      printf("%s", i - 9)
      exit(0)
    }
  '';

in
stage {
  name = "gridss-somatic";
  buildCommand = ''
    NORM=$(awk -f ${findNormal} ${vcf})
    ln -s ${vcf} in.vcf
    ${script}/bin/gridss_somatic_filter \
      --output ./out \
      --input in.vcf \
      --normalordinal $NORM
    gunzip < out.bgz > $out
  '';
}